forked from TonyJiangWJ/Ant-Forest-autoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
82 lines (80 loc) · 2.52 KB
/
main.js
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
/*
* @Author: NickHopps
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2019-12-04 10:46:59
* @Description: 蚂蚁森林自动收能量
*/
let runningQueueDispatcher = require('./lib/RunningQueueDispatcher.js')
let { config } = require('./config.js')
let LogUtils = require('./lib/LogUtils.js')
let {
debugInfo, logInfo, infoLog, warnInfo, errorInfo, clearLogFile, appendLog, removeOldLogFiles
} = LogUtils
let FloatyInstance = require('./lib/FloatyUtil.js')
let commonFunctions = require('./lib/CommonFunction.js')
let unlocker = require('./lib/Unlock.js')
let antForestRunner = require('./core/Ant_forest.js')
let formatDate = require('./lib/DateUtil.js')
let { tryRequestScreenCapture } = require('./lib/TryRequestScreenCapture.js')
logInfo('======校验是否重复运行=======')
// 检查脚本是否重复运行
commonFunctions.checkDuplicateRunning()
// 不管其他脚本是否在运行 清除任务队列 适合只使用蚂蚁森林的用户
if (config.single_script) {
runningQueueDispatcher.clearAll()
}
runningQueueDispatcher.addRunningTask()
/***********************
* 初始化
***********************/
logInfo('======校验无障碍功能======')
// 检查手机是否开启无障碍服务
// 当无障碍经常莫名消失时 可以传递true 强制开启无障碍
// if (!commonFunctions.checkAccessibilityService(true)) {
if (!commonFunctions.checkAccessibilityService()) {
try {
auto.waitFor()
} catch (e) {
warnInfo('auto.waitFor()不可用')
auto()
}
}
logInfo('---前置校验完成;启动系统--->>>>')
if (files.exists('version.json')) {
let content = JSON.parse(files.read('version.json'))
logInfo(['版本信息:{} nodeId:{}', content.version, content.nodeId])
} else {
logInfo('无法获取脚本版本信息')
}
logInfo('======解锁并校验截图权限======')
try {
unlocker.exec()
} catch (e) {
errorInfo('解锁发生异常, 三分钟后重新开始' + e)
commonFunctions.setUpAutoStart(3)
runningQueueDispatcher.removeRunningTask()
exit()
}
logInfo('解锁成功')
if (config.fuck_miui11) {
commonFunctions.showDialogAndWait()
commonFunctions.launchAutoJs()
}
// 请求截图权限
let reqResult = false
if (config.request_capture_permission) {
reqResult = tryRequestScreenCapture()
} else {
reqResult = requestScreenCapture(false)
}
if (!reqResult) {
errorInfo('请求截图失败')
runningQueueDispatcher.removeRunningTask()
exit()
} else {
logInfo('请求截图权限成功')
}
/************************
* 主程序
***********************/
antForestRunner.exec()