Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/(nut tree/plugin ocr#25)/default confidence #541

Merged
merged 7 commits into from
Oct 17, 2023
25 changes: 10 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ on:
# paths-ignore:
# - '**/*.md'
pull_request:
workflow_dispatch:

jobs:
sonar:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- name: Setup Docker
run: |
docker pull s1hofmann/nut-ci:latest
Expand Down Expand Up @@ -57,20 +58,15 @@ jobs:
strategy:
matrix:
os: [windows-latest, macos-latest]
node: [16]
node: [18]
runs-on: ${{matrix.os}}
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- name: Setup Docker
if: ${{matrix.os == 'ubuntu-latest'}}
run: |
docker pull s1hofmann/nut-ci:latest
docker run -it -d --name nut-ci --shm-size 8gb --user $(id -u):$(id -g) -v ${PWD}:${PWD}:rw s1hofmann/nut-ci:latest bash
- name: Install
run: npm ci
- name: Compile
Expand All @@ -80,10 +76,9 @@ jobs:
- name: Generate coverage report
uses: GabrielBB/xvfb-action@v1
with:
run: npm run coverage -- --coverageDirectory=coverage/unit
- name: Run Docker E2E tests
if: ${{matrix.os == 'ubuntu-latest'}}
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
run: |
npx playwright install --with-deps
npm run coverage -- --coverageDirectory=coverage/unit
- name: Run Electron e2e test subpackage
uses: GabrielBB/xvfb-action@v1
with:
Expand Down
19 changes: 11 additions & 8 deletions .github/workflows/snapshot_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ on:
repository_dispatch:
types:
- snapshot-release
workflow_dispatch:

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [16]
node: [18]
runs-on: ${{matrix.os}}
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- name: Setup Docker
Expand All @@ -39,7 +40,9 @@ jobs:
- name: Run tests
uses: GabrielBB/xvfb-action@v1
with:
run: npm test
run: |
npx playwright install --with-deps
npm test
- name: Run Docker E2E tests
if: ${{matrix.os == 'ubuntu-latest'}}
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
Expand All @@ -54,11 +57,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Install
run: npm ci
Expand All @@ -70,7 +73,7 @@ jobs:
run: npm run publish-next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
registry-url: "https://npm.pkg.github.com"
- name: Publish snapshot release to GPR
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/tagged_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [16]
node: [18]
runs-on: ${{matrix.os}}
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- name: Setup Docker
Expand All @@ -32,7 +32,9 @@ jobs:
- name: Generate coverage report
uses: GabrielBB/xvfb-action@v1
with:
run: npm test
run: |
npx playwright install --with-deps
npm test
- name: Run Docker E2E tests
if: ${{matrix.os == 'ubuntu-latest'}}
run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}"
Expand All @@ -47,11 +49,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Install
run: npm ci
Expand All @@ -67,7 +69,7 @@ jobs:
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
registry-url: "https://npm.pkg.github.com"
- name: Publish tagged release to GPR
Expand Down
9 changes: 3 additions & 6 deletions e2e/window-test/test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
const { _electron: electron } = require("playwright");
const { getActiveWindow, getWindows } = require("@nut-tree/nut-js");
const { sleep, getActiveWindow, getWindows } = require("@nut-tree/nut-js");
const { POS_X, POS_Y, WIDTH, HEIGTH, TITLE } = require("./constants");

const sleep = async (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

let app;
let page;
let windowHandle;

const APP_TIMEOUT = 10000;
jest.setTimeout(APP_TIMEOUT);

beforeEach(async () => {
app = await electron.launch({ args: ["main.js"] });
app = await electron.launch({ args: ["main.js"], cwd: __dirname });
page = await app.firstWindow({ timeout: APP_TIMEOUT });
windowHandle = await app.browserWindow(page);
await page.waitForLoadState("domcontentloaded");
Expand Down
36 changes: 18 additions & 18 deletions lib/match-request.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ export class MatchRequest<NEEDLE_TYPE, PROVIDER_DATA_TYPE> {
public constructor(
public readonly haystack: Image,
public readonly needle: NEEDLE_TYPE,
public readonly confidence: number,
public readonly providerData?: PROVIDER_DATA_TYPE
public readonly confidence: number | undefined,
public readonly providerData?: PROVIDER_DATA_TYPE,
) {}
}

export function isImageMatchRequest<PROVIDER_DATA_TYPE>(
matchRequest: any
matchRequest: any,
): matchRequest is MatchRequest<Image, PROVIDER_DATA_TYPE> {
return isImage(matchRequest.needle);
}

export function isTextMatchRequest<PROVIDER_DATA_TYPE>(
matchRequest: any
matchRequest: any,
): matchRequest is MatchRequest<TextQuery, PROVIDER_DATA_TYPE> {
return isTextQuery(matchRequest.needle);
}

export function isColorMatchRequest<PROVIDER_DATA_TYPE>(
matchRequest: any
matchRequest: any,
): matchRequest is MatchRequest<ColorQuery, PROVIDER_DATA_TYPE> {
return isColorQuery(matchRequest.needle);
}
Expand All @@ -42,35 +42,35 @@ export function createMatchRequest<PROVIDER_DATA_TYPE>(
providerRegistry: ProviderRegistry,
needle: PointResultFindInput,
searchRegion: Region,
minMatch: number,
minMatch: number | undefined,
screenImage: Image,
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
): MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE>;
export function createMatchRequest<PROVIDER_DATA_TYPE>(
providerRegistry: ProviderRegistry,
needle: RegionResultFindInput,
searchRegion: Region,
minMatch: number,
minMatch: number | undefined,
screenImage: Image,
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
): MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE>;
export function createMatchRequest<PROVIDER_DATA_TYPE>(
providerRegistry: ProviderRegistry,
needle: RegionResultFindInput | PointResultFindInput,
searchRegion: Region,
minMatch: number,
minMatch: number | undefined,
screenImage: Image,
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
):
| MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE>
| MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE>;
export function createMatchRequest<PROVIDER_DATA_TYPE>(
providerRegistry: ProviderRegistry,
needle: RegionResultFindInput | PointResultFindInput,
searchRegion: Region,
minMatch: number,
minMatch: number | undefined,
screenImage: Image,
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>
params?: OptionalSearchParameters<PROVIDER_DATA_TYPE>,
):
| MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE>
| MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE> {
Expand All @@ -80,27 +80,27 @@ export function createMatchRequest<PROVIDER_DATA_TYPE>(
.info(
`Searching for image ${
needle.id
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`,
);

return new MatchRequest(
screenImage,
needle,
minMatch,
params?.providerData
params?.providerData,
);
} else if (isTextQuery(needle)) {
providerRegistry.getLogProvider().info(
`Searching for ${isLineQuery(needle) ? "line" : "word"} {
${isLineQuery(needle) ? needle.by.line : needle.by.word}
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`
} in region ${searchRegion.toString()}. Required confidence: ${minMatch}`,
);

return new MatchRequest(
screenImage,
needle,
minMatch,
params?.providerData
params?.providerData,
);
} else if (isColorQuery(needle)) {
const color = needle.by.color;
Expand All @@ -109,7 +109,7 @@ export function createMatchRequest<PROVIDER_DATA_TYPE>(
.info(
`Searching for color RGBA(${color.R},${color.G},${color.B},${
color.A
}) in region ${searchRegion.toString()}.`
}) in region ${searchRegion.toString()}.`,
);

return new MatchRequest(screenImage, needle, 1, params?.providerData);
Expand Down
Loading
Loading