assistsx-js 0.0.1333 → 0.0.1340

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ven
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -13,6 +13,8 @@
13
13
 
14
14
  > 下载安装后会默认安装一个示例插件,可长按删除
15
15
 
16
+ **[Assistsx源码](https://github.com/ven-coder/assistsx)**
17
+
16
18
  # 快速开始
17
19
  ## 1. 创建项目
18
20
  - 创建`vite`模版项目:`npm create vite@latest assistsx-helloword -- --template vue`
@@ -72,7 +72,7 @@ export declare class AssistsX {
72
72
  */
73
73
  static takeScreenshotNodes(nodes: Node[], overlayHiddenScreenshotDelayMillis?: number): Promise<string[]>;
74
74
  static scanQR(): Promise<string>;
75
- static addWebFloatingWindow(url: string, options?: WebFloatingWindowOptions): Promise<any>;
75
+ static loadWebViewOverlay(url: string, options?: WebFloatingWindowOptions): Promise<any>;
76
76
  /**
77
77
  * 点击节点
78
78
  * @param node 要点击的节点
@@ -213,7 +213,7 @@ export declare class AssistsX {
213
213
  * @param duration 持续时间
214
214
  * @returns 是否成功
215
215
  */
216
- static gestureClick(x: number, y: number, duration: number): boolean;
216
+ static clickByGesture(x: number, y: number, duration: number): Promise<boolean>;
217
217
  /**
218
218
  * 返回操作
219
219
  * @returns 是否成功
@@ -270,7 +270,7 @@ export declare class AssistsX {
270
270
  * @param clickDuration 点击持续时间
271
271
  * @returns 是否成功
272
272
  */
273
- static nodeGestureClick(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration }?: {
273
+ static clickNodeByGesture(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration }?: {
274
274
  offsetX?: number;
275
275
  offsetY?: number;
276
276
  switchWindowIntervalDelay?: number;
@@ -286,13 +286,30 @@ export declare class AssistsX {
286
286
  * @param clickInterval 点击间隔
287
287
  * @returns 是否成功
288
288
  */
289
- static nodeGestureClickByDouble(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval }?: {
289
+ static doubleClickNodeByGesture(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval }?: {
290
290
  offsetX?: number;
291
291
  offsetY?: number;
292
292
  switchWindowIntervalDelay?: number;
293
293
  clickDuration?: number;
294
294
  clickInterval?: number;
295
295
  }): Promise<boolean>;
296
+ /**
297
+ * 执行线型手势
298
+ * @param startPoint
299
+ * @param endPoint
300
+ * @param param2
301
+ * @returns
302
+ */
303
+ static performLinearGesture(startPoint: {
304
+ x: number;
305
+ y: number;
306
+ }, endPoint: {
307
+ x: number;
308
+ y: number;
309
+ }, { duration }?: {
310
+ duration?: number;
311
+ }): Promise<boolean>;
312
+ static getAppInfo(packageName: string): Promise<any>;
296
313
  /**
297
314
  * 获取屏幕尺寸
298
315
  * @returns 屏幕尺寸对象
package/dist/AssistsX.js CHANGED
@@ -144,9 +144,9 @@ export class AssistsX {
144
144
  const data = response.getDataOrDefault({ value: "" });
145
145
  return data.value;
146
146
  }
147
- static async addWebFloatingWindow(url, options = {}) {
147
+ static async loadWebViewOverlay(url, options = {}) {
148
148
  const { initialWidth, initialHeight, minWidth, minHeight, maxWidth, maxHeight, initialCenter } = options;
149
- const response = await this.asyncCall(CallMethod.addWebFloatingWindow, { args: { url, initialWidth, initialHeight, minWidth, minHeight, maxWidth, maxHeight, initialCenter } });
149
+ const response = await this.asyncCall(CallMethod.loadWebViewOverlay, { args: { url, initialWidth, initialHeight, minWidth, minHeight, maxWidth, maxHeight, initialCenter } });
150
150
  const data = response.getDataOrDefault({});
151
151
  return data;
152
152
  }
@@ -323,8 +323,8 @@ export class AssistsX {
323
323
  * @param duration 持续时间
324
324
  * @returns 是否成功
325
325
  */
326
- static gestureClick(x, y, duration) {
327
- const response = this.call(CallMethod.gestureClick, { args: { x, y, duration } });
326
+ static async clickByGesture(x, y, duration) {
327
+ const response = await this.asyncCall(CallMethod.clickByGesture, { args: { x, y, duration } });
328
328
  return response.getDataOrDefault(false);
329
329
  }
330
330
  /**
@@ -407,8 +407,8 @@ export class AssistsX {
407
407
  * @param clickDuration 点击持续时间
408
408
  * @returns 是否成功
409
409
  */
410
- static async nodeGestureClick(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration } = {}) {
411
- const response = await this.asyncCall(CallMethod.nodeGestureClick, { node, args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration } });
410
+ static async clickNodeByGesture(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration } = {}) {
411
+ const response = await this.asyncCall(CallMethod.clickNodeByGesture, { node, args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration } });
412
412
  return response.getDataOrDefault(false);
413
413
  }
414
414
  /**
@@ -421,10 +421,25 @@ export class AssistsX {
421
421
  * @param clickInterval 点击间隔
422
422
  * @returns 是否成功
423
423
  */
424
- static async nodeGestureClickByDouble(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval } = {}) {
425
- const response = await this.asyncCall(CallMethod.nodeGestureClickByDouble, { node, args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval } });
424
+ static async doubleClickNodeByGesture(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval } = {}) {
425
+ const response = await this.asyncCall(CallMethod.doubleClickNodeByGesture, { node, args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval } });
426
426
  return response.getDataOrDefault(false);
427
427
  }
