assistsx-js 0.0.1353 → 0.0.2001

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