2 Commits

  1. 4
      app/build.gradle
  2. 2
      app/src/main/assets/apps/__UNI__3B4D40B/www/app-service.js
  3. 2
      daemonlibrary/src/main/java/com/shihoo/daemon/Daemon_Uni.java
  4. 29
      daemonlibrary/src/main/java/com/shihoo/daemon/watchdog/DaemonHelper.java
  5. 4
      uniapp_project_code/src/pages/login/index.vue
  6. 62
      uniapp_project_code/src/pages/login/mixins/watchDogCompositionAPI.js
  7. 74
      uniapp_project_code/src/pages/login/mixins/watchDogOptionsAPI.js

4
app/build.gradle

@ -8,8 +8,8 @@ android {
minSdkVersion 21
targetSdkVersion 28 //21 io.dcloud.PandoraEntry apk入口时 targetSDKVersion>=21
versionCode 118
versionName "1.1.8"
versionCode 121
versionName "1.2.1"
multiDexEnabled true
ndk {
// abiFilters 'x86','armeabi-v7a'

2
app/src/main/assets/apps/__UNI__3B4D40B/www/app-service.js
File diff suppressed because it is too large
View File

2
daemonlibrary/src/main/java/com/shihoo/daemon/Daemon_Uni.java

@ -34,7 +34,7 @@ public class Daemon_Uni extends UniModule {
* */
@UniJSMethod(uiThread = true)
public void startWatchDog(JSONObject options, UniJSCallback callback) {//
Daemon_UniAppProxy.daemonHelper.startWatchDogUni();
Daemon_UniAppProxy.daemonHelper.startWatchDog();
JSONObject data = new JSONObject();
Boolean isOn = Daemon_UniAppProxy.daemonHelper.isRestartApp();
data.put("code", isOn);

29
daemonlibrary/src/main/java/com/shihoo/daemon/watchdog/DaemonHelper.java

@ -53,8 +53,19 @@ public class DaemonHelper {
/**
* 在uniapp启动守护进程
*/
public void startWatchDogUni(){
startWatchDog(my_application);
public void startWatchDog(){
// startWatchDog(my_application);
Log.d(TAG, "startWatchDog: 开启守护进程");
startRestartApp();
}
/**
* 关闭守护进程
*/
public void closeWatchDog() {
Log.d(TAG, "closeWatchDog: 关闭守护进程");
// stopDaemonEnv();
// cancelDaemonEnvJob();
stopRestartApp();
}
/**
@ -115,15 +126,7 @@ public class DaemonHelper {
buildNotify(application);
}
/**
* 关闭守护进程
*/
public void closeWatchDog() {
Log.d(TAG, "closeWatchDog: 关闭守护进程");
// stopDaemonEnv();
// cancelDaemonEnvJob();
stopRestartApp();
}
/**
* 停止在守护进程中重启APP
@ -133,6 +136,10 @@ public class DaemonHelper {
mainWorkService.isNeedRestartApp = false;
}
private void startRestartApp(){
mainWorkService.isNeedRestartApp = true;
}
/**
* 调用MainWorkService的stopWork方法
*

4
uniapp_project_code/src/pages/login/index.vue

@ -17,6 +17,7 @@
<view class="li-btn">
<login-button @click="clickLogin">登录</login-button>
<login-button @click="selectDaemon" style="margin-top: 20rpx;">进程守护设置</login-button>
</view>
</view>
@ -48,12 +49,13 @@
} from 'vue'
import { onLoad,onReady } from '@dcloudio/uni-app';
import md5 from '@/utils/md5.js'
import {useWatchDog} from './mixins/watchDogCompositionAPI.js';
onReady(async () => {
autoLogin()
});
// import { uni } from '@dcloudio/uni-h5';
const { isDaemonRun, selectDaemon, daemonRun } = useWatchDog();//API
const username = ref('');
const password = ref('');

62
uniapp_project_code/src/pages/login/mixins/watchDogCompositionAPI.js

@ -0,0 +1,62 @@
// useWatchDog.js
import { ref } from 'vue';
// #ifdef APP-PLUS
const Daemon_Uni = uni.requireNativePlugin('Daemon_Uni');
// #endif
export function useWatchDog() {
const isDaemonRun = ref(false); // 进程守护状态
// 异步函数来开启或关闭守护进程
async function selectDaemon() {
const _arr = ["开启-进程守护", "关闭-进程守护"];
uni.showActionSheet({
itemList: _arr,
success: async (res) => {
const _sel = _arr[res.tapIndex];
console.log('选中了第' + (res.tapIndex + 1) + '个按钮' + _sel);
if (res.tapIndex === 0) {
await daemonRun(true);
} else {
await daemonRun(false);
}
console.log("daemonRun", _sel, isDaemonRun.value);
},
fail: (res) => {
console.log(res.errMsg);
}
});
}
// 开启与关闭守护进程
async function daemonRun(run) {
// #ifdef APP-PLUS
if (run) {
Daemon_Uni.startWatchDog({
"api_name": "",
}, (ret) => {
console.log(ret);
isDaemonRun.value = true; // 假设总是成功开启
});
} else {
Daemon_Uni.closeWatchDog({
"api_name": "",
}, (ret) => {
console.log(ret);
// 同上,假设关闭总是成功
isDaemonRun.value = false;
});
}
// #endif
}
// 返回响应式数据和函数
return {
isDaemonRun,
selectDaemon,
daemonRun,
};
}

74
uniapp_project_code/src/pages/login/mixins/watchDogOptionsAPI.js

@ -0,0 +1,74 @@
// mixins/watchDog.js
// 离线人脸识别
// #ifdef APP-PLUS
const Daemon_Uni = uni.requireNativePlugin('Daemon_Uni');
// #endif
import util from '@/utils/util';
export default {
data() {
return {
is_daemon_run: false, //进程守护状态
}
},
created() {
console.warn('Mixin watchDog.js!');
},
methods: {
// 选择进程守护 开/关. 该函数为附带交互的进程守护开关选择
async selectDaemon(){
let that = this
let _arr = ["开启-进程守护","关闭-进程守护"];
uni.showActionSheet({
itemList:_arr,
success: async function (res) {
let _sel = _arr[res.tapIndex]
let _val = ""
console.log('选中了第' + (res.tapIndex + 1) + '个按钮' +_sel);
if(res.tapIndex==0){
let daemon_res = await that.daemonRun(true)
that.$nextTick(()=>{
// that.globalData.localConfig.is_daemon_run = daemon_res
that.is_daemon_run = daemon_res
});
}else{
let daemon_res = await that.daemonRun(false)
that.$nextTick(()=>{
// that.globalData.localConfig.is_daemon_run = daemon_res
that.is_daemon_run = daemon_res
});
}
console.log("daemonRun",_sel,_val,that.is_daemon_run)
},
fail: function (res) {
console.log(res.errMsg);
}
})
},
//开启与关闭保活
daemonRun(run){
// #ifdef APP-PLUS
if(run){
Daemon_Uni.startWatchDog({
"api_name":"",
},
(ret) => {
console.log(ret)
})
}else{
Daemon_Uni.closeWatchDog({
"api_name":"",
},
(ret) => {
console.log(ret)
})
}
// #endif
},
}
}
Loading…
Cancel
Save