428
+ /**
429
+ * 执行线型手势
430
+ * @param startPoint
431
+ * @param endPoint
432
+ * @param param2
433
+ * @returns
434
+ */
435
+ static async performLinearGesture(startPoint, endPoint, { duration } = {}) {
436
+ const response = await this.asyncCall(CallMethod.performLinearGesture, { args: { startPoint, endPoint, duration } });
437
+ return response.getDataOrDefault(false);
438
+ }
439
+ static async getAppInfo(packageName) {
440
+ const response = await this.asyncCall(CallMethod.getAppInfo, { args: { packageName } });
441
+ return response.getDataOrDefault({});
442
+ }
428
443
  /**
429
444
  * 获取屏幕尺寸
430
445
  * @returns 屏幕尺寸对象
@@ -13,12 +13,10 @@ export declare const CallMethod: {
13
13
  readonly getNodes: "getNodes";
14
14
  readonly findFirstParentClickable: "findFirstParentClickable";
15
15
  readonly getChildren: "getChildren";
16
- readonly dispatchGesture: "dispatchGesture";
17
16
  readonly getBoundsInScreen: "getBoundsInScreen";
18
17
  readonly isVisible: "isVisible";
19
18
  readonly click: "click";
20
19
  readonly longClick: "longClick";
21
- readonly gestureClick: "gestureClick";
22
20
  readonly back: "back";
23
21
  readonly home: "home";
24
22
  readonly notifications: "notifications";
@@ -30,11 +28,14 @@ export declare const CallMethod: {
30
28
  readonly getPackageName: "getPackageName";
31
29
  readonly getScreenSize: "getScreenSize";
32
30
  readonly getAppScreenSize: "getAppScreenSize";
33
- readonly nodeGestureClick: "nodeGestureClick";
34
- readonly nodeGestureClickByDouble: "nodeGestureClickByDouble";
35
31
  readonly scrollBackward: "scrollBackward";
36
32
  readonly setOverlayFlags: "setOverlayFlags";
37
33
  readonly scanQR: "scanQR";
38
- readonly addWebFloatingWindow: "addWebFloatingWindow";
34
+ readonly loadWebViewOverlay: "loadWebViewOverlay";
35
+ readonly clickByGesture: "clickByGesture";
36
+ readonly clickNodeByGesture: "clickNodeByGesture";
37
+ readonly doubleClickNodeByGesture: "doubleClickNodeByGesture";
38
+ readonly performLinearGesture: "performLinearGesture";
39
+ readonly getAppInfo: "getAppInfo";
39
40
  };
40
41
  export type CallMethodType = typeof CallMethod[keyof typeof CallMethod];
@@ -14,12 +14,10 @@ export const CallMethod = {
14
14
  getNodes: "getNodes",
15
15
  findFirstParentClickable: "findFirstParentClickable",
16
16
  getChildren: "getChildren",
17
- dispatchGesture: "dispatchGesture",
18
17
  getBoundsInScreen: "getBoundsInScreen",
19
18
  isVisible: "isVisible",
20
19
  click: "click",
21
20
  longClick: "longClick",
22
- gestureClick: "gestureClick",
23
21
  back: "back",
24
22
  home: "home",
25
23
  notifications: "notifications",
@@ -31,10 +29,13 @@ export const CallMethod = {
31
29
  getPackageName: "getPackageName",
32
30
  getScreenSize: "getScreenSize",
33
31
  getAppScreenSize: "getAppScreenSize",
34
- nodeGestureClick: "nodeGestureClick",
35
- nodeGestureClickByDouble: "nodeGestureClickByDouble",
36
32
  scrollBackward: "scrollBackward",
37
33
  setOverlayFlags: "setOverlayFlags",
38
34
  scanQR: "scanQR",
39
- addWebFloatingWindow: "addWebFloatingWindow"
35
+ loadWebViewOverlay: "loadWebViewOverlay",
36
+ clickByGesture: "clickByGesture",
37
+ clickNodeByGesture: "clickNodeByGesture",
38
+ doubleClickNodeByGesture: "doubleClickNodeByGesture",
39
+ performLinearGesture: "performLinearGesture",
40
+ getAppInfo: "getAppInfo",
40
41
  };
package/dist/Node.d.ts CHANGED
@@ -63,7 +63,7 @@ export declare class Node {
63
63
  * @param clickDuration 点击持续时间
64
64
  * @returns 是否点击成功
65
65
  */
