wallace5303 4 yıl önce
ebeveyn
işleme
7647d11a1a
5 değiştirilmiş dosya ile 60 ekleme ve 52 silme
  1. 43 43
      electron/autoUpdater.js
  2. 3 1
      electron/config.js
  3. 7 2
      electron/setup.js
  4. 6 5
      main.js
  5. 1 1
      package.json

+ 43 - 43
electron/autoUpdater.js

@@ -1,50 +1,50 @@
-// 'use strict';
+'use strict';
 
-// const updater = require("electron-updater");
-// const autoUpdater = updater.autoUpdater;
-// const config = require('./config');
-// const path = require('path');
-// const {app} = require('electron');
+const updater = require("electron-updater");
+const autoUpdater = updater.autoUpdater;
+const config = require('./config');
+const path = require('path');
+const {app} = require('electron');
 
-// exports.setup = function () {
-//   const pkgInfo = require(path.join(app.getAppPath(), 'package.json'));
-//   ELog.info('[autoUpdater] [setup] current version: ', pkgInfo.version);
-//   const updateConfig = config.get('autoUpdate');
-//   autoUpdater.setFeedURL(updateConfig.options);
+exports.setup = function () {
+  const pkgInfo = require(path.join(app.getAppPath(), 'package.json'));
+  ELog.info('[autoUpdater] [setup] current version: ', pkgInfo.version);
+  const updateConfig = config.get('autoUpdate');
+  autoUpdater.setFeedURL(updateConfig.options);
 
-//   autoUpdater.on('checking-for-update', () => {
-//     sendStatusToWindow('Checking for update...');
-//   })
-//   autoUpdater.on('update-available', (info) => {
-//     sendStatusToWindow('Update available.');
-//   })
-//   autoUpdater.on('update-not-available', (info) => {
-//     sendStatusToWindow('Update not available.');
-//   })
-//   autoUpdater.on('error', (err) => {
-//     sendStatusToWindow('Error in auto-updater. ' + err);
-//   })
-//   autoUpdater.on('download-progress', (progressObj) => {
-//     let log_message = "Download speed: " + progressObj.bytesPerSecond;
-//     log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
-//     log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
-//     sendStatusToWindow(log_message);
-//   })
-//   autoUpdater.on('update-downloaded', (info) => {
-//     sendStatusToWindow('Update downloaded');
-//     // quit and update
-//     autoUpdater.quitAndInstall();
-//   });
+  autoUpdater.on('checking-for-update', () => {
+    sendStatusToWindow('Checking for update...');
+  })
+  autoUpdater.on('update-available', (info) => {
+    sendStatusToWindow('Update available.');
+  })
+  autoUpdater.on('update-not-available', (info) => {
+    sendStatusToWindow('Update not available.');
+  })
+  autoUpdater.on('error', (err) => {
+    sendStatusToWindow('Error in auto-updater. ' + err);
+  })
+  autoUpdater.on('download-progress', (progressObj) => {
+    let log_message = "Download speed: " + progressObj.bytesPerSecond;
+    log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
+    log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
+    sendStatusToWindow(log_message);
+  })
+  autoUpdater.on('update-downloaded', (info) => {
+    sendStatusToWindow('Update downloaded');
+    // quit and update
+    autoUpdater.quitAndInstall();
+  });
 
-// };
+};
 
-// exports.checkUpdate = function () {
-//   autoUpdater.checkForUpdatesAndNotify();
-// }
+exports.checkUpdate = function () {
+  autoUpdater.checkForUpdatesAndNotify();
+}
 
-// function sendStatusToWindow(text) {
-//   ELog.info(text);
-//   MAIN_WINDOW.webContents.send('message', text);
-// }
+function sendStatusToWindow(text) {
+  ELog.info(text);
+  MAIN_WINDOW.webContents.send('message', text);
+}
 
-// exports = module.exports;
+exports = module.exports;

+ 3 - 1
electron/config.js

@@ -51,7 +51,9 @@ const config = {
     workers: 1
   },
   autoUpdate: {
-    enable: false,
+    windows: true, // windows可以开启;macOs 需要签名验证
+    macOS: false,
+    Linux: false,
     options: {
       provider: 'generic', // or github, s3, bintray
       url: 'https://raw.githubusercontent.com/wallace5303/electron-egg/master/' // resource dir

+ 7 - 2
electron/setup.js

@@ -3,13 +3,18 @@
 global.ELog = require('electron-log');
 const storage = require('./storage');
 const config = require('./config');
-// const autoUpdater = require('./autoUpdater');
+const is = require('electron-is');
 const api = require('./api');
 
 module.exports = () => {
   storage.setup();
   logger();
-  // autoUpdater.setup();
+  const updateConfig = config.get('autoUpdate');
+  if ((is.windows() && updateConfig.windows) || (is.macOS() && updateConfig.macOS)
+    || (is.linux() && updateConfig.linux)) {
+    const autoUpdater = require('./autoUpdater');
+    autoUpdater.setup();
+  }
   api.setup();
 }
 

+ 6 - 5
main.js

@@ -1,10 +1,10 @@
-const {app, BrowserWindow, Menu, shell} = require('electron')
+const {app, BrowserWindow, Menu} = require('electron')
 const path = require('path')
 const eggLauncher = require('./electron/lanucher')
 const setup = require('./electron/setup')
 const electronConfig = require('./electron/config')
 const storage = require('./electron/storage')
-// const autoUpdater = require('./electron/autoUpdater')
+const is = require('electron-is')
 
 // main window
 global.MAIN_WINDOW = null
@@ -76,9 +76,10 @@ async function createWindow () {
 
   // check update
   const updateConfig = electronConfig.get('autoUpdate')
-  if (updateConfig.enable) {
-    // windows可以开启;macOs 需要签名验证
-    //autoUpdater.checkUpdate()
+  if ((is.windows() && updateConfig.windows) || (is.macOS() && updateConfig.macOS)
+    || (is.linux() && updateConfig.linux)) {
+    const autoUpdater = require('./autoUpdater');
+    autoUpdater.checkUpdate();
   }
 
   return MAIN_WINDOW

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "electron-egg",
-  "version": "1.6.0",
+  "version": "1.7.0",
   "description": "A fast, desktop software development framework",
   "main": "main.js",
   "scripts": {