diff --git a/electron/controller/example.js b/electron/controller/example.js index 491e3bb..fa1ef67 100644 --- a/electron/controller/example.js +++ b/electron/controller/example.js @@ -456,12 +456,11 @@ class ExampleController extends Controller { * 检查是否有新版本 */ checkForUpdater () { - // const updateConfig = config.get('autoUpdate'); - // if ((is.windows() && updateConfig.windows) || (is.macOS() && updateConfig.macOS) - // || (is.linux() && updateConfig.linux)) { - // const autoUpdater = require('../lib/autoUpdater'); - // autoUpdater.checkUpdate(); - // } + const config = this.app.config.autoUpdate; + if ( (is.windows() && config.windows) || (is.macOS() && config.macOS) || (is.linux() && config.linux) ) { + const autoUpdater = require('../library/autoUpdater'); + autoUpdater.checkUpdate(); + } return; } @@ -470,13 +469,11 @@ class ExampleController extends Controller { * 下载新版本 */ downloadApp () { - // const updateConfig = config.get('autoUpdate'); - // if ((is.windows() && updateConfig.windows) || (is.macOS() && updateConfig.macOS) - // || (is.linux() && updateConfig.linux)) { - // const autoUpdater = require('../lib/autoUpdater'); - // autoUpdater.download(); - // } - + const config = this.app.config.autoUpdate; + if ( (is.windows() && config.windows) || (is.macOS() && config.macOS) || (is.linux() && config.linux) ) { + const autoUpdater = require('../library/autoUpdater'); + autoUpdater.download(); + } return; } diff --git a/frontend/src/api/main.js b/frontend/src/api/main.js index ad33b91..f025cb8 100644 --- a/frontend/src/api/main.js +++ b/frontend/src/api/main.js @@ -28,10 +28,12 @@ const ipcApiRoute = { autoLaunch: 'controller.example.autoLaunch', setTheme: 'controller.example.setTheme', getTheme: 'controller.example.getTheme', + checkForUpdater: 'controller.example.checkForUpdater', + downloadApp: 'controller.example.downloadApp', } const specialIpcRoute = { - appUpdater: 'app.updater' + appUpdater: 'app.updater' // 此频道在后端也有相同定义 } /** diff --git a/frontend/src/utils/ipcRenderer.js b/frontend/src/utils/ipcRenderer.js index 8ef3e82..a442ad6 100644 --- a/frontend/src/utils/ipcRenderer.js +++ b/frontend/src/utils/ipcRenderer.js @@ -6,12 +6,12 @@ const { ipcRenderer: ipc } = window.require && window.require('electron') || {} * @param param * @returns {Promise} */ -const callMain = (ipc, channel, param) => { +const call = (ipc, channel, param) => { return new Promise((resolve) => { // 声明渲染进程函数, 用于主进程函数回调, 返回数据 // 调用主进程函数 ipc.once(channel, (event, result) => { - console.log('[ipcRenderer] [callMain] result:', result) + console.log('[ipcRenderer] [call] result:', result) resolve(result) }) ipc.send(channel, param) @@ -21,6 +21,6 @@ const callMain = (ipc, channel, param) => { export default { install(Vue) { Vue.prototype.$ipc = ipc // 全局注入ipc - Vue.prototype.$ipcCallMain = (channel, param) => callMain(ipc, channel, param) // 全局注入调用主进程函数的方法 + Vue.prototype.$ipcCall = (channel, param) => call(ipc, channel, param) // 全局注入调用主进程函数的方法 } } diff --git a/frontend/src/views/base/file/Index.vue b/frontend/src/views/base/file/Index.vue index aa264d1..eb32248 100644 --- a/frontend/src/views/base/file/Index.vue +++ b/frontend/src/views/base/file/Index.vue @@ -115,7 +115,7 @@ export default { }, methods: { openDirectry (id) { - this.$ipcCallMain(ipcApiRoute.openDirectory, {id: id}).then(r => { + this.$ipcCall(ipcApiRoute.openDirectory, {id: id}).then(r => { //console.log('r:', r) }) }, @@ -145,7 +145,7 @@ export default { }, selectDir() { const self = this; - self.$ipcCallMain(ipcApiRoute.selectFolder, '').then(r => { + self.$ipcCall(ipcApiRoute.selectFolder, '').then(r => { self.dir_path = r; self.$message.info(r); }) @@ -163,7 +163,7 @@ export default { self.$message.error(err + '异常') }) } else { - self.$ipcCallMain(ipcApiRoute.messageShow, '').then(r => { + self.$ipcCall(ipcApiRoute.messageShow, '').then(r => { self.$message.info(r); }) } @@ -181,7 +181,7 @@ export default { self.$message.error(err + '异常') }) } else { - self.$ipcCallMain(ipcApiRoute.messageShowConfirm, '').then(r => { + self.$ipcCall(ipcApiRoute.messageShowConfirm, '').then(r => { self.$message.info(r); }) } diff --git a/frontend/src/views/base/notification/Index.vue b/frontend/src/views/base/notification/Index.vue index cd810b8..03509c1 100644 --- a/frontend/src/views/base/notification/Index.vue +++ b/frontend/src/views/base/notification/Index.vue @@ -60,7 +60,9 @@ export default { methods: { init () { const self = this; - self.$ipc.on(ipcApiRoute.sendNotification, (event, result) => { + // 避免重复监听,或者将 on 功能写到一个统一的地方,只加载一次 + this.$ipc.removeAllListeners(ipcApiRoute.sendNotification); + this.$ipc.on(ipcApiRoute.sendNotification, (event, result) => { if (Object.prototype.toString.call(result) == '[object Object]') { self.$message.info(result.msg); } diff --git a/frontend/src/views/base/powermonitor/Index.vue b/frontend/src/views/base/powermonitor/Index.vue index fedade6..84db781 100644 --- a/frontend/src/views/base/powermonitor/Index.vue +++ b/frontend/src/views/base/powermonitor/Index.vue @@ -31,6 +31,7 @@ export default { methods: { init () { const self = this; + this.$ipc.removeAllListeners(ipcApiRoute.initPowerMonitor); self.$ipc.on(ipcApiRoute.initPowerMonitor, (event, result) => { if (Object.prototype.toString.call(result) == '[object Object]') { self.currentStatus = result.msg; diff --git a/frontend/src/views/base/screen/Index.vue b/frontend/src/views/base/screen/Index.vue index 8db0e8c..0937d49 100644 --- a/frontend/src/views/base/screen/Index.vue +++ b/frontend/src/views/base/screen/Index.vue @@ -36,18 +36,14 @@ export default { }; }, mounted () { - this.init(); }, methods: { - init () { + getScreen (index) { const self = this; - self.$ipc.on(ipcApiRoute.getScreen, (event, result) => { + this.$ipcCall(ipcApiRoute.getScreen, index).then(result => { self.data = result; }) }, - getScreen (index) { - this.$ipc.send(ipcApiRoute.getScreen, index); - }, } }; diff --git a/frontend/src/views/base/socket/Index.vue b/frontend/src/views/base/socket/Index.vue index 8fa373e..fca5e8c 100644 --- a/frontend/src/views/base/socket/Index.vue +++ b/frontend/src/views/base/socket/Index.vue @@ -59,23 +59,27 @@ export default { methods: { init () { const self = this; - self.$ipc.on(ipcApiRoute.socketMessageStart, (event, result) => { + // 避免重复监听,或者将 on 功能写到一个统一的地方,只加载一次 + this.$ipc.removeAllListeners(ipcApiRoute.socketMessageStart); + this.$ipc.removeAllListeners(ipcApiRoute.socketMessageStop); + + this.$ipc.on(ipcApiRoute.socketMessageStart, (event, result) => { console.log('[ipcRenderer] [socketMsgStart] result:', result) self.socketMessageString = result; }) - self.$ipc.on(ipcApiRoute.socketMessageStop, (event, result) => { + this.$ipc.on(ipcApiRoute.socketMessageStop, (event, result) => { console.log('[ipcRenderer] [socketMsgStop] result:', result) self.socketMessageString = result; }) }, helloHandle(value) { const self = this; - this.$ipcCallMain(ipcApiRoute.hello, value).then(r => { + this.$ipcCall(ipcApiRoute.hello, value).then(r => { self.$message.info(r); }) }, executeJSHandle(value) { - this.$ipcCallMain(ipcApiRoute.executeJS, value).then(r => { + this.$ipcCall(ipcApiRoute.executeJS, value).then(r => { console.log(r); }) }, diff --git a/frontend/src/views/base/software/Index.vue b/frontend/src/views/base/software/Index.vue index b9f6f99..b427065 100644 --- a/frontend/src/views/base/software/Index.vue +++ b/frontend/src/views/base/software/Index.vue @@ -39,13 +39,12 @@ export default { }, methods: { openSoft (id) { - const self = this; - this.$ipc.on(ipcApiRoute.openSoftware, (event, result) => { + const self = this; + this.$ipcCall(ipcApiRoute.openSoftware, id).then(result => { if (!result) { self.$message.error('程序不存在'); } - }) - this.$ipc.send(ipcApiRoute.openSoftware, id); + }) }, } }; diff --git a/frontend/src/views/base/system/Index.vue b/frontend/src/views/base/system/Index.vue index 26cb473..d265078 100644 --- a/frontend/src/views/base/system/Index.vue +++ b/frontend/src/views/base/system/Index.vue @@ -41,7 +41,7 @@ export default { // this.autoLaunchChecked = result.status; // }) // this.$ipc.send(ipcApiRoute.autoLaunch, 'check'); - self.$ipcCallMain(ipcApiRoute.autoLaunch, 'check').then(result => { + self.$ipcCall(ipcApiRoute.autoLaunch, 'check').then(result => { console.log('[ipcRenderer] [autoLaunch] result:', result) this.autoLaunchChecked = result.status; console.log('[ipcRenderer] [autoLaunch] result2:', self.autoLaunchChecked) @@ -54,7 +54,7 @@ export default { // } else { // this.$ipc.send(ipcApiRoute.autoLaunch, 'open'); // } - // self.$ipcCallMain(ipcApiRoute.selectFolder, '').then(r => { + // self.$ipcCall(ipcApiRoute.selectFolder, '').then(r => { // self.dir_path = r; // self.$message.info(r); // }) diff --git a/frontend/src/views/base/theme/Index.vue b/frontend/src/views/base/theme/Index.vue index 5ae926c..da16b80 100644 --- a/frontend/src/views/base/theme/Index.vue +++ b/frontend/src/views/base/theme/Index.vue @@ -46,28 +46,24 @@ export default { }; }, mounted () { - this.init(); }, methods: { - init () { - const self = this; - this.$ipc.on(ipcApiRoute.setTheme, (event, result) => { - console.log('result:', result) - self.currentThemeMode = result; - }) - - this.$ipc.on(ipcApiRoute.getTheme, (event, result) => { - console.log('result:', result) - self.currentThemeMode = result; - }) - }, setTheme (e) { + const self = this; this.currentThemeMode = e.target.value; console.log('setTheme currentThemeMode:', this.currentThemeMode) - this.$ipc.send(ipcApiRoute.setTheme, this.currentThemeMode); + + this.$ipcCall(ipcApiRoute.setTheme, this.currentThemeMode).then(result => { + console.log('result:', result) + self.currentThemeMode = result; + }) }, getTheme () { - this.$ipc.send(ipcApiRoute.getTheme, ''); + const self = this; + this.$ipcCall(ipcApiRoute.getTheme).then(result => { + console.log('result:', result) + self.currentThemeMode = result; + }) }, } }; diff --git a/frontend/src/views/base/updater/Index.vue b/frontend/src/views/base/updater/Index.vue index dd020c9..693473d 100644 --- a/frontend/src/views/base/updater/Index.vue +++ b/frontend/src/views/base/updater/Index.vue @@ -41,7 +41,8 @@ export default { methods: { init () { const self = this; - self.$ipc.on(specialIpcRoute.appUpdater, (event, result) => { + this.$ipc.removeAllListeners(specialIpcRoute.appUpdater); + this.$ipc.on(specialIpcRoute.appUpdater, (event, result) => { result = JSON.parse(result); self.status = result.status; if (result.status == 3) { @@ -53,20 +54,18 @@ export default { }) }, checkForUpdater () { - // const self = this; - // self.$ipcCallMain('example.checkForUpdater').then(r => { - // console.log(r); - // }) + this.$ipcCall(ipcApiRoute.checkForUpdater).then(r => { + console.log(r); + }) }, download () { - // if (this.status !== 1) { - // this.$message.info('没有可用版本'); - // return - // } - // const self = this; - // self.$ipcCallMain('example.downloadApp').then(r => { - // console.log(r); - // }) + if (this.status !== 1) { + this.$message.info('没有可用版本'); + return + } + this.$ipcCall(ipcApiRoute.downloadApp).then(r => { + console.log(r); + }) }, } }; diff --git a/frontend/src/views/base/window/Index.vue b/frontend/src/views/base/window/Index.vue index 4edd00a..83a3528 100644 --- a/frontend/src/views/base/window/Index.vue +++ b/frontend/src/views/base/window/Index.vue @@ -42,7 +42,7 @@ export default { }, methods: { createWindow (index) { - this.$ipcCallMain(ipcApiRoute.createWindow, this.views[index]).then(r => { + this.$ipcCall(ipcApiRoute.createWindow, this.views[index]).then(r => { console.log(r); }) }, diff --git a/frontend/src/views/base/windowview/Index.vue b/frontend/src/views/base/windowview/Index.vue index 082e8df..a1e8eef 100644 --- a/frontend/src/views/base/windowview/Index.vue +++ b/frontend/src/views/base/windowview/Index.vue @@ -45,13 +45,13 @@ export default { methods: { loadViewContent (index) { const self = this; - self.$ipcCallMain(ipcApiRoute.loadViewContent, this.views[index]).then(r => { + self.$ipcCall(ipcApiRoute.loadViewContent, this.views[index]).then(r => { console.log(r); }) }, removeViewContent (index) { const self = this; - self.$ipcCallMain(ipcApiRoute.removeViewContent, self.views[index]).then(r => { + self.$ipcCall(ipcApiRoute.removeViewContent, self.views[index]).then(r => { console.log(r); }) },