Skip to content

Commit 2568487

Browse files
committed
(#320) Make find, and the functions re-using it, accept Promise<Image>
1 parent 2af703a commit 2568487

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: lib/screen.class.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {timeout} from "./util/timeout.function";
99
import {Image} from "./image.class";
1010
import {ProviderRegistry} from "./provider/provider-registry.class";
1111
import {loadImageResource} from "./imageResources.function";
12+
import {FirstArgumentType} from "./typings";
1213

1314
export type FindHookCallback = (target: MatchResult) => Promise<void>;
1415

@@ -80,7 +81,7 @@ export class ScreenClass {
8081
* @param params {@link LocationParameters} which are used to fine tune search region and / or match confidence
8182
*/
8283
public async find(
83-
templateImage: string | Image,
84+
templateImage: string | Image | Promise<Image>,
8485
params?: LocationParameters,
8586
): Promise<Region> {
8687
const minMatch = (params && params.confidence) || this.config.confidence;
@@ -92,7 +93,7 @@ export class ScreenClass {
9293
if (typeof templateImage === "string") {
9394
needle = await loadImageResource(this.providerRegistry, this.config.resourceDirectory, templateImage);
9495
} else {
95-
needle = templateImage;
96+
needle = await templateImage;
9697
}
9798

9899
const screenImage = await this.providerRegistry.getScreen().grabScreenRegion(searchRegion);
@@ -171,7 +172,7 @@ export class ScreenClass {
171172
* @param params {@link LocationParameters} which are used to fine tune search region and / or match confidence
172173
*/
173174
public async waitFor(
174-
templateImage: string | Image,
175+
templateImage: FirstArgumentType<typeof ScreenClass.prototype.find>,
175176
timeoutMs: number = 5000,
176177
params?: LocationParameters,
177178
): Promise<Region> {

Diff for: lib/typings.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type FirstArgumentType<T> = T extends (first: infer ArgType, ...args: any[]) => any ? ArgType : never;

0 commit comments

Comments
 (0)