@@ -46,9 +46,11 @@ export class MouseClass {
46
46
*/
47
47
public async setPosition ( target : Point ) : Promise < MouseClass > {
48
48
if ( ! isPoint ( target ) ) {
49
- throw Error (
49
+ const e = new Error (
50
50
`setPosition requires a Point, but received ${ JSON . stringify ( target ) } `
51
51
) ;
52
+ this . providerRegistry . getLogProvider ( ) . error ( e ) ;
53
+ throw e ;
52
54
}
53
55
this . providerRegistry
54
56
. getLogProvider ( )
@@ -67,8 +69,14 @@ export class MouseClass {
67
69
/**
68
70
* {@link getPosition } returns a {@link Point } representing the current mouse position
69
71
*/
70
- public getPosition ( ) : Promise < Point > {
71
- return this . providerRegistry . getMouse ( ) . currentMousePosition ( ) ;
72
+ public async getPosition ( ) : Promise < Point > {
73
+ const currentPosition = await this . providerRegistry
74
+ . getMouse ( )
75
+ . currentMousePosition ( ) ;
76
+ this . providerRegistry
77
+ . getLogProvider ( )
78
+ . debug ( "Retrieving current mouse position" , { currentPosition } ) ;
79
+ return currentPosition ;
72
80
}
73
81
74
82
/**
@@ -83,6 +91,11 @@ export class MouseClass {
83
91
return new Promise < MouseClass > ( async ( resolve , reject ) => {
84
92
try {
85
93
const pathSteps = await path ;
94
+ this . providerRegistry
95
+ . getLogProvider ( )
96
+ . info (
97
+ `Moving mouse to target point ${ pathSteps [ pathSteps . length - 1 ] } `
98
+ ) ;
86
99
const timeSteps = calculateMovementTimesteps (
87
100
pathSteps . length ,
88
101
this . config . mouseSpeed ,
@@ -96,6 +109,7 @@ export class MouseClass {
96
109
}
97
110
resolve ( this ) ;
98
111
} catch ( e ) {
112
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
99
113
reject ( e ) ;
100
114
}
101
115
} ) ;
@@ -125,8 +139,12 @@ export class MouseClass {
125
139
try {
126
140
await sleep ( this . config . autoDelayMs ) ;
127
141
await this . providerRegistry . getMouse ( ) . scrollDown ( amount ) ;
142
+ this . providerRegistry
143
+ . getLogProvider ( )
144
+ . info ( `Scrolled down ${ amount } steps` ) ;
128
145
resolve ( this ) ;
129
146
} catch ( e ) {
147
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
130
148
reject ( e ) ;
131
149
}
132
150
} ) ;
@@ -142,8 +160,12 @@ export class MouseClass {
142
160
try {
143
161
await sleep ( this . config . autoDelayMs ) ;
144
162
await this . providerRegistry . getMouse ( ) . scrollUp ( amount ) ;
163
+ this . providerRegistry
164
+ . getLogProvider ( )
165
+ . info ( `Scrolled up ${ amount } steps` ) ;
145
166
resolve ( this ) ;
146
167
} catch ( e ) {
168
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
147
169
reject ( e ) ;
148
170
}
149
171
} ) ;
@@ -159,8 +181,12 @@ export class MouseClass {
159
181
try {
160
182
await sleep ( this . config . autoDelayMs ) ;
161
183
await this . providerRegistry . getMouse ( ) . scrollLeft ( amount ) ;
184
+ this . providerRegistry
185
+ . getLogProvider ( )
186
+ . info ( `Scrolled left ${ amount } steps` ) ;
162
187
resolve ( this ) ;
163
188
} catch ( e ) {
189
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
164
190
reject ( e ) ;
165
191
}
166
192
} ) ;
@@ -176,8 +202,12 @@ export class MouseClass {
176
202
try {
177
203
await sleep ( this . config . autoDelayMs ) ;
178
204
await this . providerRegistry . getMouse ( ) . scrollRight ( amount ) ;
205
+ this . providerRegistry
206
+ . getLogProvider ( )
207
+ . info ( `Scrolled right ${ amount } steps` ) ;
179
208
resolve ( this ) ;
180
209
} catch ( e ) {
210
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
181
211
reject ( e ) ;
182
212
}
183
213
} ) ;
@@ -193,10 +223,17 @@ export class MouseClass {
193
223
try {
194
224
await sleep ( this . config . autoDelayMs ) ;
195
225
await this . providerRegistry . getMouse ( ) . pressButton ( Button . LEFT ) ;
226
+ this . providerRegistry
227
+ . getLogProvider ( )
228
+ . info ( "Pressed left mouse button" ) ;
196
229
await this . move ( path ) ;
197
230
await this . providerRegistry . getMouse ( ) . releaseButton ( Button . LEFT ) ;
231
+ this . providerRegistry
232
+ . getLogProvider ( )
233
+ . info ( "Released left mouse button" ) ;
198
234
resolve ( this ) ;
199
235
} catch ( e ) {
236
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
200
237
reject ( e ) ;
201
238
}
202
239
} ) ;
@@ -211,8 +248,20 @@ export class MouseClass {
211
248
try {
212
249
await sleep ( this . config . autoDelayMs ) ;
213
250
await this . providerRegistry . getMouse ( ) . pressButton ( btn ) ;
251
+ this . providerRegistry
252
+ . getLogProvider ( )
253
+ . info (
254
+ `Pressed mouse button ${
255
+ btn === Button . LEFT
256
+ ? "left"
257
+ : btn === Button . MIDDLE
258
+ ? "middle"
259
+ : "right"
260
+ } `
261
+ ) ;
214
262
resolve ( this ) ;
215
263
} catch ( e ) {
264
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
216
265
reject ( e ) ;
217
266
}
218
267
} ) ;
@@ -227,8 +276,20 @@ export class MouseClass {
227
276
try {
228
277
await sleep ( this . config . autoDelayMs ) ;
229
278
await this . providerRegistry . getMouse ( ) . releaseButton ( btn ) ;
279
+ this . providerRegistry
280
+ . getLogProvider ( )
281
+ . info (
282
+ `Released mouse button ${
283
+ btn === Button . LEFT
284
+ ? "left"
285
+ : btn === Button . MIDDLE
286
+ ? "middle"
287
+ : "right"
288
+ } `
289
+ ) ;
230
290
resolve ( this ) ;
231
291
} catch ( e ) {
292
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
232
293
reject ( e ) ;
233
294
}
234
295
} ) ;
@@ -243,8 +304,20 @@ export class MouseClass {
243
304
try {
244
305
await sleep ( this . config . autoDelayMs ) ;
245
306
await this . providerRegistry . getMouse ( ) . click ( btn ) ;
307
+ this . providerRegistry
308
+ . getLogProvider ( )
309
+ . info (
310
+ `Clicked ${
311
+ btn === Button . LEFT
312
+ ? "left"
313
+ : btn === Button . MIDDLE
314
+ ? "middle"
315
+ : "right"
316
+ } button`
317
+ ) ;
246
318
resolve ( this ) ;
247
319
} catch ( e ) {
320
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
248
321
reject ( e ) ;
249
322
}
250
323
} ) ;
@@ -259,8 +332,20 @@ export class MouseClass {
259
332
try {
260
333
await sleep ( this . config . autoDelayMs ) ;
261
334
await this . providerRegistry . getMouse ( ) . doubleClick ( btn ) ;
335
+ this . providerRegistry
336
+ . getLogProvider ( )
337
+ . info (
338
+ `Double-clicked ${
339
+ btn === Button . LEFT
340
+ ? "left"
341
+ : btn === Button . MIDDLE
342
+ ? "middle"
343
+ : "right"
344
+ } button`
345
+ ) ;
262
346
resolve ( this ) ;
263
347
} catch ( e ) {
348
+ this . providerRegistry . getLogProvider ( ) . error ( e as Error ) ;
264
349
reject ( e ) ;
265
350
}
266
351
} ) ;
0 commit comments