assistsx-js 0.1.41 → 0.2.0

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.
Files changed (104) hide show
  1. package/README.md +32 -0
  2. package/dist/index.cjs +7957 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.mts +4231 -0
  5. package/dist/index.d.ts +4231 -30
  6. package/dist/index.global.js +46 -0
  7. package/dist/index.global.js.map +1 -0
  8. package/dist/index.js +7879 -30
  9. package/dist/index.js.map +1 -0
  10. package/package.json +11 -5
  11. package/src/{AssistsXAsync.ts → assistsx-async.ts} +8 -8
  12. package/src/{AssistsX.ts → assistsx.ts} +8 -8
  13. package/src/barutils/bar-utils.ts +3 -3
  14. package/src/filesystem/fileio/file-io.ts +2 -2
  15. package/src/filesystem/fileutils/file-utils.ts +2 -2
  16. package/src/filesystem/path.ts +2 -2
  17. package/src/floatingwindow/float.ts +4 -4
  18. package/src/gallery/gallery.ts +2 -2
  19. package/src/global.d.ts +6 -1
  20. package/src/imageutils/image-utils.ts +2 -2
  21. package/src/ime/ime.ts +2 -2
  22. package/src/index.ts +21 -20
  23. package/src/log/log-call-method.ts +28 -0
  24. package/src/log/log.ts +445 -0
  25. package/src/mlkit/mlkit.ts +3 -3
  26. package/src/network/http.ts +2 -2
  27. package/src/{NodeAsync.ts → node-async.ts} +5 -5
  28. package/src/{Node.ts → node.ts} +5 -5
  29. package/src/{StepAsync.ts → step-async.ts} +8 -8
  30. package/src/{Step.ts → step.ts} +7 -7
  31. package/dist/AccessibilityEventFilter.d.ts +0 -105
  32. package/dist/AccessibilityEventFilter.js +0 -89
  33. package/dist/AppInfo.d.ts +0 -45
  34. package/dist/AppInfo.js +0 -38
  35. package/dist/AssistsX.d.ts +0 -484
  36. package/dist/AssistsX.js +0 -828
  37. package/dist/AssistsXAsync.d.ts +0 -532
  38. package/dist/AssistsXAsync.js +0 -874
  39. package/dist/Bounds.d.ts +0 -48
  40. package/dist/Bounds.js +0 -68
  41. package/dist/CallMethod.d.ts +0 -69
  42. package/dist/CallMethod.js +0 -71
  43. package/dist/CallResponse.d.ts +0 -10
  44. package/dist/CallResponse.js +0 -28
  45. package/dist/DeviceInfo.d.ts +0 -69
  46. package/dist/DeviceInfo.js +0 -50
  47. package/dist/Node.d.ts +0 -334
  48. package/dist/Node.js +0 -369
  49. package/dist/NodeAsync.d.ts +0 -213
  50. package/dist/NodeAsync.js +0 -313
  51. package/dist/NodeClassValue.d.ts +0 -15
  52. package/dist/NodeClassValue.js +0 -15
  53. package/dist/Step.d.ts +0 -355
  54. package/dist/Step.js +0 -689
  55. package/dist/StepAsync.d.ts +0 -162
  56. package/dist/StepAsync.js +0 -264
  57. package/dist/StepError.d.ts +0 -35
  58. package/dist/StepError.js +0 -26
  59. package/dist/StepStateStore.d.ts +0 -14
  60. package/dist/StepStateStore.js +0 -37
  61. package/dist/Utils.d.ts +0 -3
  62. package/dist/Utils.js +0 -20
  63. package/dist/WindowFlags.d.ts +0 -75
  64. package/dist/WindowFlags.js +0 -97
  65. package/dist/barutils/BarUtilsCallMethod.d.ts +0 -24
  66. package/dist/barutils/BarUtilsCallMethod.js +0 -26
  67. package/dist/barutils/bar-utils.d.ts +0 -41
  68. package/dist/barutils/bar-utils.js +0 -205
  69. package/dist/filesystem/fileio/file-io.d.ts +0 -101
  70. package/dist/filesystem/fileio/file-io.js +0 -235
  71. package/dist/filesystem/fileutils/file-utils.d.ts +0 -242
  72. package/dist/filesystem/fileutils/file-utils.js +0 -493
  73. package/dist/filesystem/path.d.ts +0 -252
  74. package/dist/filesystem/path.js +0 -589
  75. package/dist/floatingwindow/FloatCallMethod.d.ts +0 -19
  76. package/dist/floatingwindow/FloatCallMethod.js +0 -18
  77. package/dist/floatingwindow/float.d.ts +0 -29
  78. package/dist/floatingwindow/float.js +0 -149
  79. package/dist/gallery/gallery.d.ts +0 -60
  80. package/dist/gallery/gallery.js +0 -142
  81. package/dist/imageutils/image-utils.d.ts +0 -442
  82. package/dist/imageutils/image-utils.js +0 -543
  83. package/dist/ime/ime.d.ts +0 -80
  84. package/dist/ime/ime.js +0 -141
  85. package/dist/mlkit/MlkitCallMethod.d.ts +0 -27
  86. package/dist/mlkit/MlkitCallMethod.js +0 -26
  87. package/dist/mlkit/mlkit.d.ts +0 -86
  88. package/dist/mlkit/mlkit.js +0 -169
  89. package/dist/network/http.d.ts +0 -127
  90. package/dist/network/http.js +0 -202
  91. /package/src/{AccessibilityEventFilter.ts → accessibility-event-filter.ts} +0 -0
  92. /package/src/{AppInfo.ts → app-info.ts} +0 -0
  93. /package/src/barutils/{BarUtilsCallMethod.ts → bar-utils-call-method.ts} +0 -0
  94. /package/src/{Bounds.ts → bounds.ts} +0 -0
  95. /package/src/{CallMethod.ts → call-method.ts} +0 -0
  96. /package/src/{CallResponse.ts → call-response.ts} +0 -0
  97. /package/src/{DeviceInfo.ts → device-info.ts} +0 -0
  98. /package/src/floatingwindow/{FloatCallMethod.ts → float-call-method.ts} +0 -0
  99. /package/src/mlkit/{MlkitCallMethod.ts → mlkit-call-method.ts} +0 -0
  100. /package/src/{NodeClassValue.ts → node-class-value.ts} +0 -0
  101. /package/src/{StepError.ts → step-error.ts} +0 -0
  102. /package/src/{StepStateStore.ts → step-state-store.ts} +0 -0
  103. /package/src/{Utils.ts → utils.ts} +0 -0
  104. /package/src/{WindowFlags.ts → window-flags.ts} +0 -0
