assistsx-js 0.0.1353 → 0.0.2002

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