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