@@ -17,9 +17,13 @@ export class Mouse {
17
17
}
18
18
19
19
public async setPosition ( target : Point ) : Promise < Mouse > {
20
- return new Promise < Mouse > ( async resolve => {
21
- await this . native . setMousePosition ( target ) ;
22
- resolve ( this ) ;
20
+ return new Promise < Mouse > ( async ( resolve , reject ) => {
21
+ try {
22
+ await this . native . setMousePosition ( target ) ;
23
+ resolve ( this ) ;
24
+ } catch ( e ) {
25
+ reject ( e ) ;
26
+ }
23
27
} ) ;
24
28
}
25
29
@@ -28,16 +32,20 @@ export class Mouse {
28
32
}
29
33
30
34
public async move ( path : Point [ ] , movementType = MovementType . linear ) : Promise < Mouse > {
31
- return new Promise < Mouse > ( async resolve => {
32
- const timeSteps = movementType ( path . length , this . config . mouseSpeed ) ;
33
- for ( let idx = 0 ; idx < path . length ; ++ idx ) {
34
- const node = path [ idx ] ;
35
- const minTime = timeSteps [ idx ] ;
36
- await this . waitForNextTick ( minTime ) ;
37
- await this . native . setMousePosition ( node ) ;
38
- await this . updateTick ( ) ;
35
+ return new Promise < Mouse > ( async ( resolve , reject ) => {
36
+ try {
37
+ const timeSteps = movementType ( path . length , this . config . mouseSpeed ) ;
38
+ for ( let idx = 0 ; idx < path . length ; ++ idx ) {
39
+ const node = path [ idx ] ;
40
+ const minTime = timeSteps [ idx ] ;
41
+ await this . waitForNextTick ( minTime ) ;
42
+ await this . native . setMousePosition ( node ) ;
43
+ await this . updateTick ( ) ;
44
+ }
45
+ resolve ( this ) ;
46
+ } catch ( e ) {
47
+ reject ( e ) ;
39
48
}
40
- resolve ( this ) ;
41
49
} ) ;
42
50
}
43
51
@@ -51,58 +59,82 @@ export class Mouse {
51
59
}
52
60
53
61
public async rightClick ( ) : Promise < Mouse > {
54
- return new Promise < Mouse > ( async resolve => {
55
- await this . waitForNextTick ( this . config . autoDelayMs ) ;
56
- await this . native . rightClick ( ) ;
57
- await this . updateTick ( ) ;
58
- resolve ( this ) ;
62
+ return new Promise < Mouse > ( async ( resolve , reject ) => {
63
+ try {
64
+ await this . waitForNextTick ( this . config . autoDelayMs ) ;
65
+ await this . native . rightClick ( ) ;
66
+ await this . updateTick ( ) ;
67
+ resolve ( this ) ;
68
+ } catch ( e ) {
69
+ reject ( e ) ;
70
+ }
59
71
} ) ;
60
72
}
61
73
62
74
public async scrollDown ( amount : number ) : Promise < Mouse > {
63
- return new Promise < Mouse > ( async resolve => {
64
- await this . waitForNextTick ( this . config . autoDelayMs ) ;
65
- await this . native . scrollDown ( amount ) ;
66
- await this . updateTick ( ) ;
67
- resolve ( this ) ;
75
+ return new Promise < Mouse > ( async ( resolve , reject ) => {
76
+ try {
77
+ await this . waitForNextTick ( this . config . autoDelayMs ) ;
78
+ await this . native . scrollDown ( amount ) ;
79
+ await this . updateTick ( ) ;
80
+ resolve ( this ) ;
81
+ } catch ( e ) {
82
+ reject ( e ) ;
83
+ }
68
84
} ) ;
69
85
}
70
86
71
87
public async scrollUp ( amount : number ) : Promise < Mouse > {
72
- return new Promise < Mouse > ( async resolve => {
73
- await this . waitForNextTick ( this . config . autoDelayMs ) ;
74
- await this . native . scrollUp ( amount ) ;
75
- await this . updateTick ( ) ;
76
- resolve ( this ) ;
88
+ return new Promise < Mouse > ( async ( resolve , reject ) => {
89
+ try {
90
+ await this . waitForNextTick ( this . config . autoDelayMs ) ;
91
+ await this . native . scrollUp ( amount ) ;
92
+ await this . updateTick ( ) ;
93
+ resolve ( this ) ;
94
+ } catch ( e ) {
95
+ reject ( e ) ;
96
+ }
77
97
} ) ;
78
98
}
79
99
80
100
public async scrollLeft ( amount : number ) : Promise < Mouse > {
81
- return new Promise < Mouse > ( async resolve => {
82
- await this . waitForNextTick ( this . config . autoDelayMs ) ;
83
- await this . native . scrollLeft ( amount ) ;
84
- await this . updateTick ( ) ;
85
- resolve ( this ) ;
101
+ return new Promise < Mouse > ( async ( resolve , reject ) => {
102
+ try {
103
+ await this . waitForNextTick ( this . config . autoDelayMs ) ;
104
+ await this . native . scrollLeft ( amount ) ;
105
+ await this . updateTick ( ) ;
106
+ resolve ( this ) ;
107
+ } catch ( e ) {
108
+ reject ( e ) ;
109
+ }
86
110
} ) ;
87
111
}
88
112
89
113
public async scrollRight ( amount : number ) : Promise < Mouse > {
90
- return new Promise < Mouse > ( async resolve => {
91
- await this . waitForNextTick ( this . config . autoDelayMs ) ;
92
- await this . native . scrollRight ( amount ) ;
93
- await this . updateTick ( ) ;
94
- resolve ( this ) ;
114
+ return new Promise < Mouse > ( async ( resolve , reject ) => {
115
+ try {
116
+ await this . waitForNextTick ( this . config . autoDelayMs ) ;
117
+ await this . native . scrollRight ( amount ) ;
118
+ await this . updateTick ( ) ;
119
+ resolve ( this ) ;
120
+ } catch ( e ) {
121
+ reject ( e ) ;
122
+ }
95
123
} ) ;
96
124
}
97
125
98
126
public async drag ( path : Point [ ] ) : Promise < Mouse > {
99
- return new Promise < Mouse > ( async resolve => {
100
- await this . waitForNextTick ( this . config . autoDelayMs ) ;
101
- await this . native . pressButton ( Button . LEFT ) ;
102
- await this . move ( path ) ;
103
- await this . native . releaseButton ( Button . LEFT ) ;
104
- await this . updateTick ( ) ;
105
- resolve ( this ) ;
127
+ return new Promise < Mouse > ( async ( resolve , reject ) => {
128
+ try {
129
+ await this . waitForNextTick ( this . config . autoDelayMs ) ;
130
+ await this . native . pressButton ( Button . LEFT ) ;
131
+ await this . move ( path ) ;
132
+ await this . native . releaseButton ( Button . LEFT ) ;
133
+ await this . updateTick ( ) ;
134
+ resolve ( this ) ;
135
+ } catch ( e ) {
136
+ reject ( e ) ;
137
+ }
106
138
} ) ;
107
139
}
108
140
0 commit comments