Skip to content

Commit

Permalink
增加配置,可以取消崩溃自启
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyJiangWJ committed Dec 26, 2020
1 parent 923a913 commit 147b0d9
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions lib/prototype/CrashCatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* @Author: TonyJiangWJ
* @Date: 2020-05-27 23:08:29
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-09-23 23:54:09
* @Last Modified time: 2020-12-24 21:50:58
* @Description: AutoJS崩溃自启
*/

let { storage_name } = require('../../config.js')(runtime, this)
let { storage_name, config } = require('../../config.js')(runtime, this)
let singletonRequire = require('../SingletonRequirer.js')(runtime, this)
let logUtils = singletonRequire('LogUtils')
let fileUtils = singletonRequire('FileUtils')
Expand All @@ -24,6 +24,9 @@ function CrashCatcher () {
RUN_STATE_STORAGE.put('running', false)
}
this.restartIfCrash = function () {
if (!config.auto_restart_when_crashed) {
return
}
let runningStatus = RUN_STATE_STORAGE.get('running')
if (runningStatus === 'true' || runningStatus === true) {
logUtils.warnInfo('AutoJs可能异常崩溃且已重启,重新执行脚本')
Expand All @@ -41,25 +44,27 @@ if (typeof module === 'undefined') {
// running mode
crashCatcher.restartIfCrash()
} else {
function getOnStartAction () {
let is_modify = Object.prototype.toString.call(org.autojs.autojsm.timing.TimedTask).match(/Java(Class|Object)/)
if (is_modify) {
return "org.autojs.autojsm.action.startup"
if (config.auto_restart_when_crashed) {
function getOnStartAction () {
let is_modify = Object.prototype.toString.call(org.autojs.autojsm.timing.TimedTask).match(/Java(Class|Object)/)
if (is_modify) {
return "org.autojs.autojsm.action.startup"
} else {
return "org.autojs.autojs.action.startup"
}
}
let intentTask = {
isLocal: true,
path: fileUtils.getCurrentWorkPath() + '/lib/prototype/CrashCatcher.js',
action: getOnStartAction()
}
let existTask = timers.queryIntentTasks(intentTask)
if (!existTask || existTask.length === 0) {
logUtils.debugInfo('创建异常终止后的重启任务')
timers.addIntentTask(intentTask)
} else {
return "org.autojs.autojs.action.startup"
logUtils.debugInfo(['异常终止的重启任务已存在: {}', JSON.stringify(existTask)])
}
}
let intentTask = {
isLocal: true,
path: fileUtils.getCurrentWorkPath() + '/lib/prototype/CrashCatcher.js',
action: getOnStartAction()
}
let existTask = timers.queryIntentTasks(intentTask)
if (!existTask || existTask.length === 0) {
logUtils.debugInfo('创建异常终止后的重启任务')
timers.addIntentTask(intentTask)
} else {
logUtils.debugInfo(['异常终止的重启任务已存在: {}', JSON.stringify(existTask)])
}
module.exports = crashCatcher
}

0 comments on commit 147b0d9

Please sign in to comment.