assistsx-js 0.0.2002 → 0.0.2004
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/dist/AssistsX.d.ts +35 -8
- package/dist/AssistsX.js +39 -34
- package/dist/AssistsXAsync.js +5 -3
- package/dist/Step.d.ts +24 -0
- package/dist/Step.js +77 -1
- package/package.json +1 -1
- package/src/AssistsX.ts +73 -39
- package/src/AssistsXAsync.ts +5 -3
- package/src/Step.ts +90 -1
package/dist/AssistsX.d.ts
CHANGED
|
@@ -5,6 +5,30 @@
|
|
|
5
5
|
import { Node } from "./Node";
|
|
6
6
|
import { CallResponse } from "./CallResponse";
|
|
7
7
|
import { Bounds } from "./Bounds";
|
|
8
|
+
/**
|
|
9
|
+
* 无障碍事件数据结构
|
|
10
|
+
*/
|
|
11
|
+
export interface AccessibilityEventData {
|
|
12
|
+
packageName: string;
|
|
13
|
+
className: string;
|
|
14
|
+
eventType: number;
|
|
15
|
+
action: number;
|
|
16
|
+
texts: string[];
|
|
17
|
+
node: Node;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 无障碍事件完整结构
|
|
21
|
+
*/
|
|
22
|
+
export interface AccessibilityEvent {
|
|
23
|
+
callbackId: string;
|
|
24
|
+
code: number;
|
|
25
|
+
data: AccessibilityEventData;
|
|
26
|
+
message: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 无障碍事件监听器类型
|
|
30
|
+
*/
|
|
31
|
+
export type AccessibilityEventListener = (event: AccessibilityEvent) => void;
|
|
8
32
|
/**
|
|
9
33
|
* Web浮动窗口选项接口定义
|
|
10
34
|
*/
|
|
@@ -17,10 +41,8 @@ export interface WebFloatingWindowOptions {
|
|
|
17
41
|
maxHeight?: number;
|
|
18
42
|
initialCenter?: boolean;
|
|
19
43
|
}
|
|
20
|
-
export declare const callbacks:
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
export declare const accessibilityEventListeners: ((event: any) => void)[];
|
|
44
|
+
export declare const callbacks: Map<string, (data: string) => void>;
|
|
45
|
+
export declare const accessibilityEventListeners: AccessibilityEventListener[];
|
|
24
46
|
export declare class AssistsX {
|
|
25
47
|
/**
|
|
26
48
|
* 执行同步调用
|
|
@@ -354,15 +376,20 @@ export declare class AssistsX {
|
|
|
354
376
|
/**
|
|
355
377
|
* 添加无障碍事件监听器
|
|
356
378
|
* @param listener 监听器函数
|
|
357
|
-
* @returns 监听器ID,用于移除监听器
|
|
358
379
|
*/
|
|
359
|
-
static addAccessibilityEventListener(listener:
|
|
380
|
+
static addAccessibilityEventListener(listener: AccessibilityEventListener): void;
|
|
381
|
+
/**
|
|
382
|
+
* 判断是否包含无障碍事件监听器
|
|
383
|
+
* @param listener 监听器函数
|
|
384
|
+
* @returns 是否包含
|
|
385
|
+
*/
|
|
386
|
+
static containsAccessibilityEventListener(listener: AccessibilityEventListener): boolean;
|
|
360
387
|
/**
|
|
361
388
|
* 移除无障碍事件监听器
|
|
362
|
-
* @param
|
|
389
|
+
* @param listener 要移除的监听器函数
|
|
363
390
|
* @returns 是否移除成功
|
|
364
391
|
*/
|
|
365
|
-
static removeAccessibilityEventListener(
|
|
392
|
+
static removeAccessibilityEventListener(listener: AccessibilityEventListener): boolean;
|
|
366
393
|
/**
|
|
367
394
|
* 移除所有无障碍事件监听器
|
|
368
395
|
*/
|
package/dist/AssistsX.js
CHANGED
|
@@ -8,33 +8,45 @@ import { CallResponse } from "./CallResponse";
|
|
|
8
8
|
import { Bounds } from "./Bounds";
|
|
9
9
|
import { decodeBase64UTF8, generateUUID } from "./Utils";
|
|
10
10
|
// 回调函数存储对象
|
|
11
|
-
export const callbacks =
|
|
11
|
+
export const callbacks = new Map();
|
|
12
12
|
// 无障碍事件监听器存储
|
|
13
13
|
export const accessibilityEventListeners = [];
|
|
14
14
|
// 初始化全局回调函数
|
|
15
15
|
if (typeof window !== "undefined" && !window.assistsxCallback) {
|
|
16
16
|
window.assistsxCallback = (data) => {
|
|
17
|
+
let callbackId;
|
|
17
18
|
try {
|
|
18
|
-
console.log(data);
|
|
19
19
|
const json = decodeBase64UTF8(data);
|
|
20
20
|
const response = JSON.parse(json);
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
callback(
|
|
21
|
+
callbackId = response.callbackId;
|
|
22
|
+
if (callbackId) {
|
|
23
|
+
const callback = callbacks.get(callbackId);
|
|
24
|
+
if (callback) {
|
|
25
|
+
callback(json);
|
|
26
|
+
}
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
catch (e) {
|
|
27
30
|
console.log(e);
|
|
28
31
|
}
|
|
32
|
+
finally {
|
|
33
|
+
// 无论成功还是失败,都删除回调函数
|
|
34
|
+
if (callbackId) {
|
|
35
|
+
callbacks.delete(callbackId);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
29
38
|
};
|
|
30
39
|
}
|
|
31
40
|
// 初始化全局无障碍事件函数
|
|
32
41
|
if (typeof window !== "undefined" && !window.onAccessibilityEvent) {
|
|
33
42
|
window.onAccessibilityEvent = (event) => {
|
|
34
|
-
//
|
|
43
|
+
// 通知所有注册的监听器,每个监听器都有独立的错误处理
|
|
35
44
|
accessibilityEventListeners.forEach((listener) => {
|
|
36
45
|
try {
|
|
37
|
-
|
|
46
|
+
//base64 decode
|
|
47
|
+
const decodedEvent = decodeBase64UTF8(event);
|
|
48
|
+
const parsedEvent = JSON.parse(decodedEvent);
|
|
49
|
+
listener(parsedEvent);
|
|
38
50
|
}
|
|
39
51
|
catch (error) {
|
|
40
52
|
console.error("Accessibility event listener error:", error);
|
|
@@ -79,12 +91,14 @@ export class AssistsX {
|
|
|
79
91
|
callbackId: uuid,
|
|
80
92
|
};
|
|
81
93
|
const promise = new Promise((resolve) => {
|
|
82
|
-
callbacks
|
|
94
|
+
callbacks.set(uuid, (data) => {
|
|
83
95
|
resolve(data);
|
|
84
|
-
};
|
|
96
|
+
});
|
|
85
97
|
setTimeout(() => {
|
|
98
|
+
// 超时后删除回调函数
|
|
99
|
+
callbacks.delete(uuid);
|
|
86
100
|
resolve(new CallResponse(0, null, uuid));
|
|
87
|
-
},
|
|
101
|
+
}, 1000 * 30);
|
|
88
102
|
});
|
|
89
103
|
const result = window.assistsx.call(JSON.stringify(params));
|
|
90
104
|
const promiseResult = await promise;
|
|
@@ -571,37 +585,28 @@ export class AssistsX {
|
|
|
571
585
|
/**
|
|
572
586
|
* 添加无障碍事件监听器
|
|
573
587
|
* @param listener 监听器函数
|
|
574
|
-
* @returns 监听器ID,用于移除监听器
|
|
575
588
|
*/
|
|
576
589
|
static addAccessibilityEventListener(listener) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
// 将监听器包装并存储,使用ID作为键
|
|
587
|
-
accessibilityEventListeners[listenerId] = wrappedListener;
|
|
588
|
-
accessibilityEventListeners.push(wrappedListener);
|
|
589
|
-
return listenerId;
|
|
590
|
+
accessibilityEventListeners.push(listener);
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* 判断是否包含无障碍事件监听器
|
|
594
|
+
* @param listener 监听器函数
|
|
595
|
+
* @returns 是否包含
|
|
596
|
+
*/
|
|
597
|
+
static containsAccessibilityEventListener(listener) {
|
|
598
|
+
return accessibilityEventListeners.indexOf(listener) > -1;
|
|
590
599
|
}
|
|
591
600
|
/**
|
|
592
601
|
* 移除无障碍事件监听器
|
|
593
|
-
* @param
|
|
602
|
+
* @param listener 要移除的监听器函数
|
|
594
603
|
* @returns 是否移除成功
|
|
595
604
|
*/
|
|
596
|
-
static removeAccessibilityEventListener(
|
|
597
|
-
const
|
|
598
|
-
if (
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
accessibilityEventListeners.splice(index, 1);
|
|
602
|
-
delete accessibilityEventListeners[listenerId];
|
|
603
|
-
return true;
|
|
604
|
-
}
|
|
605
|
+
static removeAccessibilityEventListener(listener) {
|
|
606
|
+
const index = accessibilityEventListeners.indexOf(listener);
|
|
607
|
+
if (index > -1) {
|
|
608
|
+
accessibilityEventListeners.splice(index, 1);
|
|
609
|
+
return true;
|
|
605
610
|
}
|
|
606
611
|
return false;
|
|
607
612
|
}
|
package/dist/AssistsXAsync.js
CHANGED
|
@@ -25,12 +25,14 @@ export class AssistsXAsync {
|
|
|
25
25
|
callbackId: uuid,
|
|
26
26
|
};
|
|
27
27
|
const promise = new Promise((resolve) => {
|
|
28
|
-
callbacks
|
|
28
|
+
callbacks.set(uuid, (data) => {
|
|
29
29
|
resolve(data);
|
|
30
|
-
};
|
|
30
|
+
});
|
|
31
31
|
setTimeout(() => {
|
|
32
|
+
// 超时后删除回调函数
|
|
33
|
+
callbacks.delete(uuid);
|
|
32
34
|
resolve(new CallResponse(0, null, uuid));
|
|
33
|
-
},
|
|
35
|
+
}, 1000 * 30);
|
|
34
36
|
});
|
|
35
37
|
const result = window.assistsxAsync.call(JSON.stringify(params));
|
|
36
38
|
const promiseResult = await promise;
|
package/dist/Step.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Node } from "./Node";
|
|
|
2
2
|
import { StepAsync } from "./StepAsync";
|
|
3
3
|
export type StepResult = Step | undefined;
|
|
4
4
|
export type StepImpl = (step: Step) => Promise<StepResult>;
|
|
5
|
+
export type StepInterceptor = (step: Step) => StepResult | Promise<StepResult>;
|
|
5
6
|
export declare class Step {
|
|
6
7
|
static delayMsDefault: number;
|
|
7
8
|
static readonly repeatCountInfinite: number;
|
|
@@ -11,6 +12,10 @@ export declare class Step {
|
|
|
11
12
|
* 当前执行步骤的ID
|
|
12
13
|
*/
|
|
13
14
|
private static _stepId;
|
|
15
|
+
/**
|
|
16
|
+
* 步骤拦截器列表
|
|
17
|
+
*/
|
|
18
|
+
private static _interceptors;
|
|
14
19
|
/**
|
|
15
20
|
* 运行步骤实现
|
|
16
21
|
* @param impl 步骤实现函数
|
|
@@ -42,6 +47,25 @@ export declare class Step {
|
|
|
42
47
|
* 停止当前步骤执行
|
|
43
48
|
*/
|
|
44
49
|
static stop(): void;
|
|
50
|
+
/**
|
|
51
|
+
* 添加步骤拦截器
|
|
52
|
+
* @param interceptor 拦截器函数
|
|
53
|
+
*/
|
|
54
|
+
static addInterceptor(interceptor: StepInterceptor): void;
|
|
55
|
+
/**
|
|
56
|
+
* 移除步骤拦截器
|
|
57
|
+
* @param interceptor 要移除的拦截器函数
|
|
58
|
+
*/
|
|
59
|
+
static removeInterceptor(interceptor: StepInterceptor): void;
|
|
60
|
+
/**
|
|
61
|
+
* 清空所有拦截器
|
|
62
|
+
*/
|
|
63
|
+
static clearInterceptors(): void;
|
|
64
|
+
/**
|
|
65
|
+
* 获取所有拦截器
|
|
66
|
+
* @returns 拦截器数组
|
|
67
|
+
*/
|
|
68
|
+
static getInterceptors(): StepInterceptor[];
|
|
45
69
|
/**
|
|
46
70
|
* 步骤ID
|
|
47
71
|
*/
|
package/dist/Step.js
CHANGED
|
@@ -45,7 +45,49 @@ export class Step {
|
|
|
45
45
|
if (Step.showLog) {
|
|
46
46
|
console.log(`执行步骤${implnName},重复次数${currentStep.repeatCount}`);
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
// 执行拦截器
|
|
49
|
+
let interceptedStep = undefined;
|
|
50
|
+
for (const interceptor of this._interceptors) {
|
|
51
|
+
try {
|
|
52
|
+
const result = await interceptor(currentStep);
|
|
53
|
+
if (result !== undefined) {
|
|
54
|
+
interceptedStep = result;
|
|
55
|
+
if (Step.showLog) {
|
|
56
|
+
console.log(`步骤${implnName}被拦截器拦截,执行拦截后的步骤`);
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
if (Step.showLog) {
|
|
63
|
+
console.error(`拦截器执行出错`, e);
|
|
64
|
+
}
|
|
65
|
+
// 拦截器出错不影响主流程,继续执行原步骤
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// 如果被拦截,执行拦截后的步骤,否则执行原步骤
|
|
69
|
+
if (interceptedStep !== undefined) {
|
|
70
|
+
// 执行拦截后的步骤,需要处理延迟和重复次数
|
|
71
|
+
const stepToExecute = interceptedStep;
|
|
72
|
+
// 如果拦截后的步骤有延迟时间,先执行延迟
|
|
73
|
+
if (stepToExecute.delayMs) {
|
|
74
|
+
if (Step.showLog) {
|
|
75
|
+
console.log(`拦截步骤延迟${stepToExecute.delayMs}毫秒`);
|
|
76
|
+
}
|
|
77
|
+
await stepToExecute.delay(stepToExecute.delayMs);
|
|
78
|
+
Step.assert(stepToExecute.stepId);
|
|
79
|
+
}
|
|
80
|
+
// 打印拦截步骤的执行信息
|
|
81
|
+
const interceptedImplName = stepToExecute.impl.name;
|
|
82
|
+
if (Step.showLog) {
|
|
83
|
+
console.log(`执行拦截步骤${interceptedImplName},重复次数${stepToExecute.repeatCount}`);
|
|
84
|
+
}
|
|
85
|
+
// 执行拦截后的步骤
|
|
86
|
+
nextStep = await stepToExecute.impl(stepToExecute);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
nextStep = await currentStep.impl(currentStep);
|
|
90
|
+
}
|
|
49
91
|
if (currentStep.repeatCountMax > Step.repeatCountInfinite &&
|
|
50
92
|
currentStep.repeatCount > currentStep.repeatCountMax) {
|
|
51
93
|
if (Step.showLog) {
|
|
@@ -113,6 +155,36 @@ export class Step {
|
|
|
113
155
|
static stop() {
|
|
114
156
|
this._stepId = undefined;
|
|
115
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* 添加步骤拦截器
|
|
160
|
+
* @param interceptor 拦截器函数
|
|
161
|
+
*/
|
|
162
|
+
static addInterceptor(interceptor) {
|
|
163
|
+
this._interceptors.push(interceptor);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 移除步骤拦截器
|
|
167
|
+
* @param interceptor 要移除的拦截器函数
|
|
168
|
+
*/
|
|
169
|
+
static removeInterceptor(interceptor) {
|
|
170
|
+
const index = this._interceptors.indexOf(interceptor);
|
|
171
|
+
if (index > -1) {
|
|
172
|
+
this._interceptors.splice(index, 1);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 清空所有拦截器
|
|
177
|
+
*/
|
|
178
|
+
static clearInterceptors() {
|
|
179
|
+
this._interceptors = [];
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 获取所有拦截器
|
|
183
|
+
* @returns 拦截器数组
|
|
184
|
+
*/
|
|
185
|
+
static getInterceptors() {
|
|
186
|
+
return [...this._interceptors];
|
|
187
|
+
}
|
|
116
188
|
/**
|
|
117
189
|
* 构造函数
|
|
118
190
|
* @param stepId 步骤ID
|
|
@@ -473,3 +545,7 @@ Step.showLog = false;
|
|
|
473
545
|
* 当前执行步骤的ID
|
|
474
546
|
*/
|
|
475
547
|
Step._stepId = undefined;
|
|
548
|
+
/**
|
|
549
|
+
* 步骤拦截器列表
|
|
550
|
+
*/
|
|
551
|
+
Step._interceptors = [];
|
package/package.json
CHANGED
package/src/AssistsX.ts
CHANGED
|
@@ -8,6 +8,33 @@ import { CallResponse } from "./CallResponse";
|
|
|
8
8
|
import { Bounds } from "./Bounds";
|
|
9
9
|
import { decodeBase64UTF8, generateUUID } from "./Utils";
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* 无障碍事件数据结构
|
|
13
|
+
*/
|
|
14
|
+
export interface AccessibilityEventData {
|
|
15
|
+
packageName: string;
|
|
16
|
+
className: string;
|
|
17
|
+
eventType: number;
|
|
18
|
+
action: number;
|
|
19
|
+
texts: string[];
|
|
20
|
+
node: Node;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 无障碍事件完整结构
|
|
25
|
+
*/
|
|
26
|
+
export interface AccessibilityEvent {
|
|
27
|
+
callbackId: string;
|
|
28
|
+
code: number;
|
|
29
|
+
data: AccessibilityEventData;
|
|
30
|
+
message: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 无障碍事件监听器类型
|
|
35
|
+
*/
|
|
36
|
+
export type AccessibilityEventListener = (event: AccessibilityEvent) => void;
|
|
37
|
+
|
|
11
38
|
/**
|
|
12
39
|
* Web浮动窗口选项接口定义
|
|
13
40
|
*/
|
|
@@ -22,35 +49,46 @@ export interface WebFloatingWindowOptions {
|
|
|
22
49
|
}
|
|
23
50
|
|
|
24
51
|
// 回调函数存储对象
|
|
25
|
-
export const callbacks:
|
|
52
|
+
export const callbacks: Map<string, (data: string) => void> = new Map();
|
|
26
53
|
|
|
27
54
|
// 无障碍事件监听器存储
|
|
28
|
-
export const accessibilityEventListeners:
|
|
55
|
+
export const accessibilityEventListeners: AccessibilityEventListener[] = [];
|
|
29
56
|
|
|
30
57
|
// 初始化全局回调函数
|
|
31
58
|
if (typeof window !== "undefined" && !window.assistsxCallback) {
|
|
32
59
|
window.assistsxCallback = (data: string) => {
|
|
60
|
+
let callbackId: string | undefined;
|
|
33
61
|
try {
|
|
34
|
-
console.log(data);
|
|
35
62
|
const json = decodeBase64UTF8(data);
|
|
36
63
|
const response = JSON.parse(json);
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
callback(
|
|
64
|
+
callbackId = response.callbackId;
|
|
65
|
+
if (callbackId) {
|
|
66
|
+
const callback = callbacks.get(callbackId);
|
|
67
|
+
if (callback) {
|
|
68
|
+
callback(json);
|
|
69
|
+
}
|
|
40
70
|
}
|
|
41
71
|
} catch (e) {
|
|
42
72
|
console.log(e);
|
|
73
|
+
} finally {
|
|
74
|
+
// 无论成功还是失败,都删除回调函数
|
|
75
|
+
if (callbackId) {
|
|
76
|
+
callbacks.delete(callbackId);
|
|
77
|
+
}
|
|
43
78
|
}
|
|
44
79
|
};
|
|
45
80
|
}
|
|
46
81
|
|
|
47
82
|
// 初始化全局无障碍事件函数
|
|
48
83
|
if (typeof window !== "undefined" && !window.onAccessibilityEvent) {
|
|
49
|
-
window.onAccessibilityEvent = (event:
|
|
50
|
-
//
|
|
84
|
+
window.onAccessibilityEvent = (event: string) => {
|
|
85
|
+
// 通知所有注册的监听器,每个监听器都有独立的错误处理
|
|
51
86
|
accessibilityEventListeners.forEach((listener) => {
|
|
52
87
|
try {
|
|
53
|
-
|
|
88
|
+
//base64 decode
|
|
89
|
+
const decodedEvent = decodeBase64UTF8(event);
|
|
90
|
+
const parsedEvent: AccessibilityEvent = JSON.parse(decodedEvent);
|
|
91
|
+
listener(parsedEvent);
|
|
54
92
|
} catch (error) {
|
|
55
93
|
console.error("Accessibility event listener error:", error);
|
|
56
94
|
}
|
|
@@ -106,12 +144,14 @@ export class AssistsX {
|
|
|
106
144
|
callbackId: uuid,
|
|
107
145
|
};
|
|
108
146
|
const promise = new Promise((resolve) => {
|
|
109
|
-
callbacks
|
|
147
|
+
callbacks.set(uuid, (data: string) => {
|
|
110
148
|
resolve(data);
|
|
111
|
-
};
|
|
149
|
+
});
|
|
112
150
|
setTimeout(() => {
|
|
151
|
+
// 超时后删除回调函数
|
|
152
|
+
callbacks.delete(uuid);
|
|
113
153
|
resolve(new CallResponse(0, null, uuid));
|
|
114
|
-
},
|
|
154
|
+
}, 1000 * 30);
|
|
115
155
|
});
|
|
116
156
|
const result = window.assistsx.call(JSON.stringify(params));
|
|
117
157
|
const promiseResult = await promise;
|
|
@@ -780,41 +820,35 @@ export class AssistsX {
|
|
|
780
820
|
/**
|
|
781
821
|
* 添加无障碍事件监听器
|
|
782
822
|
* @param listener 监听器函数
|
|
783
|
-
* @returns 监听器ID,用于移除监听器
|
|
784
823
|
*/
|
|
785
824
|
public static addAccessibilityEventListener(
|
|
786
|
-
listener:
|
|
787
|
-
):
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
(
|
|
799
|
-
accessibilityEventListeners.push(wrappedListener);
|
|
800
|
-
|
|
801
|
-
return listenerId;
|
|
825
|
+
listener: AccessibilityEventListener
|
|
826
|
+
): void {
|
|
827
|
+
accessibilityEventListeners.push(listener);
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* 判断是否包含无障碍事件监听器
|
|
831
|
+
* @param listener 监听器函数
|
|
832
|
+
* @returns 是否包含
|
|
833
|
+
*/
|
|
834
|
+
public static containsAccessibilityEventListener(
|
|
835
|
+
listener: AccessibilityEventListener
|
|
836
|
+
): boolean {
|
|
837
|
+
return accessibilityEventListeners.indexOf(listener) > -1;
|
|
802
838
|
}
|
|
803
839
|
|
|
804
840
|
/**
|
|
805
841
|
* 移除无障碍事件监听器
|
|
806
|
-
* @param
|
|
842
|
+
* @param listener 要移除的监听器函数
|
|
807
843
|
* @returns 是否移除成功
|
|
808
844
|
*/
|
|
809
|
-
public static removeAccessibilityEventListener(
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
return true;
|
|
817
|
-
}
|
|
845
|
+
public static removeAccessibilityEventListener(
|
|
846
|
+
listener: AccessibilityEventListener
|
|
847
|
+
): boolean {
|
|
848
|
+
const index = accessibilityEventListeners.indexOf(listener);
|
|
849
|
+
if (index > -1) {
|
|
850
|
+
accessibilityEventListeners.splice(index, 1);
|
|
851
|
+
return true;
|
|
818
852
|
}
|
|
819
853
|
return false;
|
|
820
854
|
}
|
package/src/AssistsXAsync.ts
CHANGED
|
@@ -29,12 +29,14 @@ export class AssistsXAsync {
|
|
|
29
29
|
callbackId: uuid,
|
|
30
30
|
};
|
|
31
31
|
const promise = new Promise((resolve) => {
|
|
32
|
-
callbacks
|
|
32
|
+
callbacks.set(uuid, (data: string) => {
|
|
33
33
|
resolve(data);
|
|
34
|
-
};
|
|
34
|
+
});
|
|
35
35
|
setTimeout(() => {
|
|
36
|
+
// 超时后删除回调函数
|
|
37
|
+
callbacks.delete(uuid);
|
|
36
38
|
resolve(new CallResponse(0, null, uuid));
|
|
37
|
-
},
|
|
39
|
+
}, 1000 * 30);
|
|
38
40
|
});
|
|
39
41
|
const result = window.assistsxAsync.call(JSON.stringify(params));
|
|
40
42
|
const promiseResult = await promise;
|
package/src/Step.ts
CHANGED
|
@@ -16,6 +16,9 @@ export type StepResult = Step | undefined;
|
|
|
16
16
|
// 步骤实现函数类型
|
|
17
17
|
export type StepImpl = (step: Step) => Promise<StepResult>;
|
|
18
18
|
|
|
19
|
+
// 步骤拦截器函数类型
|
|
20
|
+
export type StepInterceptor = (step: Step) => StepResult | Promise<StepResult>;
|
|
21
|
+
|
|
19
22
|
export class Step {
|
|
20
23
|
static delayMsDefault: number = 1000;
|
|
21
24
|
static readonly repeatCountInfinite: number = -1;
|
|
@@ -27,6 +30,11 @@ export class Step {
|
|
|
27
30
|
*/
|
|
28
31
|
private static _stepId: string | undefined = undefined;
|
|
29
32
|
|
|
33
|
+
/**
|
|
34
|
+
* 步骤拦截器列表
|
|
35
|
+
*/
|
|
36
|
+
private static _interceptors: StepInterceptor[] = [];
|
|
37
|
+
|
|
30
38
|
/**
|
|
31
39
|
* 运行步骤实现
|
|
32
40
|
* @param impl 步骤实现函数
|
|
@@ -77,7 +85,54 @@ export class Step {
|
|
|
77
85
|
`执行步骤${implnName},重复次数${currentStep.repeatCount}`
|
|
78
86
|
);
|
|
79
87
|
}
|
|
80
|
-
|
|
88
|
+
|
|
89
|
+
// 执行拦截器
|
|
90
|
+
let interceptedStep: StepResult = undefined;
|
|
91
|
+
for (const interceptor of this._interceptors) {
|
|
92
|
+
try {
|
|
93
|
+
const result = await interceptor(currentStep);
|
|
94
|
+
if (result !== undefined) {
|
|
95
|
+
interceptedStep = result;
|
|
96
|
+
if (Step.showLog) {
|
|
97
|
+
console.log(`步骤${implnName}被拦截器拦截,执行拦截后的步骤`);
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
} catch (e: any) {
|
|
102
|
+
if (Step.showLog) {
|
|
103
|
+
console.error(`拦截器执行出错`, e);
|
|
104
|
+
}
|
|
105
|
+
// 拦截器出错不影响主流程,继续执行原步骤
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 如果被拦截,执行拦截后的步骤,否则执行原步骤
|
|
110
|
+
if (interceptedStep !== undefined) {
|
|
111
|
+
// 执行拦截后的步骤,需要处理延迟和重复次数
|
|
112
|
+
const stepToExecute = interceptedStep;
|
|
113
|
+
|
|
114
|
+
// 如果拦截后的步骤有延迟时间,先执行延迟
|
|
115
|
+
if (stepToExecute.delayMs) {
|
|
116
|
+
if (Step.showLog) {
|
|
117
|
+
console.log(`拦截步骤延迟${stepToExecute.delayMs}毫秒`);
|
|
118
|
+
}
|
|
119
|
+
await stepToExecute.delay(stepToExecute.delayMs);
|
|
120
|
+
Step.assert(stepToExecute.stepId);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 打印拦截步骤的执行信息
|
|
124
|
+
const interceptedImplName = stepToExecute.impl.name;
|
|
125
|
+
if (Step.showLog) {
|
|
126
|
+
console.log(
|
|
127
|
+
`执行拦截步骤${interceptedImplName},重复次数${stepToExecute.repeatCount}`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 执行拦截后的步骤
|
|
132
|
+
nextStep = await stepToExecute.impl(stepToExecute);
|
|
133
|
+
} else {
|
|
134
|
+
nextStep = await currentStep.impl(currentStep);
|
|
135
|
+
}
|
|
81
136
|
if (
|
|
82
137
|
currentStep.repeatCountMax > Step.repeatCountInfinite &&
|
|
83
138
|
currentStep.repeatCount > currentStep.repeatCountMax
|
|
@@ -160,6 +215,40 @@ export class Step {
|
|
|
160
215
|
this._stepId = undefined;
|
|
161
216
|
}
|
|
162
217
|
|
|
218
|
+
/**
|
|
219
|
+
* 添加步骤拦截器
|
|
220
|
+
* @param interceptor 拦截器函数
|
|
221
|
+
*/
|
|
222
|
+
static addInterceptor(interceptor: StepInterceptor): void {
|
|
223
|
+
this._interceptors.push(interceptor);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 移除步骤拦截器
|
|
228
|
+
* @param interceptor 要移除的拦截器函数
|
|
229
|
+
*/
|
|
230
|
+
static removeInterceptor(interceptor: StepInterceptor): void {
|
|
231
|
+
const index = this._interceptors.indexOf(interceptor);
|
|
232
|
+
if (index > -1) {
|
|
233
|
+
this._interceptors.splice(index, 1);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 清空所有拦截器
|
|
239
|
+
*/
|
|
240
|
+
static clearInterceptors(): void {
|
|
241
|
+
this._interceptors = [];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* 获取所有拦截器
|
|
246
|
+
* @returns 拦截器数组
|
|
247
|
+
*/
|
|
248
|
+
static getInterceptors(): StepInterceptor[] {
|
|
249
|
+
return [...this._interceptors];
|
|
250
|
+
}
|
|
251
|
+
|
|
163
252
|
/**
|
|
164
253
|
* 步骤ID
|
|
165
254
|
*/
|