assistsx-js 0.0.2013 → 0.0.2015

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.
@@ -0,0 +1,105 @@
1
+ /**
2
+ * AccessibilityEvent过滤配置接口
3
+ * 用于配置AccessibilityEvent的处理方式和过滤条件
4
+ */
5
+ export interface AccessibilityEventFilterConfig {
6
+ /**
7
+ * 包名过滤
8
+ * 如果为空或null,则处理所有包的事件
9
+ * 如果指定包名,则只处理该包的事件
10
+ */
11
+ packageName?: string | null;
12
+ /**
13
+ * 是否在子线程中处理AccessibilityEvent
14
+ * true: 在子线程中处理,避免阻塞主线程
15
+ * false: 在主线程中处理
16
+ */
17
+ processInBackground?: boolean;
18
+ /**
19
+ * 是否获取节点信息
20
+ * true: 获取并解析AccessibilityNodeInfo节点信息
21
+ * false: 不获取节点信息,提高处理性能
22
+ */
23
+ fetchNodeInfo?: boolean;
24
+ /**
25
+ * 是否启用日志输出
26
+ * true: 输出AccessibilityEvent处理日志
27
+ * false: 不输出日志
28
+ */
29
+ enableLogging?: boolean;
30
+ /**
31
+ * 事件类型过滤
32
+ * 如果为空,则处理所有类型的事件
33
+ * 如果指定类型,则只处理指定类型的事件
34
+ */
35
+ eventTypes?: Set<number> | null;
36
+ /**
37
+ * 是否启用事件去重
38
+ * true: 启用去重,避免重复处理相同事件
39
+ * false: 不启用去重
40
+ */
41
+ enableDeduplication?: boolean;
42
+ }
43
+ /**
44
+ * AccessibilityEvent过滤配置类
45
+ * 用于配置AccessibilityEvent的处理方式和过滤条件
46
+ */
47
+ export declare class AccessibilityEventFilter {
48
+ /**
49
+ * 包名过滤
50
+ */
51
+ readonly packageName: string | null;
52
+ /**
53
+ * 是否在子线程中处理AccessibilityEvent
54
+ */
55
+ readonly processInBackground: boolean;
56
+ /**
57
+ * 是否获取节点信息
58
+ */
59
+ readonly fetchNodeInfo: boolean;
60
+ /**
61
+ * 是否启用日志输出
62
+ */
63
+ readonly enableLogging: boolean;
64
+ /**
65
+ * 事件类型过滤
66
+ */
67
+ readonly eventTypes: Set<number> | null;
68
+ /**
69
+ * 是否启用事件去重
70
+ */
71
+ readonly enableDeduplication: boolean;
72
+ constructor(config?: AccessibilityEventFilterConfig);
73
+ /**
74
+ * 检查是否应该处理指定包的事件
75
+ * @param targetPackageName 目标包名
76
+ * @returns true表示应该处理,false表示应该过滤
77
+ */
78
+ shouldProcessPackage(targetPackageName: string | null): boolean;
79
+ /**
80
+ * 检查是否应该处理指定类型的事件
81
+ * @param eventType 事件类型
82
+ * @returns true表示应该处理,false表示应该过滤
83
+ */
84
+ shouldProcessEventType(eventType: number): boolean;
85
+ /**
86
+ * 创建默认的过滤配置
87
+ * 所有包名,子线程处理,获取节点信息,启用日志
88
+ */
89
+ static createDefault(): AccessibilityEventFilter;
90
+ /**
91
+ * 创建高性能配置
92
+ * 不获取节点信息,不启用日志,启用去重
93
+ */
94
+ static createHighPerformance(): AccessibilityEventFilter;
95
+ /**
96
+ * 创建调试配置
97
+ * 启用所有功能,便于调试
98
+ */
99
+ static createDebug(): AccessibilityEventFilter;
100
+ /**
101
+ * 创建指定包名的过滤配置
102
+ * @param targetPackageName 目标包名
103
+ */
104
+ static createForPackage(targetPackageName: string): AccessibilityEventFilter;
105
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * AccessibilityEvent过滤配置类
3
+ * 用于配置AccessibilityEvent的处理方式和过滤条件
4
+ */
5
+ export class AccessibilityEventFilter {
6
+ constructor(config = {}) {
7
+ var _a, _b, _c, _d, _e, _f;
8
+ this.packageName = (_a = config.packageName) !== null && _a !== void 0 ? _a : null;
9
+ this.processInBackground = (_b = config.processInBackground) !== null && _b !== void 0 ? _b : true;
10
+ this.fetchNodeInfo = (_c = config.fetchNodeInfo) !== null && _c !== void 0 ? _c : true;
11
+ this.enableLogging = (_d = config.enableLogging) !== null && _d !== void 0 ? _d : false;
12
+ this.eventTypes = (_e = config.eventTypes) !== null && _e !== void 0 ? _e : null;
13
+ this.enableDeduplication = (_f = config.enableDeduplication) !== null && _f !== void 0 ? _f : false;
14
+ }
15
+ /**
16
+ * 检查是否应该处理指定包的事件
17
+ * @param targetPackageName 目标包名
18
+ * @returns true表示应该处理,false表示应该过滤
19
+ */
20
+ shouldProcessPackage(targetPackageName) {
21
+ return this.packageName === null || this.packageName === targetPackageName;
22
+ }
23
+ /**
24
+ * 检查是否应该处理指定类型的事件
25
+ * @param eventType 事件类型
26
+ * @returns true表示应该处理,false表示应该过滤
27
+ */
28
+ shouldProcessEventType(eventType) {
29
+ return this.eventTypes === null || this.eventTypes.has(eventType);
30
+ }
31
+ /**
32
+ * 创建默认的过滤配置
33
+ * 所有包名,子线程处理,获取节点信息,启用日志
34
+ */
35
+ static createDefault() {
36
+ return new AccessibilityEventFilter({
37
+ packageName: null,
38
+ processInBackground: true,
39
+ fetchNodeInfo: true,
40
+ enableLogging: false,
41
+ eventTypes: null,
42
+ enableDeduplication: false,
43
+ });
44
+ }
45
+ /**
46
+ * 创建高性能配置
47
+ * 不获取节点信息,不启用日志,启用去重
48
+ */
49
+ static createHighPerformance() {
50
+ return new AccessibilityEventFilter({
51
+ packageName: null,
52
+ processInBackground: true,
53
+ fetchNodeInfo: false,
54
+ enableLogging: false,
55
+ eventTypes: null,
56
+ enableDeduplication: true,
57
+ });
58
+ }
59
+ /**
60
+ * 创建调试配置
61
+ * 启用所有功能,便于调试
62
+ */
63
+ static createDebug() {
64
+ return new AccessibilityEventFilter({
65
+ packageName: null,
66
+ processInBackground: true,
67
+ fetchNodeInfo: true,
68
+ enableLogging: true,
69
+ eventTypes: null,
70
+ enableDeduplication: false,
71
+ });
72
+ }
73
+ /**
74
+ * 创建指定包名的过滤配置
75
+ * @param targetPackageName 目标包名
76
+ */
77
+ static createForPackage(targetPackageName) {
78
+ return new AccessibilityEventFilter({
79
+ packageName: targetPackageName,
80
+ processInBackground: true,
81
+ fetchNodeInfo: true,
82
+ enableLogging: false,
83
+ eventTypes: null,
84
+ enableDeduplication: false,
85
+ });
86
+ }
87
+ }
@@ -5,6 +5,7 @@
5
5
  import { Node } from "./Node";
6
6
  import { CallResponse } from "./CallResponse";
7
7
  import { Bounds } from "./Bounds";
8
+ import { AccessibilityEventFilter } from "AccessibilityEventFilter";
8
9
  /**
9
10
  * 无障碍事件数据结构
10
11
  */
@@ -363,6 +364,8 @@ export declare class AssistsX {
363
364
  static getUniqueDeviceId(): any;
364
365
  static getAndroidID(): any;
365
366
  static getMacAddress(): Promise<any>;
367
+ static setAccessibilityEventFilters(value: AccessibilityEventFilter[]): Promise<any>;
368
+ static addAccessibilityEventFilters(value: AccessibilityEventFilter): Promise<any>;
366
369
  /**
367
370
  * 获取屏幕尺寸
368
371
  * @returns 屏幕尺寸对象
package/dist/AssistsX.js CHANGED
@@ -566,6 +566,18 @@ export class AssistsX {
566
566
  const response = await this.asyncCall(CallMethod.getMacAddress);
567
567
  return response.getDataOrDefault({});
568
568
  }
569
+ static async setAccessibilityEventFilters(value) {
570
+ const response = this.call(CallMethod.setAccessibilityEventFilters, {
571
+ args: value,
572
+ });
573
+ return response.getDataOrDefault({});
574
+ }
575
+ static async addAccessibilityEventFilters(value) {
576
+ const response = this.call(CallMethod.addAccessibilityEventFilters, {
577
+ args: value,
578
+ });
579
+ return response.getDataOrDefault({});
580
+ }
569
581
  /**
570
582
  * 获取屏幕尺寸
571
583
  * @returns 屏幕尺寸对象
@@ -42,5 +42,7 @@ export declare const CallMethod: {
42
42
  readonly getMacAddress: "getMacAddress";
43
43
  readonly getAndroidID: "getAndroidID";
44
44
  readonly getUniqueDeviceId: "getUniqueDeviceId";
45
+ readonly addAccessibilityEventFilters: "addAccessibilityEventFilters";
46
+ readonly setAccessibilityEventFilters: "setAccessibilityEventFilters";
45
47
  };
46
- export type CallMethodType = typeof CallMethod[keyof typeof CallMethod];
48
+ export type CallMethodType = (typeof CallMethod)[keyof typeof CallMethod];
@@ -43,4 +43,6 @@ export const CallMethod = {
43
43
  getMacAddress: "getMacAddress",
44
44
  getAndroidID: "getAndroidID",
45
45
  getUniqueDeviceId: "getUniqueDeviceId",
46
+ addAccessibilityEventFilters: "addAccessibilityEventFilters",
47
+ setAccessibilityEventFilters: "setAccessibilityEventFilters",
46
48
  };
package/dist/Step.js CHANGED
@@ -105,9 +105,7 @@ export class Step {
105
105
  }
106
106
  }
107
107
  catch (e) {
108
- if (Step.showLog) {
109
- console.error(`步骤${implnName}执行出错`, e);
110
- }
108
+ console.error(`步骤${implnName}执行出错`, e);
111
109
  //步骤执行出错
112
110
  const errorMsg = JSON.stringify({
113
111
  impl: implnName,
package/dist/index.d.ts CHANGED
@@ -11,3 +11,4 @@ export * from "./WindowFlags";
11
11
  export * from "./NodeAsync";
12
12
  export * from "./AssistsXAsync";
13
13
  export * from "./StepAsync";
14
+ export * from "./AccessibilityEventFilter";
package/dist/index.js CHANGED
@@ -11,3 +11,4 @@ export * from "./WindowFlags";
11
11
  export * from "./NodeAsync";
12
12
  export * from "./AssistsXAsync";
13
13
  export * from "./StepAsync";
14
+ export * from "./AccessibilityEventFilter";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistsx-js",
3
- "version": "0.0.2013",
3
+ "version": "0.0.2015",
4
4
  "description": "assistsx-js自动化开发SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -0,0 +1,172 @@
1
+ /**
2
+ * AccessibilityEvent过滤配置接口
3
+ * 用于配置AccessibilityEvent的处理方式和过滤条件
4
+ */
5
+ export interface AccessibilityEventFilterConfig {
6
+ /**
7
+ * 包名过滤
8
+ * 如果为空或null,则处理所有包的事件
9
+ * 如果指定包名,则只处理该包的事件
10
+ */
11
+ packageName?: string | null;
12
+
13
+ /**
14
+ * 是否在子线程中处理AccessibilityEvent
15
+ * true: 在子线程中处理,避免阻塞主线程
16
+ * false: 在主线程中处理
17
+ */
18
+ processInBackground?: boolean;
19
+
20
+ /**
21
+ * 是否获取节点信息
22
+ * true: 获取并解析AccessibilityNodeInfo节点信息
23
+ * false: 不获取节点信息,提高处理性能
24
+ */
25
+ fetchNodeInfo?: boolean;
26
+
27
+ /**
28
+ * 是否启用日志输出
29
+ * true: 输出AccessibilityEvent处理日志
30
+ * false: 不输出日志
31
+ */
32
+ enableLogging?: boolean;
33
+
34
+ /**
35
+ * 事件类型过滤
36
+ * 如果为空,则处理所有类型的事件
37
+ * 如果指定类型,则只处理指定类型的事件
38
+ */
39
+ eventTypes?: Set<number> | null;
40
+
41
+ /**
42
+ * 是否启用事件去重
43
+ * true: 启用去重,避免重复处理相同事件
44
+ * false: 不启用去重
45
+ */
46
+ enableDeduplication?: boolean;
47
+ }
48
+
49
+ /**
50
+ * AccessibilityEvent过滤配置类
51
+ * 用于配置AccessibilityEvent的处理方式和过滤条件
52
+ */
53
+ export class AccessibilityEventFilter {
54
+ /**
55
+ * 包名过滤
56
+ */
57
+ public readonly packageName: string | null;
58
+
59
+ /**
60
+ * 是否在子线程中处理AccessibilityEvent
61
+ */
62
+ public readonly processInBackground: boolean;
63
+
64
+ /**
65
+ * 是否获取节点信息
66
+ */
67
+ public readonly fetchNodeInfo: boolean;
68
+
69
+ /**
70
+ * 是否启用日志输出
71
+ */
72
+ public readonly enableLogging: boolean;
73
+
74
+ /**
75
+ * 事件类型过滤
76
+ */
77
+ public readonly eventTypes: Set<number> | null;
78
+
79
+ /**
80
+ * 是否启用事件去重
81
+ */
82
+ public readonly enableDeduplication: boolean;
83
+
84
+ constructor(config: AccessibilityEventFilterConfig = {}) {
85
+ this.packageName = config.packageName ?? null;
86
+ this.processInBackground = config.processInBackground ?? true;
87
+ this.fetchNodeInfo = config.fetchNodeInfo ?? true;
88
+ this.enableLogging = config.enableLogging ?? false;
89
+ this.eventTypes = config.eventTypes ?? null;
90
+ this.enableDeduplication = config.enableDeduplication ?? false;
91
+ }
92
+
93
+ /**
94
+ * 检查是否应该处理指定包的事件
95
+ * @param targetPackageName 目标包名
96
+ * @returns true表示应该处理,false表示应该过滤
97
+ */
98
+ public shouldProcessPackage(targetPackageName: string | null): boolean {
99
+ return this.packageName === null || this.packageName === targetPackageName;
100
+ }
101
+
102
+ /**
103
+ * 检查是否应该处理指定类型的事件
104
+ * @param eventType 事件类型
105
+ * @returns true表示应该处理,false表示应该过滤
106
+ */
107
+ public shouldProcessEventType(eventType: number): boolean {
108
+ return this.eventTypes === null || this.eventTypes.has(eventType);
109
+ }
110
+
111
+ /**
112
+ * 创建默认的过滤配置
113
+ * 所有包名,子线程处理,获取节点信息,启用日志
114
+ */
115
+ public static createDefault(): AccessibilityEventFilter {
116
+ return new AccessibilityEventFilter({
117
+ packageName: null,
118
+ processInBackground: true,
119
+ fetchNodeInfo: true,
120
+ enableLogging: false,
121
+ eventTypes: null,
122
+ enableDeduplication: false,
123
+ });
124
+ }
125
+
126
+ /**
127
+ * 创建高性能配置
128
+ * 不获取节点信息,不启用日志,启用去重
129
+ */
130
+ public static createHighPerformance(): AccessibilityEventFilter {
131
+ return new AccessibilityEventFilter({
132
+ packageName: null,
133
+ processInBackground: true,
134
+ fetchNodeInfo: false,
135
+ enableLogging: false,
136
+ eventTypes: null,
137
+ enableDeduplication: true,
138
+ });
139
+ }
140
+
141
+ /**
142
+ * 创建调试配置
143
+ * 启用所有功能,便于调试
144
+ */
145
+ public static createDebug(): AccessibilityEventFilter {
146
+ return new AccessibilityEventFilter({
147
+ packageName: null,
148
+ processInBackground: true,
149
+ fetchNodeInfo: true,
150
+ enableLogging: true,
151
+ eventTypes: null,
152
+ enableDeduplication: false,
153
+ });
154
+ }
155
+
156
+ /**
157
+ * 创建指定包名的过滤配置
158
+ * @param targetPackageName 目标包名
159
+ */
160
+ public static createForPackage(
161
+ targetPackageName: string
162
+ ): AccessibilityEventFilter {
163
+ return new AccessibilityEventFilter({
164
+ packageName: targetPackageName,
165
+ processInBackground: true,
166
+ fetchNodeInfo: true,
167
+ enableLogging: false,
168
+ eventTypes: null,
169
+ enableDeduplication: false,
170
+ });
171
+ }
172
+ }
package/src/AssistsX.ts CHANGED
@@ -7,6 +7,7 @@ import { CallMethod } from "./CallMethod";
7
7
  import { CallResponse } from "./CallResponse";
8
8
  import { Bounds } from "./Bounds";
9
9
  import { decodeBase64UTF8, generateUUID } from "./Utils";
10
+ import { AccessibilityEventFilter } from "AccessibilityEventFilter";
10
11
 
11
12
  /**
12
13
  * 无障碍事件数据结构
@@ -798,6 +799,22 @@ export class AssistsX {
798
799
  const response = await this.asyncCall(CallMethod.getMacAddress);
799
800
  return response.getDataOrDefault({});
800
801
  }
802
+ public static async setAccessibilityEventFilters(
803
+ value: AccessibilityEventFilter[]
804
+ ): Promise<any> {
805
+ const response = this.call(CallMethod.setAccessibilityEventFilters, {
806
+ args: value,
807
+ });
808
+ return response.getDataOrDefault({});
809
+ }
810
+ public static async addAccessibilityEventFilters(
811
+ value: AccessibilityEventFilter
812
+ ): Promise<any> {
813
+ const response = this.call(CallMethod.addAccessibilityEventFilters, {
814
+ args: value,
815
+ });
816
+ return response.getDataOrDefault({});
817
+ }
801
818
 
802
819
  /**
803
820
  * 获取屏幕尺寸
package/src/CallMethod.ts CHANGED
@@ -1,51 +1,54 @@
1
1
  // CallMethod 常量对象
2
2
  export const CallMethod = {
3
- takeScreenshot: "takeScreenshot",
4
- overlayToast: "overlayToast",
5
- setNodeText: "setNodeText",
6
- findByTags: "findByTags",
7
- findById: "findById",
8
- findByText: "findByText",
9
- findByTextAllMatch: "findByTextAllMatch",
10
- containsText: "containsText",
11
- getAllText: "getAllText",
12
- findFirstParentByTags: "findFirstParentByTags",
13
- getAllNodes: "getAllNodes",
14
- getNodes: "getNodes",
15
- findFirstParentClickable: "findFirstParentClickable",
16
- getChildren: "getChildren",
17
- getBoundsInScreen: "getBoundsInScreen",
18
- isVisible: "isVisible",
19
- click: "click",
20
- longClick: "longClick",
21
- back: "back",
22
- home: "home",
23
- notifications: "notifications",
24
- recentApps: "recentApps",
25
- paste: "paste",
26
- focus: "focus",
27
- selectionText: "selectionText",
28
- scrollForward: "scrollForward",
29
- launchApp: "launchApp",
30
- getPackageName: "getPackageName",
31
- getScreenSize: "getScreenSize",
32
- getAppScreenSize: "getAppScreenSize",
33
- scrollBackward: "scrollBackward",
34
- setOverlayFlags: "setOverlayFlags",
35
- scanQR: "scanQR",
36
- loadWebViewOverlay: "loadWebViewOverlay",
3
+ takeScreenshot: "takeScreenshot",
4
+ overlayToast: "overlayToast",
5
+ setNodeText: "setNodeText",
6
+ findByTags: "findByTags",
7
+ findById: "findById",
8
+ findByText: "findByText",
9
+ findByTextAllMatch: "findByTextAllMatch",
10
+ containsText: "containsText",
11
+ getAllText: "getAllText",
12
+ findFirstParentByTags: "findFirstParentByTags",
13
+ getAllNodes: "getAllNodes",
14
+ getNodes: "getNodes",
15
+ findFirstParentClickable: "findFirstParentClickable",
16
+ getChildren: "getChildren",
17
+ getBoundsInScreen: "getBoundsInScreen",
18
+ isVisible: "isVisible",
19
+ click: "click",
20
+ longClick: "longClick",
21
+ back: "back",
22
+ home: "home",
23
+ notifications: "notifications",
24
+ recentApps: "recentApps",
25
+ paste: "paste",
26
+ focus: "focus",
27
+ selectionText: "selectionText",
28
+ scrollForward: "scrollForward",
29
+ launchApp: "launchApp",
30
+ getPackageName: "getPackageName",
31
+ getScreenSize: "getScreenSize",
32
+ getAppScreenSize: "getAppScreenSize",
33
+ scrollBackward: "scrollBackward",
34
+ setOverlayFlags: "setOverlayFlags",
35
+ scanQR: "scanQR",
36
+ loadWebViewOverlay: "loadWebViewOverlay",
37
37
 
38
- clickByGesture: "clickByGesture",
39
- clickNodeByGesture: "clickNodeByGesture",
40
- doubleClickNodeByGesture: "doubleClickNodeByGesture",
41
- performLinearGesture: "performLinearGesture",
42
- longPressGestureAutoPaste: "longPressGestureAutoPaste",
38
+ clickByGesture: "clickByGesture",
39
+ clickNodeByGesture: "clickNodeByGesture",
40
+ doubleClickNodeByGesture: "doubleClickNodeByGesture",
41
+ performLinearGesture: "performLinearGesture",
42
+ longPressGestureAutoPaste: "longPressGestureAutoPaste",
43
43
 
44
- getAppInfo: "getAppInfo",
45
- getMacAddress: "getMacAddress",
46
- getAndroidID: "getAndroidID",
47
- getUniqueDeviceId: "getUniqueDeviceId",
44
+ getAppInfo: "getAppInfo",
45
+ getMacAddress: "getMacAddress",
46
+ getAndroidID: "getAndroidID",
47
+ getUniqueDeviceId: "getUniqueDeviceId",
48
+
49
+ addAccessibilityEventFilters: "addAccessibilityEventFilters",
50
+ setAccessibilityEventFilters: "setAccessibilityEventFilters",
48
51
  } as const;
49
52
 
50
53
  // 导出类型定义
51
- export type CallMethodType = typeof CallMethod[keyof typeof CallMethod];
54
+ export type CallMethodType = (typeof CallMethod)[keyof typeof CallMethod];
package/src/Step.ts CHANGED
@@ -153,9 +153,7 @@ export class Step {
153
153
  }
154
154
  }
155
155
  } catch (e: any) {
156
- if (Step.showLog) {
157
- console.error(`步骤${implnName}执行出错`, e);
158
- }
156
+ console.error(`步骤${implnName}执行出错`, e);
159
157
  //步骤执行出错
160
158
  const errorMsg = JSON.stringify({
161
159
  impl: implnName,
package/src/index.ts CHANGED
@@ -11,3 +11,4 @@ export * from "./WindowFlags";
11
11
  export * from "./NodeAsync";
12
12
  export * from "./AssistsXAsync";
13
13
  export * from "./StepAsync";
14
+ export * from "./AccessibilityEventFilter";