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
package/dist/Step.js DELETED
@@ -1,689 +0,0 @@
1
- /**
2
- * 步骤执行控制类
3
- * 用于管理和执行自动化步骤,提供步骤的生命周期管理、状态控制和界面操作功能
4
- */
5
- import { AssistsX } from "./AssistsX";
6
- import { useStepStore } from "./StepStateStore";
7
- import { generateUUID } from "./Utils";
8
- import { StepError, StepStopError } from "./StepError";
9
- import { StepAsync } from "./StepAsync";
10
- export class Step {
11
- /**
12
- * 运行步骤实现
13
- * @param impl 步骤实现函数
14
- * @param tag 步骤标签
15
- * @param data 步骤数据
16
- * @param delayMs 步骤延迟时间(毫秒)
17
- */
18
- static async run(impl, { stepId, tag, data, delayMs = Step.delayMsDefault, exceptionRetryCountMax = Step.exceptionRetryCountMaxDefault, } = {}) {
19
- var _a, _b, _c, _d, _e, _f;
20
- this.exception = undefined;
21
- const stepStore = useStepStore();
22
- let implnName = impl.name;
23
- let currentStep;
24
- let nextStep;
25
- try {
26
- //步骤开始
27
- if (stepId) {
28
- this._stepId = stepId;
29
- if (Step.showLog) {
30
- console.log(`使用传入步骤ID: ${this._stepId}`);
31
- }
32
- }
33
- else {
34
- this._stepId = generateUUID();
35
- if (Step.showLog) {
36
- console.log(`生成步骤ID: ${this._stepId}`);
37
- }
38
- }
39
- stepStore.startStep(this._stepId, tag, data);
40
- currentStep = new Step({
41
- stepId: this._stepId,
42
- impl,
43
- tag,
44
- data,
45
- delayMs,
46
- exceptionRetryCountMax,
47
- });
48
- while (true) {
49
- // 在循环开始处定义变量,以便在 catch 块中访问
50
- let interceptedStep = undefined;
51
- let stepForRetry = currentStep; // 用于异常重试的步骤配置
52
- try {
53
- if (currentStep.delayMs) {
54
- if (Step.showLog) {
55
- console.log(`延迟${currentStep.delayMs}毫秒`);
56
- }
57
- await currentStep.delay(currentStep.delayMs);
58
- Step.assert(currentStep.stepId);
59
- }
60
- //执行步骤
61
- implnName = (_b = (_a = currentStep.impl) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : "undefined";
62
- if (Step.showLog) {
63
- console.log(`执行步骤${implnName},重复次数${currentStep.repeatCount}`);
64
- }
65
- // 执行拦截器
66
- for (const interceptor of this._interceptors) {
67
- try {
68
- const result = await interceptor(currentStep);
69
- if (result) {
70
- interceptedStep = result;
71
- if (Step.showLog) {
72
- console.log(`步骤${implnName}被拦截器拦截,执行拦截后的步骤`);
73
- }
74
- break;
75
- }
76
- }
77
- catch (e) {
78
- if (Step.showLog) {
79
- console.error(`拦截器执行出错`, e);
80
- }
81
- // 拦截器出错不影响主流程,继续执行原步骤
82
- }
83
- }
84
- // 如果被拦截,执行拦截后的步骤,否则执行原步骤
85
- stepForRetry = currentStep; // 默认使用当前步骤的重试配置
86
- if (interceptedStep !== undefined) {
87
- // 执行拦截后的步骤,需要处理延迟和重复次数
88
- const stepToExecute = interceptedStep;
89
- stepForRetry = stepToExecute; // 使用拦截后步骤的重试配置
90
- // 如果拦截后的步骤有延迟时间,先执行延迟
91
- if (stepToExecute.delayMs) {
92
- if (Step.showLog) {
93
- console.log(`拦截步骤延迟${stepToExecute.delayMs}毫秒`);
94
- }
95
- await stepToExecute.delay(stepToExecute.delayMs);
96
- Step.assert(stepToExecute.stepId);
97
- }
98
- // 打印拦截步骤的执行信息
99
- const interceptedImplName = (_c = stepToExecute.impl) === null || _c === void 0 ? void 0 : _c.name;
100
- if (Step.showLog) {
101
- console.log(`执行拦截步骤${interceptedImplName},重复次数${stepToExecute.repeatCount}`);
102
- }
103
- // 执行拦截后的步骤
104
- nextStep = await ((_d = stepToExecute.impl) === null || _d === void 0 ? void 0 : _d.call(stepToExecute, stepToExecute));
105
- }
106
- else {
107
- nextStep = await ((_e = currentStep.impl) === null || _e === void 0 ? void 0 : _e.call(currentStep, currentStep));
108
- }
109
- if (currentStep.repeatCountMax >= Step.repeatCountInfinite &&
110
- currentStep.repeatCount >= currentStep.repeatCountMax) {
111
- if (Step.showLog) {
112
- console.log(`重复次数${currentStep.repeatCount}超过最大次数${currentStep.repeatCountMax},停止执行`);
113
- }
114
- throw new StepError("步骤重复次数达到最大次数", { stepId: currentStep.stepId, repeatCount: currentStep.repeatCount, repeatCountMax: currentStep.repeatCountMax });
115
- }
116
- Step.assert(currentStep.stepId);
117
- // 执行成功,重置异常重试次数(使用实际执行的步骤配置)
118
- stepForRetry.exceptionRetryCount = 0;
119
- if (nextStep) {
120
- currentStep = nextStep;
121
- if (currentStep.isEnd) {
122
- if (Step.showLog) {
123
- console.log(`步骤${implnName}结束`);
124
- }
125
- break;
126
- }
127
- }
128
- else {
129
- break;
130
- }
131
- }
132
- catch (e) {
133
- // 如果是步骤重复次数达到最大次数的异常,直接抛出,不进行重试
134
- if ((e === null || e === void 0 ? void 0 : e.message) === "步骤重复次数达到最大次数") {
135
- throw e;
136
- }
137
- // 捕获循环内部的异常
138
- // stepForRetry 已在循环开始处定义,如果执行的是拦截后的步骤,使用拦截后步骤的配置
139
- stepForRetry.exceptionRetryCount++;
140
- if (stepForRetry.exceptionRetryCount < stepForRetry.exceptionRetryCountMax) {
141
- // 未达到最大重试次数,继续重试
142
- if (Step.showLog) {
143
- console.warn(`步骤${implnName}执行异常,重试第${stepForRetry.exceptionRetryCount}次,最大重试次数${stepForRetry.exceptionRetryCountMax}`, e);
144
- }
145
- // 继续循环,重试执行
146
- continue;
147
- }
148
- else {
149
- // 达到最大重试次数,抛出异常
150
- if (Step.showLog) {
151
- console.error(`步骤${implnName}执行异常,已达到最大重试次数${stepForRetry.exceptionRetryCountMax},停止重试`, e);
152
- }
153
- throw e;
154
- }
155
- }
156
- }
157
- //步骤执行完成
158
- stepStore.completeStep();
159
- }
160
- catch (e) {
161
- console.error(`步骤${implnName}执行出错`, e);
162
- //步骤执行出错
163
- const errorMsg = JSON.stringify({
164
- impl: implnName,
165
- tag: tag,
166
- data: data,
167
- error: (_f = e === null || e === void 0 ? void 0 : e.message) !== null && _f !== void 0 ? _f : String(e),
168
- });
169
- stepStore.setError(errorMsg);
170
- throw e;
171
- }
172
- return currentStep;
173
- }
174
- /**
175
- * 获取当前步骤ID
176
- */
177
- static get stepId() {
178
- return this._stepId;
179
- }
180
- /**
181
- * 验证步骤ID是否匹配,如果不匹配则表示停止
182
- * @param stepId 要验证的步骤ID
183
- */
184
- static assert(stepId) {
185
- // 检查异常变量,如果不为空则直接抛出
186
- if (Step.exception) {
187
- throw Step.exception;
188
- }
189
- if (stepId && Step.stepId != stepId) {
190
- throw new StepError("StepId mismatch", { stepId, currentStepId: Step.stepId });
191
- }
192
- }
193
- /**
194
- * 为节点数组分配步骤ID
195
- * @param nodes 节点数组
196
- * @param stepId 步骤ID
197
- */
198
- static assignIdsToNodes(nodes, stepId) {
199
- if (stepId) {
200
- nodes.forEach((node) => {
201
- node.stepId = stepId;
202
- });
203
- }
204
- }
205
- /**
206
- * 停止当前步骤执行
207
- * @param exception 可选的异常对象,如果传入则使用该异常,否则使用默认的StepStopError
208
- */
209
- static stop(exception) {
210
- this._stepId = "STEP_STOP";
211
- if (exception) {
212
- this.exception = exception;
213
- }
214
- else {
215
- this.exception = new StepStopError("主动中断步骤", { stepId: this._stepId });
216
- }
217
- }
218
- /**
219
- * 添加步骤拦截器
220
- * @param interceptor 拦截器函数
221
- */
222
- static addInterceptor(interceptor) {
223
- this._interceptors.push(interceptor);
224
- }
225
- /**
226
- * 移除步骤拦截器
227
- * @param interceptor 要移除的拦截器函数
228
- * @returns 是否成功删除
229
- */
230
- static removeInterceptor(interceptor) {
231
- const index = this._interceptors.indexOf(interceptor);
232
- if (index > -1) {
233
- this._interceptors.splice(index, 1);
234
- return true;
235
- }
236
- return false;
237
- }
238
- /**
239
- * 按索引移除步骤拦截器
240
- * @param index 要移除的拦截器索引
241
- * @returns 是否成功删除
242
- */
243
- static removeInterceptorByIndex(index) {
244
- if (index >= 0 && index < this._interceptors.length) {
245
- this._interceptors.splice(index, 1);
246
- return true;
247
- }
248
- return false;
249
- }
250
- /**
251
- * 移除所有匹配的步骤拦截器
252
- * @param interceptor 要移除的拦截器函数
253
- * @returns 删除的拦截器数量
254
- */
255
- static removeAllInterceptors(interceptor) {
256
- let removedCount = 0;
257
- for (let i = this._interceptors.length - 1; i >= 0; i--) {
258
- if (this._interceptors[i] === interceptor) {
259
- this._interceptors.splice(i, 1);
260
- removedCount++;
261
- }
262
- }
263
- return removedCount;
264
- }
265
- /**
266
- * 按条件移除步骤拦截器
267
- * @param predicate 判断是否删除的条件函数
268
- * @returns 删除的拦截器数量
269
- */
270
- static removeInterceptorByPredicate(predicate) {
271
- let removedCount = 0;
272
- for (let i = this._interceptors.length - 1; i >= 0; i--) {
273
- if (predicate(this._interceptors[i], i)) {
274
- this._interceptors.splice(i, 1);
275
- removedCount++;
276
- }
277
- }
278
- return removedCount;
279
- }
280
- /**
281
- * 清空所有拦截器
282
- */
283
- static clearInterceptors() {
284
- this._interceptors = [];
285
- }
286
- /**
287
- * 获取所有拦截器
288
- * @returns 拦截器数组
289
- */
290
- static getInterceptors() {
291
- return [...this._interceptors];
292
- }
293
- /**
294
- * 构造函数
295
- * @param stepId 步骤ID
296
- * @param impl 步骤实现函数
297
- * @param tag 步骤标签
298
- * @param data 步骤数据
299
- * @param delayMs 步骤延迟时间(毫秒)
300
- */
301
- constructor({ stepId, impl, tag, data, delayMs = Step.delayMsDefault, repeatCountMax = Step.repeatCountMaxDefault, exceptionRetryCountMax = Step.exceptionRetryCountMaxDefault, isEnd = false, }) {
302
- /**
303
- * 步骤ID
304
- */
305
- this.stepId = "";
306
- /**
307
- * 步骤重复执行次数
308
- */
309
- this.repeatCount = 0;
310
- /**
311
- * 步骤重复执行最大次数,默认不限制
312
- */
313
- this.repeatCountMax = Step.repeatCountMaxDefault;
314
- /**
315
- * 异常重试次数
316
- */
317
- this.exceptionRetryCount = 0;
318
- /**
319
- * 异常重试最大次数,默认3次
320
- */
321
- this.exceptionRetryCountMax = Step.exceptionRetryCountMaxDefault;
322
- this.isEnd = false;
323
- /**
324
- * 步骤延迟时间(毫秒)
325
- */
326
- this.delayMs = Step.delayMsDefault;
327
- this.tag = tag;
328
- this.stepId = stepId;
329
- this.data = data !== null && data !== void 0 ? data : {};
330
- this.impl = impl;
331
- this.delayMs = delayMs;
332
- this.repeatCountMax = repeatCountMax;
333
- this.exceptionRetryCountMax = exceptionRetryCountMax;
334
- this.isEnd = isEnd;
335
- }
336
- get async() {
337
- return new StepAsync(this);
338
- }
339
- /**
340
- * 创建下一个步骤
341
- * @param impl 下一步骤实现函数
342
- * @param tag 步骤标签
343
- * @param data 步骤数据
344
- * @param delayMs 步骤延迟时间(毫秒)
345
- * @returns 新的步骤实例
346
- */
347
- next(impl, { tag, data, delayMs = Step.delayMsDefault, repeatCountMax = Step.repeatCountMaxDefault, exceptionRetryCountMax = Step.exceptionRetryCountMaxDefault, } = {}) {
348
- var _a;
349
- Step.assert(this.stepId);
350
- return new Step({
351
- stepId: this.stepId,
352
- impl,
353
- tag,
354
- data: (_a = data !== null && data !== void 0 ? data : this.data) !== null && _a !== void 0 ? _a : {},
355
- delayMs,
356
- repeatCountMax,
357
- exceptionRetryCountMax,
358
- });
359
- }
360
- end({ tag, data, delayMs = Step.delayMsDefault, repeatCountMax = Step.repeatCountMaxDefault, exceptionRetryCountMax = Step.exceptionRetryCountMaxDefault, } = {}) {
361
- var _a;
362
- Step.assert(this.stepId);
363
- return new Step({
364
- stepId: this.stepId,
365
- impl: undefined,
366
- tag,
367
- data: (_a = data !== null && data !== void 0 ? data : this.data) !== null && _a !== void 0 ? _a : {},
368
- delayMs,
369
- repeatCountMax,
370
- exceptionRetryCountMax,
371
- isEnd: true,
372
- });
373
- }
374
- /**
375
- * 重复当前步骤
376
- * @param stepId 步骤ID
377
- * @param tag 步骤标签
378
- * @param data 步骤数据
379
- * @param delayMs 步骤延迟时间(毫秒)
380
- * @returns 当前步骤实例
381
- */
382
- repeat(_a) {
383
- var _b;
384
- var { stepId = this.stepId, tag = this.tag, data = (_b = this.data) !== null && _b !== void 0 ? _b : {}, delayMs = this.delayMs, repeatCountMax = this.repeatCountMax, exceptionRetryCountMax = this.exceptionRetryCountMax, } = _a === void 0 ? {} : _a;
385
- Step.assert(this.stepId);
386
- this.repeatCount++;
387
- this.stepId = stepId;
388
- this.tag = tag;
389
- this.data = data;
390
- this.delayMs = delayMs;
391
- this.repeatCountMax = repeatCountMax;
392
- this.exceptionRetryCountMax = exceptionRetryCountMax;
393
- // 重复执行时重置异常重试次数
394
- this.exceptionRetryCount = 0;
395
- return this;
396
- }
397
- /**
398
- * 延迟执行
399
- * @param ms 延迟时间(毫秒)
400
- * @returns Promise
401
- */
402
- async delay(ms) {
403
- while (true) {
404
- ms -= 100;
405
- if (ms <= 0) {
406
- break;
407
- }
408
- await new Promise((resolve) => setTimeout(resolve, 100));
409
- Step.assert(this.stepId);
410
- }
411
- }
412
- /**
413
- * 等待异步方法执行完成
414
- * @param method 异步方法
415
- * @returns Promise<T>
416
- */
417
- async await(method) {
418
- Step.assert(this.stepId);
419
- const result = await method();
420
- Step.assert(this.stepId);
421
- return result;
422
- }
423
- /**
424
- * 对单个节点进行截图
425
- * @param node 目标节点
426
- * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
427
- * @returns 截图路径
428
- */
429
- async takeScreenshotByNode(node, overlayHiddenScreenshotDelayMillis = 250) {
430
- Step.assert(this.stepId);
431
- const result = await AssistsX.takeScreenshotNodes([node], overlayHiddenScreenshotDelayMillis);
432
- Step.assert(this.stepId);
433
- return result[0];
434
- }
435
- /**
436
- * 对多个节点进行截图
437
- * @param nodes 目标节点数组
438
- * @param overlayHiddenScreenshotDelayMillis 截图延迟时间(毫秒)
439
- * @returns 截图路径数组
440
- */
441
- async takeScreenshotNodes(nodes, overlayHiddenScreenshotDelayMillis = 250) {
442
- Step.assert(this.stepId);
443
- const result = await AssistsX.takeScreenshotNodes(nodes, overlayHiddenScreenshotDelayMillis);
444
- Step.assert(this.stepId);
445
- return result;
446
- }
447
- /**
448
- * 获取所有符合条件的节点
449
- * @param filterClass 类名过滤
450
- * @param filterViewId 视图ID过滤
451
- * @param filterDes 描述过滤
452
- * @param filterText 文本过滤
453
- * @returns 节点数组
454
- */
455
- getAllNodes({ filterClass, filterViewId, filterDes, filterText, } = {}) {
456
- Step.assert(this.stepId);
457
- const nodes = AssistsX.getAllNodes({
458
- filterClass,
459
- filterViewId,
460
- filterDes,
461
- filterText,
462
- });
463
- Step.assert(this.stepId);
464
- Step.assignIdsToNodes(nodes, this.stepId);
465
- return nodes;
466
- }
467
- /**
468
- * 启动应用
469
- * @param packageName 应用包名
470
- * @returns 是否启动成功
471
- */
472
- launchApp(packageName) {
473
- Step.assert(this.stepId);
474
- const result = AssistsX.launchApp(packageName);
475
- Step.assert(this.stepId);
476
- return result;
477
- }
478
- /**
479
- * 获取当前应用包名
480
- * @returns 包名
481
- */
482
- getPackageName() {
483
- Step.assert(this.stepId);
484
- const result = AssistsX.getPackageName();
485
- Step.assert(this.stepId);
486
- return result;
487
- }
488
- /**
489
- * 通过ID查找节点
490
- * @param id 节点ID
491
- * @param filterClass 类名过滤
492
- * @param filterText 文本过滤
493
- * @param filterDes 描述过滤
494
- * @returns 节点数组
495
- */
496
- findById(id, { filterClass, filterText, filterDes, } = {}) {
497
- Step.assert(this.stepId);
498
- const nodes = AssistsX.findById(id, { filterClass, filterText, filterDes });
499
- Step.assert(this.stepId);
500
- Step.assignIdsToNodes(nodes, this.stepId);
501
- return nodes;
502
- }
503
- /**
504
- * 通过文本查找节点
505
- * @param text 要查找的文本
506
- * @param filterClass 类名过滤
507
- * @param filterViewId 视图ID过滤
508
- * @param filterDes 描述过滤
509
- * @returns 节点数组
510
- */
511
- findByText(text, { filterClass, filterViewId, filterDes, } = {}) {
512
- Step.assert(this.stepId);
513
- const nodes = AssistsX.findByText(text, {
514
- filterClass,
515
- filterViewId,
516
- filterDes,
517
- });
518
- Step.assert(this.stepId);
519
- Step.assignIdsToNodes(nodes, this.stepId);
520
- return nodes;
521
- }
522
- /**
523
- * 通过标签查找节点
524
- * @param className 类名
525
- * @param filterText 文本过滤
526
- * @param filterViewId 视图ID过滤
527
- * @param filterDes 描述过滤
528
- * @returns 节点数组
529
- */
530
- findByTags(className, { filterText, filterViewId, filterDes, } = {}) {
531
- Step.assert(this.stepId);
532
- const nodes = AssistsX.findByTags(className, {
533
- filterText,
534
- filterViewId,
535
- filterDes,
536
- });
537
- Step.assert(this.stepId);
538
- Step.assignIdsToNodes(nodes, this.stepId);
539
- return nodes;
540
- }
541
- /**
542
- * 查找所有匹配文本的节点
543
- * @param text 要查找的文本
544
- * @returns 节点数组
545
- */
546
- findByTextAllMatch(text) {
547
- Step.assert(this.stepId);
548
- const nodes = AssistsX.findByTextAllMatch(text);
549
- Step.assert(this.stepId);
550
- Step.assignIdsToNodes(nodes, this.stepId);
551
- return nodes;
552
- }
553
- /**
554
- * 检查是否包含指定文本
555
- * @param text 要检查的文本
556
- * @returns 是否包含
557
- */
558
- containsText(text) {
559
- Step.assert(this.stepId);
560
- const result = AssistsX.containsText(text);
561
- Step.assert(this.stepId);
562
- return result;
563
- }
564
- /**
565
- * 获取所有文本
566
- * @returns 文本数组
567
- */
568
- getAllText() {
569
- Step.assert(this.stepId);
570
- const texts = AssistsX.getAllText();
571
- Step.assert(this.stepId);
572
- return texts;
573
- }
574
- /**
575
- * 执行点击手势
576
- * @param x 横坐标
577
- * @param y 纵坐标
578
- * @param duration 持续时间(毫秒)
579
- * @returns 是否成功
580
- */
581
- async clickByGesture(x, y, duration) {
582
- Step.assert(this.stepId);
583
- const result = await AssistsX.clickByGesture(x, y, duration);
584
- Step.assert(this.stepId);
585
- return result;
586
- }
587
- async longPressGestureAutoPaste(point, text, { matchedPackageName, matchedText, timeoutMillis, longPressDuration, } = { matchedText: "粘贴", timeoutMillis: 1500, longPressDuration: 600 }) {
588
- Step.assert(this.stepId);
589
- const result = await AssistsX.longPressGestureAutoPaste(point, text, {
590
- matchedPackageName,
591
- matchedText,
592
- timeoutMillis,
593
- longPressDuration,
594
- });
595
- Step.assert(this.stepId);
596
- return result;
597
- }
598
- async getAppInfo(packageName) {
599
- Step.assert(this.stepId);
600
- const result = await AssistsX.getAppInfo(packageName);
601
- Step.assert(this.stepId);
602
- return result;
603
- }
604
- async performLinearGesture(startPoint, endPoint, { duration } = {}) {
605
- Step.assert(this.stepId);
606
- const result = await AssistsX.performLinearGesture(startPoint, endPoint, {
607
- duration,
608
- });
609
- Step.assert(this.stepId);
610
- return result;
611
- }
612
- /**
613
- * 返回操作
614
- * @returns 是否成功
615
- */
616
- back() {
617
- Step.assert(this.stepId);
618
- const result = AssistsX.back();
619
- Step.assert(this.stepId);
620
- return result;
621
- }
622
- /**
623
- * 回到主页
624
- * @returns 是否成功
625
- */
626
- home() {
627
- Step.assert(this.stepId);
628
- const result = AssistsX.home();
629
- Step.assert(this.stepId);
630
- return result;
631
- }
632
- /**
633
- * 打开通知栏
634
- * @returns 是否成功
635
- */
636
- notifications() {
637
- Step.assert(this.stepId);
638
- const result = AssistsX.notifications();
639
- Step.assert(this.stepId);
640
- return result;
641
- }
642
- /**
643
- * 显示最近应用
644
- * @returns 是否成功
645
- */
646
- recentApps() {
647
- Step.assert(this.stepId);
648
- const result = AssistsX.recentApps();
649
- Step.assert(this.stepId);
650
- return result;
651
- }
652
- /**
653
- * 获取屏幕尺寸
654
- * @returns 屏幕尺寸对象
655
- */
656
- getScreenSize() {
657
- Step.assert(this.stepId);
658
- const data = AssistsX.getScreenSize();
659
- Step.assert(this.stepId);
660
- return data;
661
- }
662
- /**
663
- * 获取应用窗口尺寸
664
- * @returns 应用窗口尺寸对象
665
- */
666
- getAppScreenSize() {
667
- Step.assert(this.stepId);
668
- const data = AssistsX.getAppScreenSize();
669
- Step.assert(this.stepId);
670
- return data;
671
- }
672
- }
673
- Step.delayMsDefault = 1000;
674
- Step.repeatCountInfinite = -1;
675
- Step.repeatCountMaxDefault = Step.repeatCountInfinite;
676
- Step.showLog = false;
677
- Step.exceptionRetryCountMaxDefault = 3;
678
- /**
679
- * 当前执行步骤的ID
680
- */
681
- Step._stepId = undefined;
682
- /**
683
- * 步骤拦截器列表
684
- */
685
- Step._interceptors = [];
686
- /**
687
- * 步骤异常变量,默认为空
688
- */
689
- Step.exception = undefined;