gaoshuaixing 3 роки тому
батько
коміт
d276b46af1

+ 56 - 1
electron/controller/example.js

@@ -433,7 +433,62 @@ class ExampleController extends Controller {
     }
 
     return res
-  } 
+  }
+
+  /**
+   * 获取系统主题
+   */
+  getTheme () {
+    let theme = 'system';
+    if (nativeTheme.shouldUseHighContrastColors) {
+      theme = 'light';
+    } else if (nativeTheme.shouldUseInvertedColorScheme) {
+      theme = 'dark';
+    }
+
+    return theme;
+  }
+
+  /**
+   * 设置系统主题
+   */
+  setTheme (args) {
+
+    // TODO 好像没有什么明显效果
+    nativeTheme.themeSource = args;
+
+    return args;
+  }
+
+
+  /**
+   * 检查是否有新版本
+   */
+  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();
+    // }
+
+    return;
+  }
+
+  /**
+   * 下载新版本
+   */
+  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();
+    // }
+
+    return;
+  }
+
 }
 
 module.exports = ExampleController;

+ 8 - 1
frontend/src/api/main.js

@@ -26,6 +26,12 @@ const ipcApiRoute = {
   getScreen: 'controller.example.getScreen',
   openSoftware: 'controller.example.openSoftware', 
   autoLaunch: 'controller.example.autoLaunch',
+  setTheme: 'controller.example.setTheme',
+  getTheme: 'controller.example.getTheme',
+}
+
+const specialIpcRoute = {
+  appUpdater: 'app.updater'
 }
 
 /**
@@ -41,5 +47,6 @@ const requestEggApi = (uri, parameter) => {
 
 export {
   requestEggApi,
-  ipcApiRoute
+  ipcApiRoute,
+  specialIpcRoute
 }

+ 5 - 0
frontend/src/config/router.config.js

@@ -88,6 +88,11 @@ export const constantRouterMap = [
             name: 'BaseTestApiIndex',
             component: () => import('@/views/base/testapi/Index')
           },
+          {
+            path: '/base/updater/index',
+            name: 'BaseUpdaterIndex',
+            component: () => import('@/views/base/updater/Index')
+          },  
         ]  
       },
       {

+ 20 - 11
frontend/src/views/base/system/Index.vue

@@ -14,7 +14,7 @@
             </template>
           </a-list-item-meta>
           <template v-slot:actions>
-            <a-switch v-model="autoLaunchChecked" checkedChildren="开" unCheckedChildren="关" @change="autoLaunchChange(autoLaunchChecked)" />
+            <a-switch v-model="autoLaunchChecked" checkedChildren="开" unCheckedChildren="关" @change="autoLaunchChange()" />
           </template>
         </a-list-item>
       </a-list>
@@ -36,19 +36,28 @@ export default {
   methods: {
     init () {
       const self = this;
-      this.$ipc.on(ipcApiRoute.autoLaunch, (event, result) => {
+      // this.$ipc.on(ipcApiRoute.autoLaunch, (event, result) => {
+      //   console.log('[ipcRenderer] [autoLaunch] result:', result)
+      //   this.autoLaunchChecked = result.status;
+      // })
+      // this.$ipc.send(ipcApiRoute.autoLaunch, 'check');
+      self.$ipcCallMain(ipcApiRoute.autoLaunch, 'check').then(result => {
         console.log('[ipcRenderer] [autoLaunch] result:', result)
-        self.autoLaunchChecked = result.status;
-      })
-      this.$ipc.send(ipcApiRoute.autoLaunch, 'check');
+        this.autoLaunchChecked = result.status;
+        console.log('[ipcRenderer] [autoLaunch] result2:', self.autoLaunchChecked)
+      })      
     },
     autoLaunchChange (checkStatus) {
-      console.log('[ipcRenderer] [autoLaunch] checkStatus:', checkStatus)
-      if (checkStatus) {
-        this.$ipc.send(ipcApiRoute.autoLaunch, 'close');
-      } else {
-        this.$ipc.send(ipcApiRoute.autoLaunch, 'open');       
-      }
+      console.log('[ipcRenderer] [autoLaunch] self.autoLaunchChecked:', this.autoLaunchChecked)
+      // if (checkStatus) {
+      //   this.$ipc.send(ipcApiRoute.autoLaunch, 'close');
+      // } else {
+      //   this.$ipc.send(ipcApiRoute.autoLaunch, 'open');       
+      // }
+      // self.$ipcCallMain(ipcApiRoute.selectFolder, '').then(r => {
+      //   self.dir_path = r;
+      //   self.$message.info(r);
+      // })
     },
   }
 }

+ 5 - 4
frontend/src/views/base/theme/Index.vue

@@ -32,6 +32,7 @@
   </div>
 </template>
 <script>
+import { ipcApiRoute } from '@/api/main'
 
 export default {
   data() {
@@ -50,12 +51,12 @@ export default {
   methods: {
     init () {
       const self = this;
-      this.$ipc.on('example.setTheme', (event, result) => {
+      this.$ipc.on(ipcApiRoute.setTheme, (event, result) => {
         console.log('result:', result)
         self.currentThemeMode = result;
       })
 
-      this.$ipc.on('example.getTheme', (event, result) => {
+      this.$ipc.on(ipcApiRoute.getTheme, (event, result) => {
         console.log('result:', result)
         self.currentThemeMode = result;
       })
@@ -63,10 +64,10 @@ export default {
     setTheme (e) {
       this.currentThemeMode = e.target.value;
       console.log('setTheme currentThemeMode:', this.currentThemeMode)
-      this.$ipc.send('example.setTheme', this.currentThemeMode);
+      this.$ipc.send(ipcApiRoute.setTheme, this.currentThemeMode);
     },
     getTheme () {
-      this.$ipc.send('example.getTheme', '');
+      this.$ipc.send(ipcApiRoute.getTheme, '');
     },
   }
 };

+ 87 - 0
frontend/src/views/base/updater/Index.vue

@@ -0,0 +1,87 @@
+<template>
+  <div id="app-demo-window">
+    <div class="one-block-1">
+      <span>
+        1. 自动更新
+      </span>
+    </div>  
+    <div class="one-block-2">
+      <a-space>
+        <a-button @click="checkForUpdater()">检查更新</a-button>
+        <a-button @click="download()">下载并安装</a-button>
+      </a-space>
+    </div>
+    <div class="one-block-1">
+      <span>
+        2. 下载进度
+      </span>
+    </div>  
+    <div class="one-block-2">
+      <a-progress :percent="percentNumber" status="active" />
+      <a-space>
+        {{ progress }}
+      </a-space>
+    </div>
+  </div>
+</template>
+<script>
+import { ipcApiRoute, specialIpcRoute } from '@/api/main'
+
+export default {
+  data() {
+    return {
+      status: 0, // -1:异常,1:有可用更新,2:没有可用更新,3:下载中, 4:下载完成
+      progress: '',
+      percentNumber: 0
+    };
+  },
+  mounted () {
+    this.init();
+  },
+  methods: {
+    init () {
+      const self = this;
+      self.$ipc.on(specialIpcRoute.appUpdater, (event, result) => {
+        result = JSON.parse(result);
+        self.status = result.status;
+        if (result.status == 3) {
+          self.progress = result.desc;
+          self.percentNumber = result.percentNumber;
+        } else {
+          self.$message.info(result.desc);
+        }
+      })
+    },
+    checkForUpdater () {
+      // const self = this;
+      // self.$ipcCallMain('example.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);
+      // })
+    },
+  }
+};
+</script>
+<style lang="less" scoped>
+#app-demo-window {
+  padding: 0px 10px;
+  text-align: left;
+  width: 100%;
+  .one-block-1 {
+    font-size: 16px;
+    padding-top: 10px;
+  }
+  .one-block-2 {
+    padding-top: 10px;
+  }
+}
+</style>