Skip to content

Commit 68d6193

Browse files
committed
(#371) More log output for screen.class.ts
1 parent 434a537 commit 68d6193

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: lib/screen.class.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export class ScreenClass {
281281
if (!isImage(currentScreen)) {
282282
throw Error(`capture requires an Image, but received ${JSON.stringify(currentScreen)}`)
283283
}
284+
this.providerRegistry.getLogProvider().debug(`Capturing whole screen (0, 0, ${currentScreen.width}, ${currentScreen.height})`);
284285
return this.saveImage(
285286
currentScreen,
286287
fileName,
@@ -317,6 +318,7 @@ export class ScreenClass {
317318
if (!isRegion(targetRegion)) {
318319
throw Error(`captureRegion requires an Region, but received ${JSON.stringify(targetRegion)}`)
319320
}
321+
this.providerRegistry.getLogProvider().debug(`Capturing screen region ${targetRegion.toString()}`);
320322
const regionImage = await this.providerRegistry.getScreen().grabScreenRegion(targetRegion);
321323
if (!isImage(regionImage)) {
322324
throw Error(`captureRegion requires an Image, but received ${JSON.stringify(regionImage)}`)
@@ -335,7 +337,9 @@ export class ScreenClass {
335337
* @param regionToGrab The screen region to grab
336338
*/
337339
public async grabRegion(regionToGrab: Region | Promise<Region>): Promise<Image> {
338-
return this.providerRegistry.getScreen().grabScreenRegion(await regionToGrab);
340+
const targetRegion = await regionToGrab;
341+
this.providerRegistry.getLogProvider().debug(`Grabbing screen region ${targetRegion.toString()}`);
342+
return this.providerRegistry.getScreen().grabScreenRegion(targetRegion);
339343
}
340344

341345
/**
@@ -349,6 +353,7 @@ export class ScreenClass {
349353
throw Error(`colorAt requires a Point, but received ${JSON.stringify(inputPoint)}`)
350354
}
351355
const scaledPoint = new Point(inputPoint.x * screenContent.pixelDensity.scaleX, inputPoint.y * screenContent.pixelDensity.scaleY);
356+
this.providerRegistry.getLogProvider().debug(`Point ${inputPoint.toString()} has been scaled by (${screenContent.pixelDensity.scaleX}, ${screenContent.pixelDensity.scaleY}) into ${scaledPoint.toString()}`);
352357
return this.providerRegistry.getImageProcessor().colorAt(screenContent, scaledPoint);
353358
}
354359

@@ -365,7 +370,9 @@ export class ScreenClass {
365370
prefix: fileNamePrefix,
366371
type: fileFormat,
367372
});
373+
this.providerRegistry.getLogProvider().info(`Writing image to ${outputPath}`);
368374
await this.providerRegistry.getImageWriter().store({image, path: outputPath})
375+
this.providerRegistry.getLogProvider().debug(`File written`);
369376
return outputPath;
370377
}
371378

@@ -376,13 +383,15 @@ export class ScreenClass {
376383
const screenImage = await this.providerRegistry.getScreen().grabScreenRegion(searchRegion);
377384
const searchMultipleScales = params?.searchMultipleScales ?? true;
378385

379-
return ({
386+
const findParameters = ({
380387
minMatch,
381388
screenSize,
382389
searchRegion,
383390
screenImage,
384391
searchMultipleScales
385392
});
393+
this.providerRegistry.getLogProvider().debug(`Running image search with parameters ${JSON.stringify(findParameters)}`);
394+
return findParameters;
386395
}
387396

388397
private static async getNeedle(template: FirstArgumentType<typeof ScreenClass.prototype.find>) {

0 commit comments

Comments
 (0)