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.
package/src/AssistsX.ts CHANGED
@@ -151,11 +151,17 @@ export class AssistsX {
151
151
  * 执行异步调用
152
152
  * @param method 方法名
153
153
  * @param args 参数对象
154
+ * @param timeout 超时时间(秒),默认30秒
154
155
  * @returns Promise<调用响应>
155
156
  */
156
157
  public static async asyncCall(
157
158
  method: string,
158
- { args, node, nodes }: { args?: any; node?: Node; nodes?: Node[] } = {}
159
+ {
160
+ args,
161
+ node,
162
+ nodes,
163
+ timeout = 30,
164
+ }: { args?: any; node?: Node; nodes?: Node[]; timeout?: number } = {}
159
165
  ): Promise<CallResponse> {
160
166
  const uuid = generateUUID();
161
167
  const params = {
@@ -173,7 +179,7 @@ export class AssistsX {
173
179
  // 超时后删除回调函数
174
180
  callbacks.delete(uuid);
175
181
  resolve(new CallResponse(0, null, uuid));
176
- }, 1000 * 30);
182
+ }, timeout * 1000);
177
183
  });
178
184
  const result = window.assistsx.call(JSON.stringify(params));
179
185
  const promiseResult = await promise;
@@ -249,32 +255,41 @@ export class AssistsX {
249
255
  });
250
256
  return response.getDataOrDefault(false);
251
257
  }
258
+ public static isAppInstalled(packageName: string): boolean {
259
+ const response = this.call(CallMethod.isAppInstalled, {
260
+ args: { packageName },
261
+ });
262
+ return response.getDataOrDefault(false);
263
+ }
252
264
 
253
265
  /**
254
266
  * 对指定节点进行截图
255
267
  * @param nodes 要截图的节点数组
256
268
  * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
269
+ * @param timeout 超时时间(秒),默认30秒
257
270
  * @returns 截图路径数组
258
271
  */
259
272
  public static async takeScreenshotNodes(
260
273
  nodes: Node[],
261
- overlayHiddenScreenshotDelayMillis: number = 250
274
+ overlayHiddenScreenshotDelayMillis: number = 250,
275
+ timeout?: number
262
276
  ): Promise<string[]> {
263
277
  const response = await this.asyncCall(CallMethod.takeScreenshot, {
264
278
  nodes,
265
279
  args: { overlayHiddenScreenshotDelayMillis },
280
+ timeout,
266
281
  });
267
282
  const data = response.getDataOrDefault("");
268
283
  return data.images;
269
284
  }
