assistsx-js 0.0.2024 → 0.0.2026

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.
@@ -78,12 +78,14 @@ export declare class AssistsX {
78
78
  * 执行异步调用
79
79
  * @param method 方法名
80
80
  * @param args 参数对象
81
+ * @param timeout 超时时间(秒),默认30秒
81
82
  * @returns Promise<调用响应>
82
83
  */
83
- static asyncCall(method: string, { args, node, nodes }?: {
84
+ static asyncCall(method: string, { args, node, nodes, timeout, }?: {
84
85
  args?: any;
85
86
  node?: Node;
86
87
  nodes?: Node[];
88
+ timeout?: number;
87
89
  }): Promise<CallResponse>;
88
90
  /**
89
91
  * 设置悬浮窗标志
@@ -118,15 +120,19 @@ export declare class AssistsX {
118
120
  * @returns 是否设置成功
119
121
  */
120
122
  static setNodeText(node: Node, text: string): boolean;
123
+ static isAppInstalled(packageName: string): boolean;
121
124
  /**
122
125
  * 对指定节点进行截图
123
126
  * @param nodes 要截图的节点数组
124
127
  * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
128
+ * @param timeout 超时时间(秒),默认30秒
125
129
  * @returns 截图路径数组
126
130
  */
127
- static takeScreenshotNodes(nodes: Node[], overlayHiddenScreenshotDelayMillis?: number): Promise<string[]>;
128
- static scanQR(): Promise<string>;
129
- static loadWebViewOverlay(url: string, options?: WebFloatingWindowOptions): Promise<any>;
131
+ static takeScreenshotNodes(nodes: Node[], overlayHiddenScreenshotDelayMillis?: number, timeout?: number): Promise<string[]>;
132
+ static scanQR(timeout?: number): Promise<string>;
133
+ static loadWebViewOverlay(url: string, options?: WebFloatingWindowOptions & {
134
+ timeout?: number;
135
+ }): Promise<any>;
130
136
  /**
131
137
  * 点击节点
132
138
  * @param node 要点击的节点
@@ -265,9 +271,10 @@ export declare class AssistsX {
265
271
  * @param x 横坐标
266
272
  * @param y 纵坐标
267
273
  * @param duration 持续时间
274
+ * @param timeout 超时时间(秒),默认30秒
268
275
  * @returns 是否成功
269
276
  */
270
- static clickByGesture(x: number, y: number, duration: number): Promise<boolean>;
277
+ static clickByGesture(x: number, y: number, duration: number, timeout?: number): Promise<boolean>;
271
278
  /**
272
279
  * 返回操作
273
280
  * @returns 是否成功
@@ -323,13 +330,15 @@ export declare class AssistsX {
323
330
  * @param offsetY Y轴偏移
324
331
  * @param switchWindowIntervalDelay 窗口切换延迟
325
332
  * @param clickDuration 点击持续时间
333
+ * @param timeout 超时时间(秒),默认30秒
326
334
  * @returns 是否成功
327
335
  */
328
- static clickNodeByGesture(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, }?: {
336
+ static clickNodeByGesture(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, timeout, }?: {
329
337
  offsetX?: number;
330
338
  offsetY?: number;
331
339
  switchWindowIntervalDelay?: number;
332
340
  clickDuration?: number;
341
+ timeout?: number;
333
342
  }): Promise<boolean>;
334
343
  /**
335
344
  * 对节点执行双击手势
@@ -339,20 +348,23 @@ export declare class AssistsX {
339
348
  * @param switchWindowIntervalDelay 窗口切换延迟
340
349
  * @param clickDuration 点击持续时间
341
350
  * @param clickInterval 点击间隔
351
+ * @param timeout 超时时间(秒),默认30秒
342
352
  * @returns 是否成功
343
353
  */
344
- static doubleClickNodeByGesture(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval, }?: {
354
+ static doubleClickNodeByGesture(node: Node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval, timeout, }?: {
345
355
  offsetX?: number;
346
356
  offsetY?: number;
347
357
  switchWindowIntervalDelay?: number;
348
358
  clickDuration?: number;
349
359
  clickInterval?: number;
360
+ timeout?: number;
350
361
  }): Promise<boolean>;
351
362
  /**
352
363
  * 执行线型手势
353
364
  * @param startPoint
354
365
  * @param endPoint
355
366
  * @param param2
367
+ * @param timeout 超时时间(秒),默认30秒
356
368
  * @returns
357
369
  */
358
370
  static performLinearGesture(startPoint: {
@@ -361,30 +373,33 @@ export declare class AssistsX {
361
373
  }, endPoint: {
362
374
  x: number;
363
375
  y: number;
364
- }, { duration }?: {
376
+ }, { duration, timeout }?: {
365
377
  duration?: number;
378
+ timeout?: number;
366
379
  }): Promise<boolean>;
367
- static longPressNodeByGestureAutoPaste(node: Node, text: string, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, }?: {
380
+ static longPressNodeByGestureAutoPaste(node: Node, text: string, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, timeout, }?: {
368
381
  matchedPackageName?: string;
369
382
  matchedText?: string;
370
383
  timeoutMillis?: number;
371
384
  longPressDuration?: number;
385
+ timeout?: number;
372
386
  }): Promise<boolean>;
373
387
  static longPressGestureAutoPaste(point: {
374
388
  x: number;
375
389
  y: number;
376
- }, text: string, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, }?: {
390
+ }, text: string, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, timeout, }?: {
377
391
  matchedPackageName?: string;
378
392
  matchedText?: string;
379
393
  timeoutMillis?: number;
380
394
  longPressDuration?: number;
395
+ timeout?: number;
381
396
  }): Promise<boolean>;
382
- static getAppInfo(packageName: string): Promise<any>;
397
+ static getAppInfo(packageName: string, timeout?: number): Promise<any>;
383
398
  static getUniqueDeviceId(): any;
384
399
  static getAndroidID(): any;
385
- static getMacAddress(): Promise<any>;
386
- static getDeviceInfo(): Promise<any>;
387
- static getNetworkType(): Promise<any>;
400
+ static getMacAddress(timeout?: number): Promise<any>;
401
+ static getDeviceInfo(timeout?: number): Promise<any>;
402
+ static getNetworkType(timeout?: number): Promise<any>;
388
403
  static setAccessibilityEventFilters(value: AccessibilityEventFilter[]): Promise<any>;
389
404
  static addAccessibilityEventFilter(value: AccessibilityEventFilter): Promise<any>;
390
405
  /**
package/dist/AssistsX.js CHANGED
@@ -79,9 +79,10 @@ export class AssistsX {
79
79
  * 执行异步调用
80
80
  * @param method 方法名
81
81
  * @param args 参数对象
82
+ * @param timeout 超时时间(秒),默认30秒
82
83
  * @returns Promise<调用响应>
83
84
  */
84
- static async asyncCall(method, { args, node, nodes } = {}) {
85
+ static async asyncCall(method, { args, node, nodes, timeout = 30, } = {}) {
85
86
  const uuid = generateUUID();
86
87
  const params = {
87
88
  method,
@@ -98,7 +99,7 @@ export class AssistsX {
98
99
  // 超时后删除回调函数
99
100
  callbacks.delete(uuid);
100
101
  resolve(new CallResponse(0, null, uuid));
101
- }, 1000 * 30);
102
+ }, timeout * 1000);
102
103
  });