@@ -1,874 +0,0 @@
1
- /**
2
- * AssistsX 类
3
- * 提供与移动应用程序界面交互的工具类,包括节点查找、手势操作、屏幕操作等功能
4
- */
5
- import { Node } from "./Node";
6
- import { CallMethod } from "./CallMethod";
7
- import { CallResponse } from "./CallResponse";
8
- import { Bounds } from "./Bounds";
9
- import { generateUUID } from "./Utils";
10
- import { AppInfo } from "./AppInfo";
11
- import { DeviceInfo } from "./DeviceInfo";
12
- import { callbacks, } from "./AssistsX";
13
- export class AssistsXAsync {
14
- /**
15
- * 执行异步调用
16
- * @param method 方法名
17
- * @param args 参数对象
18
- * @param timeout 超时时间(秒),默认30秒
19
- * @returns Promise<调用响应>
20
- */
21
- static async asyncCall(method, { args, node, nodes, timeout = 30, } = {}) {
22
- const uuid = generateUUID();
23
- const params = {
24
- method,
25
- arguments: args ? args : undefined,
26
- node: node ? node : undefined,
27
- nodes: nodes ? nodes : undefined,
28
- callbackId: uuid,
29
- };
30
- const promise = new Promise((resolve) => {
31
- callbacks.set(uuid, (data) => {
32
- resolve(data);
33
- });
34
- setTimeout(() => {
35
- // 超时后删除回调函数
36
- callbacks.delete(uuid);
37
- resolve(new CallResponse(0, null, uuid));
38
- }, timeout * 1000);
39
- });
40
- const result = window.assistsxAsync.call(JSON.stringify(params));
41
- const promiseResult = await promise;
42
- if (typeof promiseResult === "string") {
43
- const responseData = JSON.parse(promiseResult);
44
- const response = new CallResponse(responseData.code, responseData.data, responseData.callbackId);
45
- return response;
46
- }
47
- throw new Error("Call failed");
48
- }
49
- /**
50
- * 设置悬浮窗标志
51
- * @param flags 标志
52
- * @param timeout 超时时间(秒),默认30秒
53
- * @returns 是否设置成功
54
- */
55
- static async setOverlayFlags(flags, timeout) {
56
- const response = await this.asyncCall(CallMethod.setOverlayFlags, {
57
- args: { flags: flags },
58
- timeout,
59
- });
60
- return response.getDataOrDefault(false);
61
- }
62
- /**
63
- * 设置悬浮窗标志
64
- * @param flags 标志
65
- * @param timeout 超时时间(秒),默认30秒
66
- * @returns 是否设置成功
67
- */
68
- static async setOverlayFlagList(flags, timeout) {
69
- const response = await this.asyncCall(CallMethod.setOverlayFlags, {
70
- args: { flags: flags },
71
- timeout,
72
- });
73
- return response.getDataOrDefault(false);
74
- }
75
- /**
76
- * 获取所有符合条件的节点
77
- * @param filterClass 类名过滤
78
- * @param filterViewId 视图ID过滤
79
- * @param filterDes 描述过滤
80
- * @param filterText 文本过滤
81
- * @param timeout 超时时间(秒),默认30秒
82
- * @returns 节点数组
83
- */
84
- static async getAllNodes({ filterClass, filterViewId, filterDes, filterText, timeout, } = {}) {
85
- const response = await this.asyncCall(CallMethod.getAllNodes, {
86
- args: { filterClass, filterViewId, filterDes, filterText },
87
- timeout,
88
- });
89
- const data = response.getDataOrDefault([]);
90
- if (!Array.isArray(data)) {
91
- throw new Error(`AssistsXAsync.getAllNodes: Expected array, but got ${typeof data}. ` +
92
- `Value: ${JSON.stringify(data)}`);
93
- }
94
- return Node.fromJSONArray(data);
95
- }
96
- /**
97
- * 设置节点文本
98
- * @param node 目标节点
99
- * @param text 要设置的文本
100
- * @param timeout 超时时间(秒),默认30秒
101
- * @returns 是否设置成功
102
- */
103
- static async setNodeText(node, text, timeout) {
104
- const response = await this.asyncCall(CallMethod.setNodeText, {
105
- args: { text },
106
- node,
107
- timeout,
108
- });
109
- return response.getDataOrDefault(false);
110
- }
111
- /**
112
- * 对指定节点进行截图
113
- * @param nodes 要截图的节点数组
114
- * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
115
- * @param timeout 超时时间(秒),默认30秒
116
- * @returns 截图路径数组
117
- */
118
- static async takeScreenshotNodes(nodes, overlayHiddenScreenshotDelayMillis = 250, timeout) {
119
- const response = await this.asyncCall(CallMethod.takeScreenshot, {
120
- nodes,
121
- args: { overlayHiddenScreenshotDelayMillis },
122
- timeout,
123
- });
124
- const data = response.getDataOrDefault({ images: [] });
125
- return data.images;
126
- }
127
- /**
128
- * 保存全屏截图到文件
129
- * @param options 截图保存选项
130
- * @param options.filePath 文件路径(可选,不提供则自动生成)
131
- * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
132
- * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
133
- * @param options.timeout 超时时间(秒),默认30秒
134
- * @returns 保存的文件路径
135
- */
136
- static async takeScreenshotSave(options = {}) {
137
- const { filePath, format = "PNG", overlayHiddenScreenshotDelayMillis = 250, timeout, } = options;
138
- const response = await this.asyncCall(CallMethod.takeScreenshotSave, {
139
- args: {
140
- filePath,
141
- format,
142
- overlayHiddenScreenshotDelayMillis,
143
- },
144
- timeout,
145
- });
146
- const data = response.getDataOrDefault({ file: "" });
147
- return data.file;
148
- }
149
- /**
150
- * 保存截图到文件(支持多个节点)
151
- * @param options 截图保存选项
152
- * @param options.nodes 要截图的节点数组(可选,不提供则保存全屏截图)
153
- * @param options.filePath 文件路径(可选,不提供则自动生成。多个节点时会自动添加索引后缀)
154
- * @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认为 "PNG"
155
- * @param options.overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒),默认为 250
156
- * @param options.timeout 超时时间(秒),默认30秒
157
- * @returns 保存的文件路径数组
158
- */
159
- static async takeScreenshotToFile(options = {}) {
160
- const { nodes, filePath, format = "PNG", overlayHiddenScreenshotDelayMillis = 250, timeout, } = options;
161
- const response = await this.asyncCall(CallMethod.takeScreenshotToFile, {
162
- nodes,
163
- args: {
164
- filePath,
165
- format,
166
- overlayHiddenScreenshotDelayMillis,
167
- },
168
- timeout,
169
- });
170
- const data = response.getDataOrDefault({ files: [] });
171
- if (!Array.isArray(data.files)) {
172
- throw new Error(`AssistsXAsync.takeScreenshotToFile: Expected files array, but got ${typeof data.files}. ` +
173
- `Value: ${JSON.stringify(data.files)}`);
174
- }
175
- return data.files;
176
- }
177
- /**
178
- * 截图识别文本
179
- * @param param0 识别参数
180
- * @returns 截图识别结果
181
- */
182
- static async recognizeTextInScreenshot(targetText, options = {}) {
183
- const { rotationDegrees = 0, overlayHiddenScreenshotDelayMillis = 250, restoreOverlay = true, region, timeout, } = options;
184
- const response = await this.asyncCall(CallMethod.recognizeTextInScreenshot, {
185
- args: {
186
- targetText,
187
- rotationDegrees,
188
- overlayHiddenScreenshotDelayMillis,
189
- restoreOverlay,
190
- region,
191
- },
192
- timeout,
193
- });
194
- return response.getDataOrDefault({
195
- fullText: "",
196
- processingTimeMillis: 0,
197
- positions: [],
198
- });
199
- }
200
- static async scanQR(timeout) {
201
- const response = await this.asyncCall(CallMethod.scanQR, { timeout });
202
- const data = response.getDataOrDefault({ value: "" });
203
- return data.value;
204
- }
205
- static async loadWebViewOverlay(url, options = {}) {
206
- const { initialWidth, initialHeight, initialX, initialY, minWidth, minHeight, maxWidth, maxHeight, initialCenter, showTopOperationArea, showBottomOperationArea, backgroundColor, timeout, } = options;
207
- const response = await this.asyncCall(CallMethod.loadWebViewOverlay, {
208
- args: {
209
- url,
210
- initialWidth,
211
- initialHeight,
212
- initialX,
213
- initialY,
214
- minWidth,
215
- minHeight,
216
- maxWidth,
217
- maxHeight,
218
- initialCenter,
219
- showTopOperationArea,
220
- showBottomOperationArea,
221
- backgroundColor,
222
- },
223
- timeout,
224
- });
225
- const data = response.getDataOrDefault({});
226
- return data;
227
- }
228
- /**
229
- * 关闭当前 WebView 悬浮窗
230
- * @param timeout 超时时间(秒),默认30秒
231
- * @returns 是否关闭成功(当前页面在悬浮窗内时返回 true,否则 false)
232
- */
233
- static async closeOverlay(timeout) {
234
- const response = await this.asyncCall(CallMethod.closeOverlay, {
235
- timeout,
236
- });
237
- return response.getDataOrDefault(false);
238
- }
239
- /**
240
- * 点击节点
241
- * @param node 要点击的节点
242
- * @param timeout 超时时间(秒),默认30秒
243
- * @returns 是否点击成功
244
- */
245
- static async click(node, timeout) {
246
- const response = await this.asyncCall(CallMethod.click, { node, timeout });
247
- return response.getDataOrDefault(false);
248
- }
249
- /**
250
- * 长按节点
251
- * @param node 要长按的节点
252
- * @param timeout 超时时间(秒),默认30秒
253
- * @returns 是否长按成功
254
- */
255
- static async longClick(node, timeout) {
256
- const response = await this.asyncCall(CallMethod.longClick, {
257
- node,
258
- timeout,
259
- });
260
- return response.getDataOrDefault(false);
261
- }
262
- /**
263
- * 启动应用
264
- * @param packageName 应用包名
265
- * @param timeout 超时时间(秒),默认30秒
266
- * @returns 是否启动成功
267
- */
268
- static async launchApp(packageName, timeout) {
269
- const response = await this.asyncCall(CallMethod.launchApp, {
270
- args: { packageName },
271
- timeout,
272
- });
273
- return response.getDataOrDefault(false);
274
- }
275
- /**
276
- * 获取当前应用包名
277
- * @param timeout 超时时间(秒),默认30秒
278
- * @returns 包名
279
- */
280
- static async getPackageName(timeout) {
281
- const response = await this.asyncCall(CallMethod.getPackageName, {
282
- timeout,
283
- });
284
- return response.getDataOrDefault("");
285
- }
286
- /**
287
- * 显示悬浮提示
288
- * @param text 提示文本
289
- * @param delay 显示时长(毫秒)
290
- * @param timeout 超时时间(秒),默认30秒
291
- * @returns 是否显示成功
292
- */
293
- static async overlayToast(text, delay = 2000, timeout) {
294
- const response = await this.asyncCall(CallMethod.overlayToast, {
295
- args: { text, delay },
296
- timeout,
297
- });
298
- return response.getDataOrDefault(false);
299
- }
300
- /**
301
- * 通过ID查找节点
302
- * @param id 节点ID
303
- * @param filterClass 类名过滤
304
- * @param filterText 文本过滤
305
- * @param filterDes 描述过滤
306
- * @param node 父节点范围
307
- * @param timeout 超时时间(秒),默认30秒
308
- * @returns 节点数组
309
- */
310
- static async findById(id, { filterClass, filterText, filterDes, node, timeout, } = {}) {
311
- const response = await this.asyncCall(CallMethod.findById, {
312
- args: { id, filterClass, filterText, filterDes },
313
- node,
314
- timeout,
315
- });
316
- const data = response.getDataOrDefault([]);
317
- if (!Array.isArray(data)) {
318
- throw new Error(`AssistsXAsync.findById: Expected array, but got ${typeof data}. ` +
319
- `Value: ${JSON.stringify(data)}`);
320
- }
321
- return Node.fromJSONArray(data);
322
- }
323
- /**
324
- * 通过文本查找节点
325
- * @param text 要查找的文本
326
- * @param filterClass 类名过滤
327
- * @param filterViewId 视图ID过滤
328
- * @param filterDes 描述过滤
329
- * @param node 父节点范围
330
- * @param timeout 超时时间(秒),默认30秒
331
- * @returns 节点数组
332
- */
333
- static async findByText(text, { filterClass, filterViewId, filterDes, node, timeout, } = {}) {
334
- const response = await this.asyncCall(CallMethod.findByText, {
335
- args: { text, filterClass, filterViewId, filterDes },
336
- node,
337
- timeout,
338
- });
339
- const data = response.getDataOrDefault([]);
340
- if (!Array.isArray(data)) {
341
- throw new Error(`AssistsXAsync.findByText: Expected array, but got ${typeof data}. ` +
342
- `Value: ${JSON.stringify(data)}`);
343
- }
344
- return Node.fromJSONArray(data);
345
- }
346
- /**
347
- * 通过标签查找节点
348
- * @param className 类名
349
- * @param filterText 文本过滤
350
- * @param filterViewId 视图ID过滤
351
- * @param filterDes 描述过滤
352
- * @param node 父节点范围
353
- * @param timeout 超时时间(秒),默认30秒
354
- * @returns 节点数组
355
- */
356
- static async findByTags(className, { filterText, filterViewId, filterDes, node, timeout, } = {}) {
357
- const response = await this.asyncCall(CallMethod.findByTags, {
358
- args: { className, filterText, filterViewId, filterDes },
359
- node,
360
- timeout,
361
- });
362
- const data = response.getDataOrDefault([]);
363
- if (!Array.isArray(data)) {
364
- throw new Error(`AssistsXAsync.findByTags: Expected array, but got ${typeof data}. ` +
365
- `Value: ${JSON.stringify(data)}`);
366
- }
367
- return Node.fromJSONArray(data);
368
- }
369
- /**
370
- * 查找所有匹配文本的节点
371
- * @param text 要查找的文本
372
- * @param timeout 超时时间(秒),默认30秒
373
- * @returns 节点数组
374
- */
375
- static async findByTextAllMatch(text, timeout) {
376
- const response = await this.asyncCall(CallMethod.findByTextAllMatch, {
377
- args: { text },
378
- timeout,
379
- });
380
- const data = response.getDataOrDefault([]);
381
- if (!Array.isArray(data)) {
382
- throw new Error(`AssistsXAsync.findByTextAllMatch: Expected array, but got ${typeof data}. ` +
383
- `Value: ${JSON.stringify(data)}`);
384
- }
385
- return Node.fromJSONArray(data);
386
- }
387
- /**
388
- * 检查是否包含指定文本
389
- * @param text 要检查的文本
390
- * @param timeout 超时时间(秒),默认30秒
391
- * @returns 是否包含
392
- */
393
- static async containsText(text, timeout) {
394
- const response = await this.asyncCall(CallMethod.containsText, {
395
- args: { text },
396
- timeout,
397
- });
398
- return response.getDataOrDefault(false);
399
- }
400
- /**
401
- * 获取所有文本
402
- * @param timeout 超时时间(秒),默认30秒
403
- * @returns 文本数组
404
- */
405
- static async getAllText(timeout) {
406
- const response = await this.asyncCall(CallMethod.getAllText, { timeout });
407
- const data = response.getDataOrDefault([]);
408
- if (!Array.isArray(data)) {
409
- throw new Error(`AssistsXAsync.getAllText: Expected array, but got ${typeof data}. ` +
410
- `Value: ${JSON.stringify(data)}`);
411
- }
412
- return data;
413
- }
414
- /**
415
- * 查找第一个匹配标签的父节点
416
- * @param className 类名
417
- * @param timeout 超时时间(秒),默认30秒
418
- * @returns 父节点
419
- */
420
- static async findFirstParentByTags(node, className, timeout) {
421
- const response = await this.asyncCall(CallMethod.findFirstParentByTags, {
422
- args: { className },
423
- node,
424
- timeout,
425
- });
426
- return Node.create(response.getDataOrDefault({}));
427
- }
428
- /**
429
- * 获取节点的所有子节点
430
- * @param node 父节点
431
- * @param timeout 超时时间(秒),默认30秒
432
- * @returns 子节点数组
433
- */
434
- static async getNodes(node, timeout) {
435
- const response = await this.asyncCall(CallMethod.getNodes, {
436
- node,
437
- timeout,
438
- });
439
- const data = response.getDataOrDefault([]);
440
- if (!Array.isArray(data)) {
441
- throw new Error(`AssistsXAsync.getNodes: Expected array, but got ${typeof data}. ` +
442
- `Value: ${JSON.stringify(data)}`);
443
- }
444
- return Node.fromJSONArray(data);
445
- }
446
- /**
447
- * 获取节点的直接子节点
448
- * @param node 父节点
449
- * @param timeout 超时时间(秒),默认30秒
450
- * @returns 子节点数组
451
- */
452
- static async getChildren(node, timeout) {
453
- const response = await this.asyncCall(CallMethod.getChildren, {
454
- node,
455
- timeout,
456
- });
457
- const data = response.getDataOrDefault([]);
458
- if (!Array.isArray(data)) {
459
- throw new Error(`AssistsXAsync.getChildren: Expected array, but got ${typeof data}. ` +
460
- `Value: ${JSON.stringify(data)}`);
461
- }
462
- return Node.fromJSONArray(data);
463
- }
464
- /**
465
- * 查找第一个可点击的父节点
466
- * @param node 起始节点
467
- * @param timeout 超时时间(秒),默认30秒
468
- * @returns 可点击的父节点
469
- */
470
- static async findFirstParentClickable(node, timeout) {
471
- const response = await this.asyncCall(CallMethod.findFirstParentClickable, {
472
- node,
473
- timeout,
474
- });
475
- return Node.create(response.getDataOrDefault({}));
476
- }
477
- /**
478
- * 获取节点在屏幕中的边界
479
- * @param node 目标节点
480
- * @param timeout 超时时间(秒),默认30秒
481
- * @returns 边界对象
482
- */
483
- static async getBoundsInScreen(node, timeout) {
484
- const response = await this.asyncCall(CallMethod.getBoundsInScreen, {
485
- node,
486
- timeout,
487
- });
488
- return Bounds.fromData(response.getDataOrDefault({}));
489
- }
490
- /**
491
- * 检查节点是否可见
492
- * @param node 目标节点
493
- * @param compareNode 比较节点
494
- * @param isFullyByCompareNode 是否完全可见
495
- * @param timeout 超时时间(秒),默认30秒
496
- * @returns 是否可见
497
- */
498
- static async isVisible(node, { compareNode, isFullyByCompareNode, timeout, } = {}) {
499
- const response = await this.asyncCall(CallMethod.isVisible, {
500
- node,
501
- args: { compareNode, isFullyByCompareNode },
502
- timeout,
503
- });
504
- return response.getDataOrDefault(false);
505
- }
506
- /**
507
- * 执行点击手势
508
- * @param x 横坐标
509
- * @param y 纵坐标
510
- * @param duration 持续时间
511
- * @param timeout 超时时间(秒),默认30秒
512
- * @returns 是否成功
513
- */
514
- static async clickByGesture(x, y, duration, timeout) {
515
- const response = await this.asyncCall(CallMethod.clickByGesture, {
516
- args: { x, y, duration },
517
- timeout,
518
- });
519
- return response.getDataOrDefault(false);
520
- }
521
- /**
522
- * 返回操作
523
- * @param timeout 超时时间(秒),默认30秒
524
- * @returns 是否成功
525
- */
526
- static async back(timeout) {
527
- const response = await this.asyncCall(CallMethod.back, { timeout });
528
- return response.getDataOrDefault(false);
529
- }
530
- /**
531
- * 回到主页
532
- * @param timeout 超时时间(秒),默认30秒
533
- * @returns 是否成功
534
- */
535
- static async home(timeout) {
536
- const response = await this.asyncCall(CallMethod.home, { timeout });
537
- return response.getDataOrDefault(false);
538
- }
539
- /**
540
- * 打开通知栏
541
- * @param timeout 超时时间(秒),默认30秒
542
- * @returns 是否成功
543
- */
544
- static async notifications(timeout) {
545
- const response = await this.asyncCall(CallMethod.notifications, {
546
- timeout,
547
- });
548
- return response.getDataOrDefault(false);
549
- }
550
- /**
551
- * 显示最近应用
552
- * @param timeout 超时时间(秒),默认30秒
553
- * @returns 是否成功
554
- */
555
- static async recentApps(timeout) {
556
- const response = await this.asyncCall(CallMethod.recentApps, { timeout });
557
- return response.getDataOrDefault(false);
558
- }
559
- /**
560
- * 在节点中粘贴文本
561
- * @param node 目标节点
562
- * @param text 要粘贴的文本
563
- * @param timeout 超时时间(秒),默认30秒
564
- * @returns 是否成功
565
- */
566
- static async paste(node, text, timeout) {
567
- const response = await this.asyncCall(CallMethod.paste, {
568
- args: { text },
569
- node,
570
- timeout,
571
- });
572
- return response.getDataOrDefault(false);
573
- }
574
- static async focus(node, timeout) {
575
- const response = await this.asyncCall(CallMethod.focus, { node, timeout });
576
- return response.getDataOrDefault(false);
577
- }
578
- /**
579
- * 选择文本
580
- * @param node 目标节点
581
- * @param selectionStart 选择起始位置
582
- * @param selectionEnd 选择结束位置
583
- * @param timeout 超时时间(秒),默认30秒
584
- * @returns 是否成功
585
- */
586
- static async selectionText(node, selectionStart, selectionEnd, timeout) {
587
- const response = await this.asyncCall(CallMethod.selectionText, {
588
- args: { selectionStart, selectionEnd },
589
- node,
590
- timeout,
591
- });
592
- return response.getDataOrDefault(false);
593
- }
594
- /**
595
- * 向前滚动
596
- * @param node 可滚动节点
597
- * @param timeout 超时时间(秒),默认30秒
598
- * @returns 是否成功
599
- */
600
- static async scrollForward(node, timeout) {
601
- const response = await this.asyncCall(CallMethod.scrollForward, {
602
- node,
603
- timeout,
604
- });
605
- return response.getDataOrDefault(false);
606
- }
607
- /**
608
- * 向后滚动
609
- * @param node 可滚动节点
610
- * @param timeout 超时时间(秒),默认30秒
611
- * @returns 是否成功
612
- */
613
- static async scrollBackward(node, timeout) {
614
- const response = await this.asyncCall(CallMethod.scrollBackward, {
615
- node,
616
- timeout,
617
- });
618
- return response.getDataOrDefault(false);
619
- }
620
- /**
621
- * 对节点执行点击手势
622
- * @param node 目标节点
623
- * @param offsetX X轴偏移
624
- * @param offsetY Y轴偏移
625
- * @param switchWindowIntervalDelay 窗口切换延迟
626
- * @param clickDuration 点击持续时间
627
- * @param timeout 超时时间(秒),默认30秒
628
- * @returns 是否成功
629
- */
630
- static async clickNodeByGesture(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, timeout, } = {}) {
631
- const response = await this.asyncCall(CallMethod.clickNodeByGesture, {
632
- node,
633
- args: { offsetX, offsetY, switchWindowIntervalDelay, clickDuration },
634
- timeout,
635
- });
636
- return response.getDataOrDefault(false);
637
- }
638
- /**
639
- * 对节点执行双击手势
640
- * @param node 目标节点
641
- * @param offsetX X轴偏移
642
- * @param offsetY Y轴偏移
643
- * @param switchWindowIntervalDelay 窗口切换延迟
644
- * @param clickDuration 点击持续时间
645
- * @param clickInterval 点击间隔
646
- * @param timeout 超时时间(秒),默认30秒
647
- * @returns 是否成功
648
- */
649
- static async doubleClickNodeByGesture(node, { offsetX, offsetY, switchWindowIntervalDelay, clickDuration, clickInterval, timeout, } = {}) {
650
- const response = await this.asyncCall(CallMethod.doubleClickNodeByGesture, {
651
- node,
652
- args: {
653
- offsetX,
654
- offsetY,
655
- switchWindowIntervalDelay,
656
- clickDuration,
657
- clickInterval,
658
- },
659
- timeout,
660
- });
661
- return response.getDataOrDefault(false);
662
- }
663
- /**
664
- * 执行线型手势
665
- * @param startPoint
666
- * @param endPoint
667
- * @param param2
668
- * @param timeout 超时时间(秒),默认30秒
669
- * @returns
670
- */
671
- static async performLinearGesture(startPoint, endPoint, { duration, timeout } = {}) {
672
- const response = await this.asyncCall(CallMethod.performLinearGesture, {
673
- args: { startPoint, endPoint, duration },
674
- timeout,
675
- });
676
- return response.getDataOrDefault(false);
677
- }
678
- static async longPressNodeByGestureAutoPaste(node, text, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, timeout, } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }) {
679
- const response = await this.asyncCall(CallMethod.longPressGestureAutoPaste, {
680
- node,
681
- args: {
682
- text,
683
- matchedPackageName,
684
- matchedText,
685
- timeoutMillis,
686
- longPressDuration,
687
- },
688
- timeout,
689
- });
690
- return response.getDataOrDefault(false);
691
- }
692
- static async longPressGestureAutoPaste(point, text, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, timeout, } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }) {
693
- const response = await this.asyncCall(CallMethod.longPressGestureAutoPaste, {
694
- args: {
695
- point,
696
- text,
697
- matchedPackageName,
698
- matchedText,
699
- timeoutMillis,
700
- longPressDuration,
701
- },
702
- timeout,
703
- });
704
- return response.getDataOrDefault(false);
705
- }
706
- static async getAppInfo(packageName, timeout) {
707
- const response = await this.asyncCall(CallMethod.getAppInfo, {
708
- args: { packageName },
709
- timeout,
710
- });
711
- return AppInfo.fromJSON(response.getDataOrDefault({}));
712
- }
713
- static async getUniqueDeviceId(timeout) {
714
- const response = await this.asyncCall(CallMethod.getUniqueDeviceId, {
715
- timeout,
716
- });
717
- return response.getDataOrDefault("");
718
- }
719
- static async getAndroidID(timeout) {
720
- const response = await this.asyncCall(CallMethod.getAndroidID, { timeout });
721
- return response.getDataOrDefault("");
722
- }
723
- static async getMacAddress(timeout) {
724
- const response = await this.asyncCall(CallMethod.getMacAddress, {
725
- timeout,
726
- });
727
- return response.getDataOrDefault({});
728
- }
729
- static async getDeviceInfo(timeout) {
730
- const response = await this.asyncCall(CallMethod.getDeviceInfo, {
731
- timeout,
732
- });
733
- return DeviceInfo.fromJSON(response.getDataOrDefault({}));
734
- }
735
- /**
736
- * 获取屏幕尺寸
737
- * @param timeout 超时时间(秒),默认30秒
738
- * @returns 屏幕尺寸对象
739
- */
740
- static async getScreenSize(timeout) {
741
- const response = await this.asyncCall(CallMethod.getScreenSize, {
742
- timeout,
743
- });
744
- return response.getDataOrDefault({});
745
- }
746
- /**
747
- * 获取应用窗口尺寸
748
- * @param timeout 超时时间(秒),默认30秒
749
- * @returns 应用窗口尺寸对象
750
- */
751
- static async getAppScreenSize(timeout) {
752
- const response = await this.asyncCall(CallMethod.getAppScreenSize, {
753
- timeout,
754
- });
755
- return response.getDataOrDefault({});
756
- }
757
- /**
758
- * 在浏览器中打开URL
759
- * @param url 要打开的URL
760
- * @param timeout 超时时间(秒),默认30秒
761
- * @returns 是否成功打开
762
- */
763
- static async openUrlInBrowser(url, timeout) {
764
- const response = await this.asyncCall(CallMethod.openUrlInBrowser, {
765
- args: { url },
766
- timeout,
767
- });
768
- return response.getDataOrDefault(false);
769
- }
770
- static async download(url, timeout) {
771
- const response = await this.asyncCall(CallMethod.download, {
772
- args: { url },
773
- timeout,
774
- });
775
- return response.getDataOrDefault(null);
776
- }
777
- static async audioPlayFromFile(filePath, { volume = undefined, useAbsoluteVolume = false, timeout = 30, }) {
778
- const response = await this.asyncCall(CallMethod.audioPlayFromFile, {
779
- args: { filePath, volume, useAbsoluteVolume },
780
- timeout,
781
- });
782
- return response.getDataOrDefault(null);
783
- }
784
- static async audioStop({ timeout = 30, }) {
785
- const response = await this.asyncCall(CallMethod.audioStop, {
786
- timeout,
787
- });
788
- return response.getDataOrDefault(false);
789
- }
790
- /**
791
- * 播放系统电话铃声
792
- * @param timeout 超时时间(秒),默认30秒
793
- * @returns 播放结果消息
794
- */
795
- static async audioPlayRingtone({ timeout = 30, }) {
796
- const response = await this.asyncCall(CallMethod.audioPlayRingtone, {
797
- timeout,
798
- });
799
- return response.getDataOrDefault("");
800
- }
801
- /**
802
- * 停止播放系统电话铃声
803
- * @param timeout 超时时间(秒),默认30秒
804
- * @returns 停止结果消息
805
- */
806
- static async audioStopRingtone({ timeout = 30, }) {
807
- const response = await this.asyncCall(CallMethod.audioStopRingtone, {
808
- timeout,
809
- });
810
- return response.getDataOrDefault("");
811
- }
812
- /**
813
- * 添加联系人
814
- * @param name 联系人姓名(必填)
815
- * @param phoneNumber 电话号码(必填)
816
- * @param timeout 超时时间(秒),默认30秒
817
- * @returns 是否添加成功
818
- */
819
- static async addContact(name, phoneNumber, timeout) {
820
- const response = await this.asyncCall(CallMethod.addContact, {
821
- args: { name, phoneNumber },
822
- timeout,
823
- });
824
- return response.getDataOrDefault(false);
825
- }
826
- /**
827
- * 获取所有联系人
828
- * @param timeout 超时时间(秒),默认30秒
829
- * @returns 联系人列表
830
- */
831
- static async getAllContacts(timeout) {
832
- const response = await this.asyncCall(CallMethod.getAllContacts, {
833
- timeout,
834
- });
835
- const data = response.getDataOrDefault([]);
836
- if (!Array.isArray(data)) {
837
- throw new Error(`AssistsXAsync.getAllContacts: Expected array, but got ${typeof data}. ` +
838
- `Value: ${JSON.stringify(data)}`);
839
- }
840
- return data;
841
- }
842
- /**
843
- * 保存根节点树为JSON文件
844
- * @param options 保存选项
845
- * @param options.filePath 文件路径(可选,不提供则自动生成)
846
- * @param options.prettyPrint 是否格式化输出,默认为 true
847
- * @param options.timeout 超时时间(秒),默认30秒
848
- * @returns 保存的文件路径
849
- */
850
- static async saveRootNodeTreeJson(options = {}) {
851
- const { filePath, prettyPrint = true, timeout, } = options;
852
- const response = await this.asyncCall(CallMethod.saveRootNodeTreeJson, {
853
- args: {
854
- filePath,
855
- prettyPrint,
856
- },
857
- timeout,
858
- });
859
- const data = response.getDataOrDefault({ file: "" });
860
- return data.file;
861
- }
862
- /**
863
- * 获取剪贴板文本内容
864
- * @param timeout 超时时间(秒),默认30秒
865
- * @returns 剪贴板文本内容,如果获取失败则返回空字符串
866
- */
867
- static async getClipboardText(timeout) {
868
- const response = await this.asyncCall(CallMethod.getClipboardText, {
869
- timeout,
870
- });
871
- const data = response.getDataOrDefault({ text: "" });
872
- return data.text || "";
873
- }
874
- }