gaoshuaixing hace 3 años
padre
commit
0dc733cc98

+ 10 - 13
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;
   }
 

+ 3 - 1
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' // 此频道在后端也有相同定义
 }
 
 /**

+ 3 - 3
frontend/src/utils/ipcRenderer.js

@@ -6,12 +6,12 @@ const { ipcRenderer: ipc } = window.require && window.require('electron') || {}
  * @param param
  * @returns {Promise<unknown>}
  */
-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) // 全局注入调用主进程函数的方法
   }
 }

+ 4 - 4
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);
         })
       }

+ 3 - 1
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);
         }  

+ 1 - 0
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;

+ 2 - 6
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);
-    },
   }
 };
 </script>

+ 8 - 4
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);
       })      
     },

+ 3 - 4
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);      
+      })       
     },
   }
 };

+ 2 - 2
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);
       // })

+ 10 - 14
frontend/src/views/base/theme/Index.vue

@@ -46,28 +46,24 @@ export default {
     };
   },
   mounted () {
-    this.init();
   },
   methods: {
-    init () {
+    setTheme (e) {
       const self = this;
-      this.$ipc.on(ipcApiRoute.setTheme, (event, result) => {
-        console.log('result:', result)
-        self.currentThemeMode = result;
-      })
+      this.currentThemeMode = e.target.value;
+      console.log('setTheme currentThemeMode:', this.currentThemeMode)
 
-      this.$ipc.on(ipcApiRoute.getTheme, (event, result) => {
+      this.$ipcCall(ipcApiRoute.setTheme, this.currentThemeMode).then(result => {
         console.log('result:', result)
         self.currentThemeMode = result;
-      })
-    },
-    setTheme (e) {
-      this.currentThemeMode = e.target.value;
-      console.log('setTheme currentThemeMode:', this.currentThemeMode)
-      this.$ipc.send(ipcApiRoute.setTheme, this.currentThemeMode);
+      })      
     },
     getTheme () {
-      this.$ipc.send(ipcApiRoute.getTheme, '');
+      const self = this;
+      this.$ipcCall(ipcApiRoute.getTheme).then(result => {
+        console.log('result:', result)
+        self.currentThemeMode = result;
+      })  
     },
   }
 };

+ 12 - 13
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);
+      })
     },
   }
 };

+ 1 - 1
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);
       })
     },

+ 2 - 2
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);
       })
     },