103
104
  const result = window.assistsx.call(JSON.stringify(params));
104
105
  const promiseResult = await promise;
@@ -158,27 +159,35 @@ export class AssistsX {
158
159
  });
159
160
  return response.getDataOrDefault(false);
160
161
  }
162
+ static isAppInstalled(packageName) {
163
+ const response = this.call(CallMethod.isAppInstalled, {
164
+ args: { packageName },
165
+ });
166
+ return response.getDataOrDefault(false);
167
+ }
161
168
  /**
162
169
  * 对指定节点进行截图
163
170
  * @param nodes 要截图的节点数组
164
171
  * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
172
+ * @param timeout 超时时间(秒),默认30秒
165
173
  * @returns 截图路径数组
166
174
  */
167
- static async takeScreenshotNodes(nodes, overlayHiddenScreenshotDelayMillis = 250) {
175
+ static async takeScreenshotNodes(nodes, overlayHiddenScreenshotDelayMillis = 250, timeout) {
168
176
  const response = await this.asyncCall(CallMethod.takeScreenshot, {
169
177
  nodes,
170
178
  args: { overlayHiddenScreenshotDelayMillis },
179
+ timeout,
171
180
  });
172
181
  const data = response.getDataOrDefault("");
173
182
  return data.images;
174
183
  }
175
- static async scanQR() {
176
- const response = await this.asyncCall(CallMethod.scanQR);
184
+ static async scanQR(timeout) {
185
+ const response = await this.asyncCall(CallMethod.scanQR, { timeout });
177
186
  const data = response.getDataOrDefault({ value: "" });
178
187
  return data.value;
179
188
  }
180
189
  static async loadWebViewOverlay(url, options = {}) {
181
- const { initialWidth, initialHeight, minWidth, minHeight, maxWidth, maxHeight, initialCenter, } = options;
190
+ const { initialWidth, initialHeight, minWidth, minHeight, maxWidth, maxHeight, initialCenter, timeout, } = options;
182
191
  const response = await this.asyncCall(CallMethod.loadWebViewOverlay, {
183
192
  args: {
184
193
  url,
@@ -190,6 +199,7 @@ export class AssistsX {
190
199
  maxHeight,
191
200
  initialCenter,
192
201
  },
202
+ timeout,
193
203
  });
194
204
  const data = response.getDataOrDefault({});
195
205
  return data;
@@ -384,11 +394,13 @@ export class AssistsX {
384
394
  * @param x 横坐标
385
395
  * @param y 纵坐标
386
396
  * @param duration 持续时间
397
+ * @param timeout 超时时间(秒),默认30秒
387
398
  * @returns 是否成功
388
399
  */
389
- static async clickByGesture(x, y, duration) {
400
+ static async clickByGesture(x, y, duration, timeout) {
390
401
  const response = await this.asyncCall(CallMethod.clickByGesture, {
391
402
  args: { x, y, duration },
403
+ timeout,
392
404
  });
393
405
  return response.getDataOrDefault(false);
394
406
  }
@@ -477,12 +489,14 @@ export class AssistsX {
477
489
  * @param offsetY Y轴偏移
478
490
  * @param switchWindowIntervalDelay 窗口切换延迟
479
491
  * @param clickDuration 点击持续时间
492
+ * @param timeout 超时时间(秒),默认30秒
480
493
  * @returns 是否成功
481
494
  */
482
- static async clickNodeByGesture(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, } = {}) {
495
+ static async clickNodeByGesture(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, timeout, } = {}) {
483
496
  const response = await this.asyncCall(CallMethod.clickNodeByGesture, {
484
497
  node,
485
498
  args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration },
499
+ timeout,
486
500
  });
487
501
  return response.getDataOrDefault(false);
488
502
  }
@@ -494,9 +508,10 @@ export class AssistsX {
494
508
  * @param switchWindowIntervalDelay 窗口切换延迟
495
509
  * @param clickDuration 点击持续时间
496
510
  * @param clickInterval 点击间隔
511
+ * @param timeout 超时时间(秒),默认30秒
497
512
  * @returns 是否成功
498
513
  */
499
- static async doubleClickNodeByGesture(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval, } = {}) {
514
+ static async doubleClickNodeByGesture(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval, timeout, } = {}) {
500
515
  const response = await this.asyncCall(CallMethod.doubleClickNodeByGesture, {
501
516
  node,
502
517
  args: {
@@ -506,6 +521,7 @@ export class AssistsX {
506
521
  clickDuration,
507
522
  clickInterval,
508
523
  },
524
+ timeout,
509
525
  });
510
526
  return response.getDataOrDefault(false);
511
527
  }
@@ -514,15 +530,17 @@ export class AssistsX {
514
530
  * @param startPoint
515
531
  * @param endPoint
516
532
  * @param param2
533
+ * @param timeout 超时时间(秒),默认30秒
517
534
  * @returns
518
535
  */
519
- static async performLinearGesture(startPoint, endPoint, { duration } = {}) {
536
+ static async performLinearGesture(startPoint, endPoint, { duration, timeout } = {}) {
520
537
  const response = await this.asyncCall(CallMethod.performLinearGesture, {
521
538
  args: { startPoint, endPoint, duration },
539
+ timeout,
522
540
  });
523
541
  return response.getDataOrDefault(false);
524
542
  }
525
- static async longPressNodeByGestureAutoPaste(node, text, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }) {
543
+ static async longPressNodeByGestureAutoPaste(node, text, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, timeout, } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }) {
526
544
  const response = await this.asyncCall(CallMethod.longPressGestureAutoPaste, {
527
545
  node,
528
546
  args: {
@@ -532,10 +550,11 @@ export class AssistsX {
532
550
  timeoutMillis,
533
551
  longPressDuration,
534
552
  },
553
+ timeout,
535
554
  });
536
555
  return response.getDataOrDefault(false);
537
556
  }
538
- static async longPressGestureAutoPaste(point, text, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }) {
557
+ static async longPressGestureAutoPaste(point, text, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, timeout, } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }) {
539
558
  const response = await this.asyncCall(CallMethod.longPressGestureAutoPaste, {
540
559
  args: {
541
560
  point,
@@ -545,12 +564,14 @@ export class AssistsX {
545
564
  timeoutMillis,
546
565
  longPressDuration,
547
566
  },
567
+ timeout,
548
568
  });
549
569
  return response.getDataOrDefault(false);
550
570
  }
551
- static async getAppInfo(packageName) {
571
+ static async getAppInfo(packageName, timeout) {
552
572
  const response = await this.asyncCall(CallMethod.getAppInfo, {
553
573
  args: { packageName },
574
+ timeout,
554
575
  });
555
576
  return response.getDataOrDefault({});
556
577
  }
@@ -562,16 +583,22 @@ export class AssistsX {
562
583
  const response = this.call(CallMethod.getAndroidID);
563
584
  return response.getDataOrDefault("");
564
585
  }
565
- static async getMacAddress() {
566
- const response = await this.asyncCall(CallMethod.getMacAddress);
586
+ static async getMacAddress(timeout) {
587
+ const response = await this.asyncCall(CallMethod.getMacAddress, {
588
+ timeout,
589
+ });
567
590
  return response.getDataOrDefault({});
568
591
  }
569
- static async getDeviceInfo() {
570
- const response = await this.asyncCall(CallMethod.getDeviceInfo);
592
+ static async getDeviceInfo(timeout) {
593
+ const response = await this.asyncCall(CallMethod.getDeviceInfo, {
594
+ timeout,
595
+ });
571
596
  return response.getDataOrDefault({});
572
597
  }
573
- static async getNetworkType() {
574
- const response = await this.asyncCall(CallMethod.getNetworkType);
598
+ static async getNetworkType(timeout) {
599
+ const response = await this.asyncCall(CallMethod.getNetworkType, {
600
+ timeout,
601
+ });
575
602
  return response.getDataOrDefault({});
576
603
  }
577
604
  static async setAccessibilityEventFilters(value) {