@@ -78,6 +78,7 @@ export class ScreenClass {
78
78
* Screens with higher pixel density (e.g. retina displays in MacBooks) might have a higher width in in actual pixels
79
79
*/
80
80
public width ( ) {
81
+ this . providerRegistry . getLogProvider ( ) . debug ( `Fetching screen width` ) ;
81
82
return this . providerRegistry . getScreen ( ) . screenWidth ( ) ;
82
83
}
83
84
@@ -87,6 +88,7 @@ export class ScreenClass {
87
88
* Screens with higher pixel density (e.g. retina displays in MacBooks) might have a higher height in in actual pixels
88
89
*/
89
90
public height ( ) {
91
+ this . providerRegistry . getLogProvider ( ) . debug ( `Fetching screen height` ) ;
90
92
return this . providerRegistry . getScreen ( ) . screenHeight ( ) ;
91
93
}
92
94
@@ -108,6 +110,7 @@ export class ScreenClass {
108
110
} = await this . getFindParameters ( params ) ;
109
111
110
112
const needle = await ScreenClass . getNeedle ( template ) ;
113
+ this . providerRegistry . getLogProvider ( ) . info ( `Searching for image ${ needle . id } in region ${ searchRegion . toString ( ) } ${ searchMultipleScales ? 'over multiple scales' : 'without scaling' } . Required confidence: ${ minMatch } ` ) ;
111
114
112
115
const matchRequest = new MatchRequest (
113
116
screenImage ,
@@ -119,9 +122,12 @@ export class ScreenClass {
119
122
return new Promise < Region > ( async ( resolve , reject ) => {
120
123
try {
121
124
validateSearchRegion ( searchRegion , screenSize ) ;
125
+ this . providerRegistry . getLogProvider ( ) . debug ( `Search region is valid` ) ;
122
126
const matchResult = await this . providerRegistry . getImageFinder ( ) . findMatch ( matchRequest ) ;
123
127
const possibleHooks = this . findHooks . get ( needle ) || [ ] ;
128
+ this . providerRegistry . getLogProvider ( ) . debug ( `${ possibleHooks . length } hooks triggered for match` ) ;
124
129
for ( const hook of possibleHooks ) {
130
+ this . providerRegistry . getLogProvider ( ) . debug ( `Executing hook` ) ;
125
131
await hook ( matchResult ) ;
126
132
}
127
133
const resultRegion = new Region (
@@ -130,7 +136,9 @@ export class ScreenClass {
130
136
matchResult . location . width ,
131
137
matchResult . location . height
132
138
)
139
+ this . providerRegistry . getLogProvider ( ) . info ( `Match is located at ${ resultRegion . toString ( ) } ` ) ;
133
140
if ( this . config . autoHighlight ) {
141
+ this . providerRegistry . getLogProvider ( ) . debug ( `Autohighlight is enabled` ) ;
134
142
resolve ( this . highlight ( resultRegion ) ) ;
135
143
} else {
136
144
resolve ( resultRegion ) ;
@@ -161,6 +169,7 @@ export class ScreenClass {
161
169
} = await this . getFindParameters ( params ) ;
162
170
163
171
const needle = await ScreenClass . getNeedle ( template ) ;
172
+ this . providerRegistry . getLogProvider ( ) . info ( `Searching for image ${ needle . id } in region ${ searchRegion . toString ( ) } ${ searchMultipleScales ? 'over multiple scales' : 'without scaling' } . Required confidence: ${ minMatch } ` ) ;
164
173
165
174
const matchRequest = new MatchRequest (
166
175
screenImage ,
@@ -172,22 +181,28 @@ export class ScreenClass {
172
181
return new Promise < Region [ ] > ( async ( resolve , reject ) => {
173
182
try {
174
183
validateSearchRegion ( searchRegion , screenSize ) ;
184
+ this . providerRegistry . getLogProvider ( ) . debug ( `Search region is valid` ) ;
175
185
const matchResults = await this . providerRegistry . getImageFinder ( ) . findMatches ( matchRequest ) ;
176
186
const possibleHooks = this . findHooks . get ( needle ) || [ ] ;
187
+ this . providerRegistry . getLogProvider ( ) . debug ( `${ possibleHooks . length } hooks triggered for ${ matchResults . length } matches` ) ;
177
188
for ( const hook of possibleHooks ) {
178
189
for ( const matchResult of matchResults ) {
190
+ this . providerRegistry . getLogProvider ( ) . debug ( `Executing hook` ) ;
179
191
await hook ( matchResult ) ;
180
192
}
181
193
}
182
194
const resultRegions = matchResults . map ( matchResult => {
183
- return new Region (
195
+ const resultRegion = new Region (
184
196
searchRegion . left + matchResult . location . left ,
185
197
searchRegion . top + matchResult . location . top ,
186
198
matchResult . location . width ,
187
199
matchResult . location . height
188
200
)
201
+ this . providerRegistry . getLogProvider ( ) . info ( `Match is located at ${ resultRegion . toString ( ) } ` ) ;
202
+ return resultRegion ;
189
203
} )
190
204
if ( this . config . autoHighlight ) {
205
+ this . providerRegistry . getLogProvider ( ) . debug ( `Autohighlight is enabled` ) ;
191
206
resultRegions . forEach ( region => this . highlight ( region ) ) ;
192
207
resolve ( resultRegions ) ;
193
208
} else {
@@ -207,6 +222,7 @@ export class ScreenClass {
207
222
*/
208
223
public async highlight ( regionToHighlight : Region | Promise < Region > ) : Promise < Region > {
209
224
const highlightRegion = await regionToHighlight ;
225
+ this . providerRegistry . getLogProvider ( ) . info ( `Highlighting ${ highlightRegion . toString ( ) } for ${ this . config . highlightDurationMs / 1000 } with ${ this . config . highlightOpacity * 100 } % opacity` ) ;
210
226
await this . providerRegistry . getScreen ( ) . highlightScreenRegion ( highlightRegion , this . config . highlightDurationMs , this . config . highlightOpacity ) ;
211
227
return highlightRegion ;
212
228
}
@@ -229,6 +245,7 @@ export class ScreenClass {
229
245
if ( ! isImage ( needle ) ) {
230
246
throw Error ( `waitFor requires an Image, but received ${ JSON . stringify ( templateImage ) } ` )
231
247
}
248
+ this . providerRegistry . getLogProvider ( ) . info ( `Waiting for image ${ needle . id } to appear on screen. Timeout: ${ timeoutMs / 1000 } seconds, interval: ${ updateInterval } ms` ) ;
232
249
return timeout ( updateInterval , timeoutMs , ( ) => this . find ( needle , params ) , { signal : params ?. abort } ) ;
233
250
}
234
251
@@ -243,6 +260,7 @@ export class ScreenClass {
243
260
}
244
261
const existingHooks = this . findHooks . get ( templateImage ) || [ ] ;
245
262
this . findHooks . set ( templateImage , [ ...existingHooks , callback ] ) ;
263
+ this . providerRegistry . getLogProvider ( ) . info ( `Registered callback for image ${ templateImage . id } . There are currently ${ existingHooks . length + 1 } hooks registered` ) ;
246
264
}
247
265
248
266
/**
0 commit comments