270
- public static async scanQR(): Promise<string> {
271
- const response = await this.asyncCall(CallMethod.scanQR);
285
+ public static async scanQR(timeout?: number): Promise<string> {
286
+ const response = await this.asyncCall(CallMethod.scanQR, { timeout });
272
287
  const data = response.getDataOrDefault({ value: "" });
273
288
  return data.value;
274
289
  }
275
290
  public static async loadWebViewOverlay(
276
291
  url: string,
277
- options: WebFloatingWindowOptions = {}
292
+ options: WebFloatingWindowOptions & { timeout?: number } = {}
278
293
  ): Promise<any> {
279
294
  const {
280
295
  initialWidth,
@@ -284,6 +299,7 @@ export class AssistsX {
284
299
  maxWidth,
285
300
  maxHeight,
286
301
  initialCenter,
302
+ timeout,
287
303
  } = options;
288
304
  const response = await this.asyncCall(CallMethod.loadWebViewOverlay, {
289
305
  args: {
@@ -296,6 +312,7 @@ export class AssistsX {
296
312
  maxHeight,
297
313
  initialCenter,
298
314
  },
315
+ timeout,
299
316
  });
300
317
  const data = response.getDataOrDefault({});
301
318
  return data;
@@ -553,15 +570,18 @@ export class AssistsX {
553
570
  * @param x 横坐标
554
571
  * @param y 纵坐标
555
572
  * @param duration 持续时间
573
+ * @param timeout 超时时间(秒),默认30秒
556
574
  * @returns 是否成功
557
575
  */
558
576
  public static async clickByGesture(
559
577
  x: number,
560
578
  y: number,
561
- duration: number
579
+ duration: number,
580
+ timeout?: number
562
581
  ): Promise<boolean> {
563
582
  const response = await this.asyncCall(CallMethod.clickByGesture, {
564
583
  args: { x, y, duration },
584
+ timeout,
565
585
  });
566
586
  return response.getDataOrDefault(false);
567
587
  }
@@ -663,6 +683,7 @@ export class AssistsX {
663
683
  * @param offsetY Y轴偏移
664
684
  * @param switchWindowIntervalDelay 窗口切换延迟
665
685
  * @param clickDuration 点击持续时间
686
+ * @param timeout 超时时间(秒),默认30秒
666
687
  * @returns 是否成功
667
688
  */
668
689
  public static async clickNodeByGesture(
@@ -672,16 +693,19 @@ export class AssistsX {
672
693
  offsetY,
673
694
  switchWindowIntervalDelay,
674
695
  clickDuration,
696
+ timeout,
675
697
  }: {
676
698
  offsetX?: number;
677
699
  offsetY?: number;
678
700
  switchWindowIntervalDelay?: number;
679
701
  clickDuration?: number;
702
+ timeout?: number;
680
703
  } = {}
681
704
  ): Promise<boolean> {
682
705
  const response = await this.asyncCall(CallMethod.clickNodeByGesture, {
683
706
  node,
684
707
  args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration },
708
+ timeout,
685
709
  });
686
710
  return response.getDataOrDefault(false);
687
711
  }
@@ -694,6 +718,7 @@ export class AssistsX {
694
718
  * @param switchWindowIntervalDelay 窗口切换延迟
695
719
  * @param clickDuration 点击持续时间
696
720
  * @param clickInterval 点击间隔
721
+ * @param timeout 超时时间(秒),默认30秒
697
722
  * @returns 是否成功
698
723
  */
699
724
  public static async doubleClickNodeByGesture(
@@ -704,12 +729,14 @@ export class AssistsX {
704
729
  switchWindowIntervalDelay,
705
730
  clickDuration,
706
731
  clickInterval,
732
+ timeout,
707
733
  }: {
708
734
  offsetX?: number;
709
735
  offsetY?: number;
710
736
  switchWindowIntervalDelay?: number;
711
737
  clickDuration?: number;
712
738
  clickInterval?: number;
739
+ timeout?: number;
713
740
  } = {}
714
741
  ): Promise<boolean> {
715
742
  const response = await this.asyncCall(CallMethod.doubleClickNodeByGesture, {
@@ -721,6 +748,7 @@ export class AssistsX {
721
748
  clickDuration,
722
749
  clickInterval,
723
750
  },
751
+ timeout,
724
752
  });
725
753
  return response.getDataOrDefault(false);
726
754
  }
@@ -729,15 +757,17 @@ export class AssistsX {
729
757
  * @param startPoint
730
758
  * @param endPoint
731
759
  * @param param2
760
+ * @param timeout 超时时间(秒),默认30秒
732
761
  * @returns
733
762
  */
734
763
  public static async performLinearGesture(
735
764
  startPoint: { x: number; y: number },
736
765
  endPoint: { x: number; y: number },
737
- { duration }: { duration?: number } = {}
766
+ { duration, timeout }: { duration?: number; timeout?: number } = {}
738
767
  ): Promise<boolean> {
739
768
  const response = await this.asyncCall(CallMethod.performLinearGesture, {
740
769
  args: { startPoint, endPoint, duration },
770
+ timeout,
741
771
  });
742
772
  return response.getDataOrDefault(false);
743
773
  }
@@ -749,11 +779,13 @@ export class AssistsX {
749
779
  matchedText,
750
780
  timeoutMillis,
751
781
  longPressDuration,
782
+ timeout,
752
783
  }: {
753
784
  matchedPackageName?: string;
754
785
  matchedText?: string;
755
786
  timeoutMillis?: number;
756
787
  longPressDuration?: number;
788
+ timeout?: number;
757
789
  } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
758
790
  ): Promise<boolean> {
759
791
  const response = await this.asyncCall(
@@ -767,6 +799,7 @@ export class AssistsX {
767
799
  timeoutMillis,
768
800
  longPressDuration,
769
801
  },
802
+ timeout,
770
803
  }
771
804
  );
772
805
  return response.getDataOrDefault(false);
@@ -780,11 +813,13 @@ export class AssistsX {
780
813
  matchedText,
781
814
  timeoutMillis,
782
815
  longPressDuration,
816
+ timeout,
783
817
  }: {
784
818
  matchedPackageName?: string;
785
819
  matchedText?: string;
786
820
  timeoutMillis?: number;
787
821
  longPressDuration?: number;
822
+ timeout?: number;
788
823
  } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
789
824
  ): Promise<boolean> {
790
825
  const response = await this.asyncCall(
@@ -798,13 +833,18 @@ export class AssistsX {
798
833
  timeoutMillis,
799
834
  longPressDuration,
800
835
  },
836
+ timeout,
801
837
  }
802
838
  );
803
839
  return response.getDataOrDefault(false);
804
840
  }
805
- public static async getAppInfo(packageName: string): Promise<any> {
841
+ public static async getAppInfo(
842
+ packageName: string,
843
+ timeout?: number
844
+ ): Promise<any> {
806
845
  const response = await this.asyncCall(CallMethod.getAppInfo, {
807
846
  args: { packageName },
847
+ timeout,
808
848
  });
809
849
  return response.getDataOrDefault({});
810
850
  }
@@ -816,16 +856,22 @@ export class AssistsX {
816
856
  const response = this.call(CallMethod.getAndroidID);
817
857
  return response.getDataOrDefault("");
818
858
  }
819
- public static async getMacAddress(): Promise<any> {
820
- const response = await this.asyncCall(CallMethod.getMacAddress);
859
+ public static async getMacAddress(timeout?: number): Promise<any> {
860
+ const response = await this.asyncCall(CallMethod.getMacAddress, {
861
+ timeout,
862
+ });
821
863
  return response.getDataOrDefault({});
822
864
  }
823
- public static async getDeviceInfo(): Promise<any> {
824
- const response = await this.asyncCall(CallMethod.getDeviceInfo);
865
+ public static async getDeviceInfo(timeout?: number): Promise<any> {
866
+ const response = await this.asyncCall(CallMethod.getDeviceInfo, {
867
+ timeout,
868
+ });
825
869
  return response.getDataOrDefault({});
826
870
  }
827
- public static async getNetworkType(): Promise<any> {
828
- const response = await this.asyncCall(CallMethod.getNetworkType);
871
+ public static async getNetworkType(timeout?: number): Promise<any> {
872
+ const response = await this.asyncCall(CallMethod.getNetworkType, {
873
+ timeout,
874
+ });
829
875
  return response.getDataOrDefault({});
830
876
  }
831
877
  public static async setAccessibilityEventFilters(