Skip to content

Commit

Permalink
优化配置工具
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyJiangWJ committed Nov 30, 2020
1 parent 7a70c74 commit 3e6b86a
Show file tree
Hide file tree
Showing 9 changed files with 2,899 additions and 2,324 deletions.
2,531 changes: 2,531 additions & 0 deletions _config.js

Large diffs are not rendered by default.

2,233 changes: 1 addition & 2,232 deletions config.js

Large diffs are not rendered by default.

39 changes: 36 additions & 3 deletions config_with_webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2020-11-29 11:28:15
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-11-30 00:02:24
* @Last Modified time: 2020-11-30 23:41:02
* @Description:
*/
"ui";
Expand All @@ -29,8 +29,10 @@ activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LI

let singletonRequire = require('./lib/SingletonRequirer.js')(runtime, this)
let FileUtils = singletonRequire('FileUtils')
let { config, storage_name } = require('./config.js')(runtime, this)
let { config, default_config, storage_name } = require('./config.js')(runtime, this)
let commonFunctions = singletonRequire('CommonFunction')
config.hasRootPermission = files.exists("/sbin/su") || files.exists("/system/xbin/su") || files.exists("/system/bin/su")

ui.layout(
<vertical>
<webview id="webview" margin="0 10" />
Expand Down Expand Up @@ -60,6 +62,31 @@ let bridgeHandler = {
storageConfig.put(key, newVal)
}
})
sendConfigChangedBroadcast(data)
},
showRealtimeVisualConfig: () => {
// 不在ui线程启动的话会丢失线程上下文,导致执行异常
ui.run(function () {
let source = FileUtils.getCurrentWorkPath() + '/test/全局悬浮窗显示-配置信息.js'
engines.execScriptFile(source, { path: source.substring(0, source.lastIndexOf('/')) })
})
},
resetConfigs: (data, callbackId) => {
ui.run(function () {
confirm('确定要将所有配置重置为默认值吗?').then(ok => {
if (ok) {
Object.keys(default_config).forEach(key => {
let defaultValue = default_config[key]
config[key] = defaultValue
storageConfig.put(key, defaultValue)
})
toastLog('重置默认值')
postMessageToWebView({ functionName: 'reloadBasicConfigs' })
postMessageToWebView({ functionName: 'reloadAdvanceConfigs' })
postMessageToWebView({ functionName: 'reloadWidgetConfigs' })
}
})
})
},
// 测试回调
callback: (data, callbackId) => {
Expand Down Expand Up @@ -106,7 +133,7 @@ ui.webview.setWebViewClient(
ui.webview.setWebChromeClient(
new JavaAdapter(WebChromeClient, {
onConsoleMessage: function (message) {
message.message && log(message.message())
message.message && log('h5:' + message.message())
}
})
)
Expand Down Expand Up @@ -182,3 +209,9 @@ function registerSensors () {
})
}
}

function sendConfigChangedBroadcast (newConfig) {
newConfig = newConfig || config
console.verbose(engines.myEngine().id + ' 发送广播 通知配置变更')
events.broadcast.emit(storage_name + 'config_changed', { config: newConfig, id: engines.myEngine().id })
}
14 changes: 11 additions & 3 deletions lib/prototype/CommonFunction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: TonyJiangWJ
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-11-29 19:39:52
* @Last Modified time: 2020-11-30 23:43:20
* @Description: 通用工具
*/
importClass(android.content.Context)
Expand Down Expand Up @@ -140,8 +140,12 @@ function CommonFunctions () {
/**
* 自动设置刘海的偏移量
*/
this.autoSetUpBangOffset = function () {
this.autoSetUpBangOffset = function (doNotRestart) {
if (_config.auto_set_bang_offset || _config.updated_temp_flag_1325) {
if (!this.requestScreenCaptureOrRestart(doNotRestart)) {
// 请求截图权限失败,取消设置刘海偏移量
return
}
let DETECT_COLOR = '#10FF1F'
let window = floaty.rawWindow(
<frame id="container" gravity="center" bg="#10FF1F">
Expand Down Expand Up @@ -1550,7 +1554,7 @@ function CommonFunctions () {
return !_config.develop_mode && _config.limit_runnable_time_range && 30 <= checkValue && 650 >= checkValue
}

this.requestScreenCaptureOrRestart = function () {
this.requestScreenCaptureOrRestart = function (doNotRestart) {
// 请求截图权限
let screenPermission = false
let actionSuccess = this.waitFor(function () {
Expand All @@ -1564,6 +1568,9 @@ function CommonFunctions () {
}
}, 15000)
if (!actionSuccess || !screenPermission) {
if (doNotRestart) {
return false
}
_logUtils.errorInfo('请求截图失败, 设置6秒后重启')
_runningQueueDispatcher.removeRunningTask()
sleep(6000)
Expand All @@ -1573,6 +1580,7 @@ function CommonFunctions () {
_logUtils.logInfo('请求截屏权限成功')
_config.has_screen_capture_permission = true
}
return screenPermission
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/全局悬浮窗显示-配置信息.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let { debugInfo, warnInfo, errorInfo, infoLog, logInfo, debugForDev } = sRequire
let { config } = require('../config.js')(runtime, this)
let fileUtils = sRequire('FileUtils')
let commonFunction = sRequire('CommonFunction')
commonFunction.autoSetUpBangOffset()
commonFunction.autoSetUpBangOffset(true)
let offset = config.bang_offset

var window = floaty.rawWindow(
Expand Down
16 changes: 16 additions & 0 deletions vue_configs/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.custom-slide-button {
min-width: 26px;
font-size: 10px;
line-height: 18px;
text-align: center;
border-radius: 100px;
background-color: #ffffff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.simple-span {
margin: 0;
color: rgba(69, 90, 100, 0.6);
font-weight: normal;
font-size: 14px;
line-height: 16px;
}
17 changes: 14 additions & 3 deletions vue_configs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2020-11-29 13:17:06
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2020-11-29 17:17:56
* @Last Modified time: 2020-11-30 23:28:45
* @Description:
-->
<!DOCTYPE html>
Expand All @@ -15,14 +15,15 @@
<title>配置工具</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.10/lib/index.css" />
<script src="https://cdn.jsdelivr.net/npm/vue@2.6/dist/vue.min.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/vant@2.10/lib/vant.min.js"></script>
</head>

<body>
<noscript><strong>We're sorry but this doesn't work properly without JavaScript enabled. Please enable
it to continue.</strong></noscript>
<div id=app>
<van-tabs v-model="activeTab" sticky>
<van-tabs v-model="activeTab" sticky swipeable>
<van-tab title="基础设置">
<sample-configs />
</van-tab>
Expand All @@ -36,6 +37,9 @@
</div>
</body>
<script type="text/javascript">
/**
* 加载本地js文件
*/
function appendScripts(filePath) {
let element = document.createElement('script')
// element.src = 'file://' + filePath + '/vue_configs/js/vue.min.js'
Expand All @@ -50,7 +54,14 @@
}, 100 + (index++) * 10)
})
console.log('append scripts done')

let csses = ['/vue_configs/css/style.css']
csses.forEach(css => {
element = document.createElement('link')
element.href = filePath + css
element.rel = "stylesheet"
document.head.appendChild(element)
})
console.log('append css done')
}
function nativeInvoke(message) {
//document.getElementById('content').innerText = message
Expand Down
Loading

0 comments on commit 3e6b86a

Please sign in to comment.