Sfoglia il codice sorgente

自动更新优化

gaoshuaixing 3 anni fa
parent
commit
86e0000f1e

File diff suppressed because it is too large
+ 0 - 0
app/public/css/app.84c646e9.css


+ 1 - 0
app/public/css/chunk-4922ae20.42e97468.css

@@ -0,0 +1 @@
+#app-demo-window[data-v-667bcd63]{padding:0 10px;text-align:left;width:100%}#app-demo-window .one-block-1[data-v-667bcd63]{font-size:16px;padding-top:10px}#app-demo-window .one-block-2[data-v-667bcd63]{padding-top:10px}

File diff suppressed because it is too large
+ 0 - 0
app/public/index.html


File diff suppressed because it is too large
+ 0 - 0
app/public/js/app.708bbbaf.js


File diff suppressed because it is too large
+ 0 - 0
app/public/js/app.708bbbaf.js.map


File diff suppressed because it is too large
+ 0 - 0
app/public/js/app.f33ab358.js


File diff suppressed because it is too large
+ 0 - 0
app/public/js/app.f33ab358.js.map


+ 2 - 0
app/public/js/chunk-4922ae20.1bf6678e.js

@@ -0,0 +1,2 @@
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-4922ae20"],{"2e16":function(t,n,e){"use strict";e.r(n);var o=function(){var t=this,n=t.$createElement,e=t._self._c||n;return e("div",{attrs:{id:"app-demo-window"}},[t._m(0),e("div",{staticClass:"one-block-2"},[e("a-space",[e("a-button",{on:{click:function(n){return t.checkForUpdater()}}},[t._v("检查更新")]),e("a-button",{on:{click:function(n){return t.download()}}},[t._v("下载并安装")])],1)],1)])},a=[function(){var t=this,n=t.$createElement,e=t._self._c||n;return e("div",{staticClass:"one-block-1"},[e("span",[t._v(" 1. 自动更新 ")])])}],c={data:function(){return{status:0}},mounted:function(){this.init()},methods:{init:function(){var t=this;t.$ipc.on("app.updater",(function(n,e){e=JSON.parse(e),console.log("app updater:",e);var o=e.desc;t.status=e.status,t.$message.info(o)}))},checkForUpdater:function(){var t=this;t.$ipcCallMain("example.checkForUpdater").then((function(t){console.log(t)}))},download:function(){if(1===this.status){var t=this;t.$ipcCallMain("example.downloadApp").then((function(t){console.log(t)}))}else this.$message.info("没有可用版本")}}},i=c,s=(e("d1e9"),e("2877")),u=Object(s["a"])(i,o,a,!1,null,"667bcd63",null);n["default"]=u.exports},"55bb":function(t,n,e){},d1e9:function(t,n,e){"use strict";e("55bb")}}]);
+//# sourceMappingURL=chunk-4922ae20.1bf6678e.js.map

File diff suppressed because it is too large
+ 0 - 0
app/public/js/chunk-4922ae20.1bf6678e.js.map


File diff suppressed because it is too large
+ 0 - 0
app/view/index.ejs


+ 14 - 0
electron/ipc/example.js

@@ -319,4 +319,18 @@ exports.checkForUpdater = function (event, channel, arg) {
   }
 
   return;
+}
+
+/**
+ * 下载新版本
+ */
+exports.downloadApp = function (event, channel, arg) {
+  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;
 }

+ 36 - 16
electron/lib/autoUpdater.js

@@ -6,6 +6,7 @@ const config = require('../config');
 const {app} = require('electron');
 const eLogger = require('./eLogger').get();
 const helper = require('./helper');
