Skip to content

Commit

Permalink
同步优化脚本,修复已知问题
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyJiangWJ committed May 7, 2020
1 parent 5301e27 commit b946c7c
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 21 deletions.
18 changes: 15 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2019-12-09 20:42:08
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-04-27 18:55:44
* @Last Modified time: 2020-05-07 19:58:41
* @Description:
*/
'ui';
Expand All @@ -25,6 +25,8 @@ let default_config = {
auto_lock: false,
lock_x: 150,
lock_y: 970,
// 锁屏启动关闭提示框
dismissDialogIfLocked: true,
request_capture_permission: true,
// 是否保存日志文件,如果设置为保存,则日志文件会按时间分片备份在logback/文件夹下
saveLogFile: true,
Expand Down Expand Up @@ -61,8 +63,10 @@ Object.keys(default_config).forEach(key => {

if (!isRunningMode) {
if (config.device_height <= 10 || config.device_width <= 10) {
toastLog('请先运行config.js并输入设备宽高')
exit()
if (!currentEngine.endsWith('/config.js')) {
toastLog('请先运行config.js并输入设备宽高')
exit()
}
}
module.exports = function (__runtime__, scope) {
if (typeof scope.config_instance === 'undefined') {
Expand Down Expand Up @@ -163,6 +167,7 @@ if (!isRunningMode) {
ui.lockPositionContainer.setVisibility(config.auto_lock && !_hasRootPermission ? View.VISIBLE : View.INVISIBLE)
ui.lockDescNoRoot.setVisibility(!_hasRootPermission ? View.VISIBLE : View.INVISIBLE)

ui.dismissDialogIfLockedChkBox.setChecked(config.dismissDialogIfLocked)

ui.timeoutUnlockInpt.text(config.timeout_unlock + '')
ui.timeoutFindOneInpt.text(config.timeout_findOne + '')
Expand Down Expand Up @@ -282,6 +287,9 @@ if (!isRunningMode) {
<button id="showLockPointConfig" >手动输入坐标</button>
</vertical>
</horizontal>
{/* 是否锁屏启动关闭弹框提示 */}
<checkbox id="dismissDialogIfLockedChkBox" text="锁屏启动关闭弹框提示" />

{/* 基本不需要修改的 */}
<horizontal w="*" h="1sp" bg="#cccccc" margin="5 0"></horizontal>
<horizontal gravity="center">
Expand Down Expand Up @@ -467,6 +475,10 @@ if (!isRunningMode) {
config.request_capture_permission = ui.requestCapturePermissionChkBox.isChecked()
})

ui.dismissDialogIfLockedChkBox.on('click', () => {
config.dismissDialogIfLocked = ui.dismissDialogIfLockedChkBox.isChecked()
})

ui.autoLockChkBox.on('click', () => {
let checked = ui.autoLockChkBox.isChecked()
config.auto_lock = checked
Expand Down
2 changes: 1 addition & 1 deletion lib/DateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Date: 2019-12-10 19:41:12
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-04-25 20:36:33
* @Description:
* @Description: 日期格式化工具
*/
module.exports = function (date, fmt) {
if (typeof fmt === 'undefined') {
Expand Down
10 changes: 6 additions & 4 deletions lib/Unlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2019-11-05 09:12:00
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-04-26 19:38:40
* @Last Modified time: 2020-05-07 12:03:25
* @Description:
*/
let { config: _config } = require('../config.js')(runtime, this)
Expand Down Expand Up @@ -145,7 +145,7 @@ function Unlocker () {
// let y = _HEIGHT / 6
// gesture(320, [x, 5 * y], [x, 1 * y])
// 暂时写死 否则兼容性较差
gesture(320, [540, 1800], [540, 1000])
gesture(320, [500, parseInt(_config.device_height * 0.8)], [500, parseInt(_config.device_height * 0.3)])
sleep(_config.timeout_unlock)
}

Expand Down Expand Up @@ -178,8 +178,10 @@ function Unlocker () {
// 如果解锁失败
this.failed()
} else {
// 锁屏状态下启动不再弹框倒计时
_commonFunctions.getAndUpdateDismissReason('screen_locked')
if (_config.dismissDialogIfLocked) {
// 锁屏状态下启动不再弹框倒计时
_commonFunctions.getAndUpdateDismissReason('screen_locked')
}
}
}
}
Expand Down
Binary file added lib/color-region-center.dex
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/prototype/CommonFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ function CommonFunctions () {
if (!screen) {
_logUtils.errorInfo(['获取截图失败多次[{}], 可能已经没有了截图权限,重新执行脚本', errorCount], true)
automator.back()
this.setUpAutoStart(0.02)
if (releaseLock) {
_runningQueueDispatcher.removeRunningTask(true)
} else {
// 用于取消下一次运行的dialog
this.getAndUpdateDismissReason('capture-screen-error')
}
_runningQueueDispatcher.executeTargetScript(FileUtils.getRealMainScriptPath())
exit()
}
return screen
Expand Down
8 changes: 4 additions & 4 deletions lib/prototype/LogUtils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* @Author: TonyJiangWJ
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-04-27 18:51:58
* @Last Modified time: 2020-05-07 10:56:12
* @Description: 日志工具
*/

importClass(java.lang.Thread)
let { config: _config, storage_name: _storage_name } = require('../../config.js')(runtime, this)
let singletonRequire = require('../SingletonRequirer.js')(runtime, this)
let formatDate = require('../DateUtil.js')
Expand All @@ -26,7 +26,7 @@ const showToast = function (content, logFunc, isToast, appendLogFunc, prefix) {
}
innerAppendLog(content, appendLogFunc, prefix)
if (_config.show_engine_id) {
content = '[E:' + ENGINE_ID + '] - ' + content
content = '[E:' + ENGINE_ID + ' T:' + Thread.currentThread().getId() + '] - ' + content
}
logFunc(content)
}
Expand Down Expand Up @@ -126,7 +126,7 @@ const innerAppendLog = function (content, appendAnother, prefix) {
storage.put('last_back_file', compareDateTime)
removeOutdateBacklogFiles()
}
let string = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss.S') + ' ' + (prefix ? prefix : '') + ' [E:' + ENGINE_ID + '] - ' + content + '\n'
let string = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss.S') + ' ' + (prefix ? prefix : '') + ' [E:' + ENGINE_ID + ' T:' + Thread.currentThread().getId() + '] - ' + content + '\n'
files.ensureDir(FileUtils.getRealMainScriptPath(true) + '/logs/')
let logFilePath = FileUtils.getRealMainScriptPath(true) + '/logs/log-verboses.log'
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/prototype/RunningQueueDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function RunningQueueDispatcher () {
let compareSource = compareEngine.getSource() + ''
_logUtils.debugInfo('Dispatcher:对比脚本信息 id:' + compareEngine.id + ' source:' + compareSource)
if (currentEngine.id !== compareEngine.id && compareSource === currentSource) {
_logUtils.warnInfo('Dispatcher:脚本正在运行中 退出当前脚本:' + currentSource, true)
_logUtils.warnInfo(['Dispatcher:脚本正在运行中 退出当前脚本:{} - {}', currentEngine.id, currentSource], true)
this.removeRunningTask(true)
engines.myEngine().forceStop()
exit()
Expand Down
4 changes: 2 additions & 2 deletions lib/prototype/WidgetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2019-11-05 09:12:00
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-04-28 01:41:37
* @Last Modified time: 2020-05-07 20:52:15
* @Description:
*/
let { config: _config } = require('../../config.js')(runtime, this)
Expand Down Expand Up @@ -169,7 +169,7 @@ const widgetGetOne = function (contentVal, timeout, containType, suspendWarning)
let result = {
target: target,
isDesc: isDesc,
content: content
content: isDesc ? target.desc() : target.text()
}
return result
}
Expand Down
16 changes: 12 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* @Author: TonyJiangWJ
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-04-26 19:30:30
* @Last Modified time: 2020-05-07 10:43:15
* @Description:
*/
let { config } = require('./config.js')(runtime, this)
let singletonRequire = require('./lib/SingletonRequirer.js')(runtime, this)
let runningQueueDispatcher = singletonRequire('RunningQueueDispatcher')
let { logInfo, errorInfo, warnInfo, debugInfo, infoLog } = singletonRequire('LogUtils')
let { logInfo, errorInfo, warnInfo, debugInfo, infoLog, debugForDev, clearLogFile } = singletonRequire('LogUtils')
let FloatyInstance = singletonRequire('FloatyUtil')
let commonFunctions = singletonRequire('CommonFunction')
let tryRequestScreenCapture = singletonRequire('TryRequestScreenCapture')
Expand Down Expand Up @@ -39,9 +39,14 @@ logInfo('---前置校验完成;启动系统--->>>>')
if (files.exists('version.json')) {
let content = JSON.parse(files.read('version.json'))
logInfo(['版本信息:{} nodeId:{}', content.version, content.nodeId])
} else if (files.exists('project.json')) {
let content = JSON.parse(files.read('project.json'))
logInfo(['版本信息:{}', content.versionName])
} else {
logInfo('无法获取脚本版本信息')
}
logInfo(['AutoJS version: {}', app.autojs.versionName])
logInfo(['device info: {} {} {}', device.brand, device.product, device.release])

logInfo(['设备分辨率:[{}, {}]', config.device_width, config.device_height])
logInfo('======解锁并校验截图权限======')
Expand All @@ -67,7 +72,8 @@ let actionSuccess = commonFunctions.waitFor(function () {
if (!actionSuccess || !screenPermission) {
errorInfo('请求截图失败, 设置6秒后重启')
runningQueueDispatcher.removeRunningTask()
commonFunctions.setUpAutoStart(0.1)
sleep(6000)
runningQueueDispatcher.executeTargetScript(FileUtils.getRealMainScriptPath())
exit()
} else {
logInfo('请求截屏权限成功')
Expand All @@ -76,7 +82,9 @@ if (!actionSuccess || !screenPermission) {
if (!FloatyInstance.init()) {
runningQueueDispatcher.removeRunningTask()
// 悬浮窗初始化失败,6秒后重试
commonFunctions.setUpAutoStart(0.1)
sleep(6000)
runningQueueDispatcher.executeTargetScript(FileUtils.getRealMainScriptPath())
exit()
}
/************************
* 主程序
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/doc/RunningQueueDispatcherMindMap.mmap
Binary file not shown.
6 changes: 5 additions & 1 deletion sync_libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: TonyJiangWJ
# @Date: 2020-04-27 09:15:51
# @Last Modified by: TonyJiangWJ
# @Last Modified time: 2020-04-29 22:10:23
# @Last Modified time: 2020-05-07 11:16:36
# @Description:
###
#!/bin/bash
Expand Down Expand Up @@ -49,6 +49,10 @@ target_files=(
"unit/获取当前页面的布局信息.js"
"resources/for_update/autojs-tools.dex"
"lib/autojs-tools.dex"
"lib/color-region-center.dex"
"lib/SingletonRequirer.js"
"lib/DateUtil.js"
"lib/Unlock.js"
)
# 定义target_files下标,mac下的bash无法使用dict 暂时这么写
running_queue_dispatcher=0
Expand Down

0 comments on commit b946c7c

Please sign in to comment.