assistsx-js 0.0.2024 → 0.0.2025

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;
@@ -254,27 +260,30 @@ export class AssistsX {
254
260
  * 对指定节点进行截图
255
261
  * @param nodes 要截图的节点数组
256
262
  * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
263
+ * @param timeout 超时时间(秒),默认30秒
257
264
  * @returns 截图路径数组
258
265
  */
259
266
  public static async takeScreenshotNodes(
260
267
  nodes: Node[],
261
- overlayHiddenScreenshotDelayMillis: number = 250
268
+ overlayHiddenScreenshotDelayMillis: number = 250,
269
+ timeout?: number
262
270
  ): Promise<string[]> {
263
271
  const response = await this.asyncCall(CallMethod.takeScreenshot, {
264
272
  nodes,
265
273
  args: { overlayHiddenScreenshotDelayMillis },
274
+ timeout,
266
275
  });
267
276
  const data = response.getDataOrDefault("");
268
277
  return data.images;
269
278
  }
270
- public static async scanQR(): Promise<string> {
271
- const response = await this.asyncCall(CallMethod.scanQR);
279
+ public static async scanQR(timeout?: number): Promise<string> {
280
+ const response = await this.asyncCall(CallMethod.scanQR, { timeout });
272
281
  const data = response.getDataOrDefault({ value: "" });
273
282
  return data.value;
274
283
  }
275
284
  public static async loadWebViewOverlay(
276
285
  url: string,
277
- options: WebFloatingWindowOptions = {}
286
+ options: WebFloatingWindowOptions & { timeout?: number } = {}
278
287
  ): Promise<any> {
279
288
  const {
280
289
  initialWidth,
@@ -284,6 +293,7 @@ export class AssistsX {
284
293
  maxWidth,
285
294
  maxHeight,
286
295
  initialCenter,
296
+ timeout,
287
297
  } = options;
288
298
  const response = await this.asyncCall(CallMethod.loadWebViewOverlay, {
289
299
  args: {
@@ -296,6 +306,7 @@ export class AssistsX {
296
306
  maxHeight,
297
307
  initialCenter,
298
308
  },
309
+ timeout,
299
310
  });
300
311
  const data = response.getDataOrDefault({});
301
312
  return data;
@@ -553,15 +564,18 @@ export class AssistsX {
553
564
  * @param x 横坐标
554
565
  * @param y 纵坐标
555
566
  * @param duration 持续时间
567
+ * @param timeout 超时时间(秒),默认30秒
556
568
  * @returns 是否成功
557
569
  */
558
570
  public static async clickByGesture(
559
571
  x: number,
560
572
  y: number,
561
- duration: number
573
+ duration: number,
574
+ timeout?: number
562
575
  ): Promise<boolean> {
563
576
  const response = await this.asyncCall(CallMethod.clickByGesture, {
564
577
  args: { x, y, duration },
578
+ timeout,
565
579
  });
566
580
  return response.getDataOrDefault(false);
567
581
  }
@@ -663,6 +677,7 @@ export class AssistsX {
663
677
  * @param offsetY Y轴偏移
664
678
  * @param switchWindowIntervalDelay 窗口切换延迟
665
679
  * @param clickDuration 点击持续时间
680
+ * @param timeout 超时时间(秒),默认30秒
666
681
  * @returns 是否成功
667
682
  */
668
683
  public static async clickNodeByGesture(
@@ -672,16 +687,19 @@ export class AssistsX {
672
687
  offsetY,
673
688
  switchWindowIntervalDelay,
674
689
  clickDuration,
690
+ timeout,
675
691
  }: {
676
692
  offsetX?: number;
677
693
  offsetY?: number;
678
694
  switchWindowIntervalDelay?: number;
679
695
  clickDuration?: number;
696
+ timeout?: number;
680
697
  } = {}
681
698
  ): Promise<boolean> {
682
699
  const response = await this.asyncCall(CallMethod.clickNodeByGesture, {
683
700
  node,
684
701
  args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration },
702
+ timeout,
685
703
  });
686
704
  return response.getDataOrDefault(false);
687
705
  }
@@ -694,6 +712,7 @@ export class AssistsX {
694
712
  * @param switchWindowIntervalDelay 窗口切换延迟
695
713
  * @param clickDuration 点击持续时间
696
714
  * @param clickInterval 点击间隔
715
+ * @param timeout 超时时间(秒),默认30秒
697
716
  * @returns 是否成功
698
717
  */
699
718
  public static async doubleClickNodeByGesture(
@@ -704,12 +723,14 @@ export class AssistsX {
704
723
  switchWindowIntervalDelay,
705
724
  clickDuration,
706
725
  clickInterval,
726
+ timeout,
707
727
  }: {
708
728
  offsetX?: number;
709
729
  offsetY?: number;
710
730
  switchWindowIntervalDelay?: number;
711
731
  clickDuration?: number;
712
732
  clickInterval?: number;
733
+ timeout?: number;
713
734
  } = {}
714
735
  ): Promise<boolean> {
715
736
  const response = await this.asyncCall(CallMethod.doubleClickNodeByGesture, {
@@ -721,6 +742,7 @@ export class AssistsX {
721
742
  clickDuration,
722
743
  clickInterval,
723
744
  },
745
+ timeout,
724
746
  });
725
747
  return response.getDataOrDefault(false);
726
748
  }
@@ -729,15 +751,17 @@ export class AssistsX {
729
751
  * @param startPoint
730
752
  * @param endPoint
731
753
  * @param param2
754
+ * @param timeout 超时时间(秒),默认30秒
732
755
  * @returns
733
756
  */
734
757
  public static async performLinearGesture(
735
758
  startPoint: { x: number; y: number },
736
759
  endPoint: { x: number; y: number },
737
- { duration }: { duration?: number } = {}
760
+ { duration, timeout }: { duration?: number; timeout?: number } = {}
738
761
  ): Promise<boolean> {
739
762
  const response = await this.asyncCall(CallMethod.performLinearGesture, {
740
763
  args: { startPoint, endPoint, duration },
764
+ timeout,
741
765
  });
742
766
  return response.getDataOrDefault(false);
743
767
  }
@@ -749,11 +773,13 @@ export class AssistsX {
749
773
  matchedText,
750
774
  timeoutMillis,
751
775
  longPressDuration,
776
+ timeout,
752
777
  }: {
753
778
  matchedPackageName?: string;
754
779
  matchedText?: string;
755
780
  timeoutMillis?: number;
756
781
  longPressDuration?: number;
782
+ timeout?: number;
757
783
  } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
758
784
  ): Promise<boolean> {
759
785
  const response = await this.asyncCall(
@@ -767,6 +793,7 @@ export class AssistsX {
767
793
  timeoutMillis,
768
794
  longPressDuration,
769
795
  },
796
+ timeout,
770
797
  }
771
798
  );
772
799
  return response.getDataOrDefault(false);
@@ -780,11 +807,13 @@ export class AssistsX {
780
807
  matchedText,
781
808
  timeoutMillis,
782
809
  longPressDuration,
810
+ timeout,
783
811
  }: {
784
812
  matchedPackageName?: string;
785
813
  matchedText?: string;
786
814
  timeoutMillis?: number;
787
815
  longPressDuration?: number;
816
+ timeout?: number;
788
817
  } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }
789
818
  ): Promise<boolean> {
790
819
  const response = await this.asyncCall(
@@ -798,13 +827,18 @@ export class AssistsX {
798
827
  timeoutMillis,
799
828
  longPressDuration,
800
829
  },
830
+ timeout,
801
831
  }
802
832
  );
803
833
  return response.getDataOrDefault(false);
804
834
  }
805
- public static async getAppInfo(packageName: string): Promise<any> {
835
+ public static async getAppInfo(
836
+ packageName: string,
837
+ timeout?: number
838
+ ): Promise<any> {
806
839
  const response = await this.asyncCall(CallMethod.getAppInfo, {
807
840
  args: { packageName },
841
+ timeout,
808
842
  });
809
843
  return response.getDataOrDefault({});
810
844
  }
@@ -816,16 +850,22 @@ export class AssistsX {
816
850
  const response = this.call(CallMethod.getAndroidID);
817
851
  return response.getDataOrDefault("");
818
852
  }
819
- public static async getMacAddress(): Promise<any> {
820
- const response = await this.asyncCall(CallMethod.getMacAddress);
853
+ public static async getMacAddress(timeout?: number): Promise<any> {
854
+ const response = await this.asyncCall(CallMethod.getMacAddress, {
855
+ timeout,
856
+ });
821
857
  return response.getDataOrDefault({});
822
858
  }
823
- public static async getDeviceInfo(): Promise<any> {
824
- const response = await this.asyncCall(CallMethod.getDeviceInfo);
859
+ public static async getDeviceInfo(timeout?: number): Promise<any> {
860
+ const response = await this.asyncCall(CallMethod.getDeviceInfo, {
861
+ timeout,
862
+ });
825
863
  return response.getDataOrDefault({});
826
864
  }
827
- public static async getNetworkType(): Promise<any> {
828
- const response = await this.asyncCall(CallMethod.getNetworkType);
865
+ public static async getNetworkType(timeout?: number): Promise<any> {
866
+ const response = await this.asyncCall(CallMethod.getNetworkType, {
867
+ timeout,
868
+ });
829
869
  return response.getDataOrDefault({});
830
870
  }
831
871
  public static async setAccessibilityEventFilters(