66
- nodeGestureClick({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration }?: {
66
+ clickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration }?: {
67
67
  offsetX?: number;
68
68
  offsetY?: number;
69
69
  switchWindowIntervalDelay?: number;
@@ -78,7 +78,7 @@ export declare class Node {
78
78
  * @param clickInterval 点击间隔
79
79
  * @returns 是否双击成功
80
80
  */
81
- nodeGestureClickByDouble({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval }?: {
81
+ doubleClickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval }?: {
82
82
  offsetX?: number;
83
83
  offsetY?: number;
84
84
  switchWindowIntervalDelay?: number;
package/dist/Node.js CHANGED
@@ -25,9 +25,9 @@ export class Node {
25
25
  * @param clickDuration 点击持续时间
26
26
  * @returns 是否点击成功
27
27
  */
28
- async nodeGestureClick({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration } = {}) {
28
+ async clickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration } = {}) {
29
29
  Step.assert(this.stepId);
30
- const result = await AssistsX.nodeGestureClick(this, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration });
30
+ const result = await AssistsX.clickNodeByGesture(this, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration });
31
31
  Step.assert(this.stepId);
32
32
  return result;
33
33
  }
@@ -40,9 +40,9 @@ export class Node {
40
40
  * @param clickInterval 点击间隔
41
41
  * @returns 是否双击成功
42
42
  */
43
- async nodeGestureClickByDouble({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval } = {}) {
43
+ async doubleClickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval } = {}) {
44
44
  Step.assert(this.stepId);
45
- const result = await AssistsX.nodeGestureClickByDouble(this, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval });
45
+ const result = await AssistsX.doubleClickNodeByGesture(this, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval });
46
46
  Step.assert(this.stepId);
47
47
  return result;
48
48
  }
package/dist/Step.d.ts CHANGED
@@ -3,6 +3,7 @@ export declare class Step {
3
3
  static delayMsDefault: number;
4
4
  static readonly repeatCountInfinite: number;
5
5
  static repeatCountMaxDefault: number;
6
+ static showLog: boolean;
6
7
  /**
7
8
  * 当前执行步骤的ID
8
9
  */
@@ -231,7 +232,17 @@ export declare class Step {
231
232
  * @param duration 持续时间(毫秒)
232
233
  * @returns 是否成功
233
234
  */
234
- gestureClick(x: number, y: number, duration: number): boolean;
235
+ clickByGesture(x: number, y: number, duration: number): Promise<boolean>;
236
+ getAppInfo(packageName: string): Promise<any>;
237
+ performLinearGesture(startPoint: {
238
+ x: number;
239
+ y: number;
240
+ }, endPoint: {
241
+ x: number;
242
+ y: number;
243
+ }, { duration }?: {
244
+ duration?: number;
245
+ }): Promise<boolean>;
235
246
  /**
236
247
  * 返回操作
237
248
  * @returns 是否成功
package/dist/Step.js CHANGED
@@ -24,16 +24,22 @@ export class Step {
24
24
  let step = new Step({ stepId: this._stepId, impl, tag, data, delayMs });
25
25
  while (true) {
26
26
  if (step.delayMs) {
27
- console.log(`延迟${step.delayMs}毫秒`);
27
+ if (Step.showLog) {
28
+ console.log(`延迟${step.delayMs}毫秒`);
29
+ }
28
30
  await step.delay(step.delayMs);
29
31
  Step.assert(step.stepId);
30
32
  }
31
33
  //执行步骤
32
34
  implnName = step.impl.name;
33
- console.log(`执行步骤${implnName},重复次数${step.repeatCount}`);
35
+ if (Step.showLog) {
36
+ console.log(`执行步骤${implnName},重复次数${step.repeatCount}`);
37
+ }
34
38
  const nextStep = await step.impl(step);
35
39
  if (step.repeatCountMax > Step.repeatCountInfinite && step.repeatCount > step.repeatCountMax) {
36
- console.log(`重复次数${step.repeatCount}超过最大次数${step.repeatCountMax},停止执行`);
40
+ if (Step.showLog) {
41
+ console.log(`重复次数${step.repeatCount}超过最大次数${step.repeatCountMax},停止执行`);
42
+ }
37
43
  break;
38
44
  }
39
45
  Step.assert(step.stepId);
@@ -46,7 +52,9 @@ export class Step {
46
52
  }
47
53
  }
48
54
  catch (e) {
49
- console.error(`步骤${implnName}执行出错`, e);
55
+ if (Step.showLog) {
56
+ console.error(`步骤${implnName}执行出错`, e);
57
+ }
50
58
  //步骤执行出错
51
59
  const errorMsg = JSON.stringify({
52
60
  impl: implnName,
@@ -341,9 +349,21 @@ export class Step {
341
349
  * @param duration 持续时间(毫秒)
342
350
  * @returns 是否成功
343
351
  */
344
- gestureClick(x, y, duration) {
352
+ async clickByGesture(x, y, duration) {
353
+ Step.assert(this.stepId);
354
+ const result = await AssistsX.clickByGesture(x, y, duration);
355
+ Step.assert(this.stepId);
356
+ return result;
357
+ }
358
+ async getAppInfo(packageName) {
359
+ Step.assert(this.stepId);
360
+ const result = await AssistsX.getAppInfo(packageName);
361
+ Step.assert(this.stepId);
362
+ return result;
363
+ }
364
+ async performLinearGesture(startPoint, endPoint, { duration } = {}) {
345
365
  Step.assert(this.stepId);
346
- const result = AssistsX.gestureClick(x, y, duration);
366
+ const result = await AssistsX.performLinearGesture(startPoint, endPoint, { duration });
347
367
  Step.assert(this.stepId);
348
368
  return result;
349
369
  }
@@ -411,6 +431,7 @@ export class Step {
411
431
  Step.delayMsDefault = 1000;
412
432
  Step.repeatCountInfinite = -1;
413
433
  Step.repeatCountMaxDefault = Step.repeatCountInfinite;
434
+ Step.showLog = false;
414
435
  /**
415
436
  * 当前执行步骤的ID
416
437
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistsx-js",
3
- "version": "0.0.1333",
3
+ "version": "0.0.1340",
4
4
  "description": "assistsx-js自动化开发SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "dev"
34
34
  ],
35
35
  "author": "Ven",
36
- "license": "ISC",
36
+ "license": "MIT",
37
37
  "devDependencies": {
38
38
  "typescript": "^5.3.3"
39
39
  },
package/src/AssistsX.ts CHANGED
@@ -175,10 +175,10 @@ export class AssistsX {
175
175
  const data = response.getDataOrDefault({ value: "" });
176
176
  return data.value;
177
177
  }
178
- public static async addWebFloatingWindow(url: string, options: WebFloatingWindowOptions = {}): Promise<any> {
178
+ public static async loadWebViewOverlay(url: string, options: WebFloatingWindowOptions = {}): Promise<any> {
179
179
  const { initialWidth, initialHeight, minWidth, minHeight, maxWidth, maxHeight, initialCenter } = options;
180
180
  const response = await this.asyncCall(
181
- CallMethod.addWebFloatingWindow,
181
+ CallMethod.loadWebViewOverlay,
182
182
  { args: { url, initialWidth, initialHeight, minWidth, minHeight, maxWidth, maxHeight, initialCenter } }
183
183
  );
184
184
  const data = response.getDataOrDefault({});
@@ -375,8 +375,8 @@ export class AssistsX {
375
375
  * @param duration 持续时间
376
376
  * @returns 是否成功
377
377
  */
378
- public static gestureClick(x: number, y: number, duration: number): boolean {
379
- const response = this.call(CallMethod.gestureClick, { args: { x, y, duration } });
378
+ public static async clickByGesture(x: number, y: number, duration: number): Promise<boolean> {
379
+ const response = await this.asyncCall(CallMethod.clickByGesture, { args: { x, y, duration } });
380
380
  return response.getDataOrDefault(false);
381
381
  }
382
382
 
@@ -468,8 +468,8 @@ export class AssistsX {
468
468
  * @param clickDuration 点击持续时间
469
469
  * @returns 是否成功
470
470
  */
471
- public static async nodeGestureClick(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration }: { offsetX?: number, offsetY?: number, switchWindowIntervalDelay?: number, clickDuration?: number } = {}): Promise<boolean> {
472
- const response = await this.asyncCall(CallMethod.nodeGestureClick, { node, args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration } });
471
+ public static async clickNodeByGesture(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration }: { offsetX?: number, offsetY?: number, switchWindowIntervalDelay?: number, clickDuration?: number } = {}): Promise<boolean> {
472
+ const response = await this.asyncCall(CallMethod.clickNodeByGesture, { node, args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration } });
473
473
  return response.getDataOrDefault(false);
474
474
  }
475
475
 
@@ -483,11 +483,26 @@ export class AssistsX {
483
483
  * @param clickInterval 点击间隔
484
484
  * @returns 是否成功
485
485
  */
486
- public static async nodeGestureClickByDouble(node: Node,
486
+ public static async doubleClickNodeByGesture(node: Node,
487
487
  { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval }: { offsetX?: number, offsetY?: number, switchWindowIntervalDelay?: number, clickDuration?: number, clickInterval?: number } = {}): Promise<boolean> {
488
- const response = await this.asyncCall(CallMethod.nodeGestureClickByDouble, { node, args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval } });
488
+ const response = await this.asyncCall(CallMethod.doubleClickNodeByGesture, { node, args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval } });
489
489
  return response.getDataOrDefault(false);
490
490
  }
491
+ /**
492
+ * 执行线型手势
493
+ * @param startPoint
494
+ * @param endPoint
495
+ * @param param2
496
+ * @returns
497
+ */
498
+ public static async performLinearGesture(startPoint: { x: number, y: number }, endPoint: { x: number, y: number }, { duration }: { duration?: number } = {}): Promise<boolean> {
499
+ const response = await this.asyncCall(CallMethod.performLinearGesture, { args: { startPoint, endPoint, duration } });
500
+ return response.getDataOrDefault(false);
501
+ }
502
+ public static async getAppInfo(packageName: string): Promise<any> {
503
+ const response = await this.asyncCall(CallMethod.getAppInfo, { args: { packageName } });
504
+ return response.getDataOrDefault({});
505
+ }
491
506
 
492
507
  /**
493
508
  * 获取屏幕尺寸
package/src/CallMethod.ts CHANGED
@@ -14,12 +14,10 @@ export const CallMethod = {
14
14
  getNodes: "getNodes",
15
15
  findFirstParentClickable: "findFirstParentClickable",
16
16
  getChildren: "getChildren",
17
- dispatchGesture: "dispatchGesture",
18
17
  getBoundsInScreen: "getBoundsInScreen",
19
18
  isVisible: "isVisible",
20
19
  click: "click",
21
20
  longClick: "longClick",
22
- gestureClick: "gestureClick",
23
21
  back: "back",
24
22
  home: "home",
25
23
  notifications: "notifications",
@@ -31,12 +29,17 @@ export const CallMethod = {
31
29
  getPackageName: "getPackageName",
32
30
  getScreenSize: "getScreenSize",
33
31
  getAppScreenSize: "getAppScreenSize",
34
- nodeGestureClick: "nodeGestureClick",
35
- nodeGestureClickByDouble: "nodeGestureClickByDouble",
36
32
  scrollBackward: "scrollBackward",
37
33
  setOverlayFlags: "setOverlayFlags",
38
34
  scanQR: "scanQR",
39
- addWebFloatingWindow: "addWebFloatingWindow"
35
+ loadWebViewOverlay: "loadWebViewOverlay",
36
+
37
+ clickByGesture: "clickByGesture",
38
+ clickNodeByGesture: "clickNodeByGesture",
39
+ doubleClickNodeByGesture: "doubleClickNodeByGesture",
40
+ performLinearGesture: "performLinearGesture",
41
+
42
+ getAppInfo: "getAppInfo",
40
43
  } as const;
41
44
 
42
45
  // 导出类型定义
package/src/Node.ts CHANGED
@@ -87,9 +87,9 @@ export class Node {
87
87
  * @param clickDuration 点击持续时间
88
88
  * @returns 是否点击成功
89
89
  */
90
- public async nodeGestureClick({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration }: { offsetX?: number, offsetY?: number, switchWindowIntervalDelay?: number, clickDuration?: number } = {}): Promise<boolean> {
90
+ public async clickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration }: { offsetX?: number, offsetY?: number, switchWindowIntervalDelay?: number, clickDuration?: number } = {}): Promise<boolean> {
91
91
  Step.assert(this.stepId);
92
- const result = await AssistsX.nodeGestureClick(this, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration });
92
+ const result = await AssistsX.clickNodeByGesture(this, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration });
93
93
  Step.assert(this.stepId);
94
94
  return result;
95
95
  }
@@ -102,9 +102,9 @@ export class Node {
102
102
  * @param clickInterval 点击间隔
103
103
  * @returns 是否双击成功
104
104
  */
105
- public async nodeGestureClickByDouble({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval }: { offsetX?: number, offsetY?: number, switchWindowIntervalDelay?: number, clickDuration?: number, clickInterval?: number } = {}): Promise<boolean> {
105
+ public async doubleClickNodeByGesture({ offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval }: { offsetX?: number, offsetY?: number, switchWindowIntervalDelay?: number, clickDuration?: number, clickInterval?: number } = {}): Promise<boolean> {
106
106
  Step.assert(this.stepId);
107
- const result = await AssistsX.nodeGestureClickByDouble(this, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval });
107
+ const result = await AssistsX.doubleClickNodeByGesture(this, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval });
108
108
  Step.assert(this.stepId);
109
109
  return result;
110
110
  }
package/src/Step.ts CHANGED
@@ -14,6 +14,7 @@ export class Step {
14
14
  static delayMsDefault: number = 1000;
15
15
  static readonly repeatCountInfinite: number = -1;
16
16
  static repeatCountMaxDefault: number = Step.repeatCountInfinite;
17
+ static showLog: boolean = false;
17
18
 
18
19
  /**
19
20
  * 当前执行步骤的ID
@@ -38,16 +39,22 @@ export class Step {
38
39
  let step = new Step({ stepId: this._stepId, impl, tag, data, delayMs });
39
40
  while (true) {
40
41
  if (step.delayMs) {
41
- console.log(`延迟${step.delayMs}毫秒`)
42
+ if (Step.showLog) {
43
+ console.log(`延迟${step.delayMs}毫秒`)
44
+ }
42
45
  await step.delay(step.delayMs);
43
46
  Step.assert(step.stepId);
44
47
  }
45
48
  //执行步骤
46
49
  implnName = step.impl.name
47
- console.log(`执行步骤${implnName},重复次数${step.repeatCount}`)
50
+ if (Step.showLog) {
51
+ console.log(`执行步骤${implnName},重复次数${step.repeatCount}`)
52
+ }
48
53
  const nextStep = await step.impl(step);
49
54
  if (step.repeatCountMax > Step.repeatCountInfinite && step.repeatCount > step.repeatCountMax) {
50
- console.log(`重复次数${step.repeatCount}超过最大次数${step.repeatCountMax},停止执行`)
55
+ if (Step.showLog) {
56
+ console.log(`重复次数${step.repeatCount}超过最大次数${step.repeatCountMax},停止执行`)
57
+ }
51
58
  break;
52
59
  }
53
60
 
@@ -60,7 +67,9 @@ export class Step {
60
67
  }
61
68
 
62
69
  } catch (e: any) {
63
- console.error(`步骤${implnName}执行出错`, e)
70
+ if (Step.showLog) {
71
+ console.error(`步骤${implnName}执行出错`, e)
72
+ }
64
73
  //步骤执行出错
65
74
  const errorMsg = JSON.stringify({
66
75
  impl: implnName,
@@ -395,9 +404,21 @@ export class Step {
395
404
  * @param duration 持续时间(毫秒)
396
405
  * @returns 是否成功
397
406
  */
398
- public gestureClick(x: number, y: number, duration: number): boolean {
407
+ public async clickByGesture(x: number, y: number, duration: number): Promise<boolean> {
408
+ Step.assert(this.stepId);
409
+ const result = await AssistsX.clickByGesture(x, y, duration);
410
+ Step.assert(this.stepId);
411
+ return result;
412
+ }
413
+ public async getAppInfo(packageName: string): Promise<any> {
414
+ Step.assert(this.stepId);
415
+ const result = await AssistsX.getAppInfo(packageName);
416
+ Step.assert(this.stepId);
417
+ return result;
418
+ }
419
+ public async performLinearGesture(startPoint: { x: number, y: number }, endPoint: { x: number, y: number }, { duration }: { duration?: number } = {}): Promise<boolean> {
399
420
  Step.assert(this.stepId);
400
- const result = AssistsX.gestureClick(x, y, duration);
421
+ const result = await AssistsX.performLinearGesture(startPoint, endPoint, { duration });
401
422
  Step.assert(this.stepId);
402
423
  return result;
403
424
  }