Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
98 lines (94 loc) · 2.19 KB
/
Copy pathutils.js
File metadata and controls
98 lines (94 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
if (typeof module === 'undefined') {
requestScreenCaptureAuto();
getOcrRes();
}
else {
module.exports = {
ocrUntilFound: ocrUntilFound,
clickRect: clickRect,
unlockIfNeed: unlockIfNeed,
requestScreenCaptureAuto: requestScreenCaptureAuto,
getOcrRes: getOcrRes
};
}
function getOcrRes() {
sleep(5000);
ocrUntilFound(res => {
for (let i of res.children) {
log(i.text);
log(i.bounds);
}
return true;
}, 1, 1);
}
function ocrUntilFound(found, retry, interval) {
var res;
for (let i = 0; i < retry; ++i) {
sleep(interval);
// log('OCR中');
res = found(gmlkit.ocr(captureScreen(), "zh"))
if (res || res === 0)
return res;
}
log("OCR失败");
return null;
}
function clickRect(rect) {
sleep(1000);
click(rect.bounds.centerX(), rect.bounds.centerY());
}
/**
* 解锁屏幕
*/
function unlockIfNeed() {
if (!device.isScreenOn()) {
device.wakeUp();
sleep(1000);
const { width, height } = device;
swipe(width / 2, height * 0.8, width / 2, 0, 500);
}
if (!isLocked()) {
log("没有锁屏无需解锁");
return;
}
enterPwd('手机锁屏密码');
log("解锁完毕");
}
/**
* 手机是否锁屏
*/
function isLocked() {
var km = context.getSystemService(android.content.Context.KEYGUARD_SERVICE);
return km.isKeyguardLocked() && km.isKeyguardSecure();
}
function enterPwd(pwd) {
//点击
if (text(0).clickable(true).exists()) {
for (var i = 0; i < pwd.length; i++) {
a = pwd.charAt(i)
sleep(200);
text(a).clickable(true).findOne().click()
}
} else {
for (var i = 0; i < pwd.length; i++) {
a = pwd.charAt(i)
sleep(200);
desc(a).clickable(true).findOne().click()
}
}
}
function requestScreenCaptureAuto() {
//安卓版本高于Android 9
if (device.sdkInt > 28) {
//等待截屏权限申请并同意
threads.start(function () {
packageName('com.android.systemui').text('允许').waitFor();
text('允许').click();
});
}
//申请截屏权限
if (!requestScreenCapture()) {
log("请求截图失败");
exit();
}
}