+const constant = require('./constant');
 
 /**
  * 安装模块
@@ -33,30 +34,44 @@ exports.setup = function () {
   }
 
   autoUpdater.on('checking-for-update', () => {
-    sendStatusToWindow('正在检查更新...');
+    //sendStatusToWindow('正在检查更新...');
   })
   autoUpdater.on('update-available', (info) => {
-    sendStatusToWindow('有可用更新');
+    info.status = constant.appUpdaterStatus.available;
+    info.desc = '有可用更新';
+    sendStatusToWindow(info);
   })
   autoUpdater.on('update-not-available', (info) => {
-    sendStatusToWindow('没有可用更新');
+    info.status = constant.appUpdaterStatus.noAvailable;
+    info.desc = '没有可用更新';
+    sendStatusToWindow(info);
   })
   autoUpdater.on('error', (err) => {
-    sendStatusToWindow('更新异常: ' + err);
+    let info = {
+      status: constant.appUpdaterStatus.error,
+      desc: err
+    }
+    sendStatusToWindow(info);
   })
   autoUpdater.on('download-progress', (progressObj) => {
-    let log_message = "下载进度: " + progressObj.bytesPerSecond;
-    log_message = log_message + ' - 已下载 ' + progressObj.percent + '%';
-    log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
-    sendStatusToWindow(log_message);
+    let text = "下载进度: " + progressObj.bytesPerSecond;
+    text = text + ' - 已下载 ' + progressObj.percent + '%';
+    text = text + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
+
+    let info = {
+      status: constant.appUpdaterStatus.downloading,
+      desc: text
+    }
+    sendStatusToWindow(info);
   })
   autoUpdater.on('update-downloaded', (info) => {
-    sendStatusToWindow('下载完成');
+    console.log('downloaded info:', info)
+    info.status = constant.appUpdaterStatus.downloaded;
+    info.desc = '下载完成';
+    sendStatusToWindow(info);
     // quit and update
-    if (updateConfig.force) {
-      helper.appQuit();
-      autoUpdater.quitAndInstall();
-    }
+    helper.appQuit();
+    autoUpdater.quitAndInstall();
   });
 
 };
@@ -65,9 +80,14 @@ exports.checkUpdate = function () {
   autoUpdater.checkForUpdates();
 }
 
-function sendStatusToWindow(text) {
-  eLogger.info(text);
-  MAIN_WINDOW.webContents.send('public.message', text);
+exports.download = function () {
+  autoUpdater.downloadUpdate();
+}
+
+function sendStatusToWindow(content = {}) {
+  const textJson = JSON.stringify(content);
+  eLogger.info(textJson);
+  MAIN_WINDOW.webContents.send(constant.ipcChannels.appUpdater, textJson);
 }
 
 exports = module.exports;

+ 11 - 0
electron/lib/constant.js

@@ -7,4 +7,15 @@ module.exports = {
       ]
     }
   },
+  ipcChannels: {
+    appMessage: 'app.message',
+    appUpdater: 'app.updater'
+  },
+  appUpdaterStatus: {
+    error: -1,
+    available: 1,
+    noAvailable: 2,
+    downloading: 3,
+    downloaded: 4,
+  }
 };

+ 1 - 0
frontend/src/App.vue

@@ -19,6 +19,7 @@ export default {
   methods: {
     initIpc () {
       const self = this;
+      // 公共频道
       self.$ipc.on('public.message', (event, result) => {
         // 使用ant-desing-vue, message组件
         self.$message.info(result);

+ 23 - 3
frontend/src/views/demo/updater/Index.vue

@@ -8,7 +8,7 @@
     <div class="one-block-2">
       <a-space>
         <a-button @click="checkForUpdater()">检查更新</a-button>
-        <!-- <a-button @click="check(0)">打开哔哩哔哩</a-button> -->
+        <a-button @click="download()">下载并安装</a-button>
       </a-space>
     </div>
     <!-- <div class="one-block-1">
@@ -28,19 +28,39 @@
 export default {
   data() {
     return {
-      views: [],
+      status: 0, // -1:异常,1:有可用更新,2:没有可用更新,3:下载中, 4:下载完成
     };
   },
   mounted () {
-    //this.init();
+    this.init();
   },
   methods: {
+    init () {
+      const self = this;
+      self.$ipc.on('app.updater', (event, result) => {
+        result = JSON.parse(result);
+        console.log('app updater:', result);
+        let text = result.desc;
+        self.status = result.status;
+        self.$message.info(text);
+      })
+    },
     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>

Some files were not shown because too many files changed in this diff