gaoshuaixing 4 years ago
parent
commit
377d2142ab
3 changed files with 58 additions and 8 deletions
  1. 2 2
      electron/config.js
  2. 16 6
      electron/lib/autoUpdater.js
  3. 40 0
      electron/lib/helper.js

+ 2 - 2
electron/config.js

@@ -52,12 +52,12 @@ const config = {
     workers: 1
   },
   autoUpdate: {
-    windows: false, // windows可以开启;macOs 需要签名验证
+    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
+      url: 'http://img01.kaka996.com/exe/electron-egg/' // resource dir, end with '/'
     }
   },
   awakeProtocol: {

+ 16 - 6
electron/lib/autoUpdater.js

@@ -3,15 +3,26 @@
 const updater = require("electron-updater");
 const autoUpdater = updater.autoUpdater;
 const config = require('../config');
-const path = require('path');
 const {app} = require('electron');
 const eLogger = require('./eLogger').get();
+const helper = require('./helper');
 
 exports.setup = function () {
-  const pkgInfo = require(path.join(app.getAppPath(), 'package.json'));
-  eLogger.info('[autoUpdater] [setup] current version: ', pkgInfo.version);
+  const version = app.getVersion();
+  eLogger.info('[autoUpdater] [setup] current version: ', version);
+  const platformObj = helper.getPlatform();
+
   const updateConfig = config.get('autoUpdate');
-  autoUpdater.setFeedURL(updateConfig.options);
+  let server = updateConfig.options.url;
+  server = `${server}${platformObj.platform}/${platformObj.arch}`;
+  eLogger.info('[autoUpdater] [setup] server: ', server);
+  updateConfig.options.url = server;
+
+  try {
+    autoUpdater.setFeedURL(updateConfig.options);
+  } catch (error) {
+    eLogger.error('[autoUpdater] [setup] setFeedURL error : ', error);
+  }
 
   autoUpdater.on('checking-for-update', () => {
     sendStatusToWindow('Checking for update...');
@@ -34,8 +45,7 @@ exports.setup = function () {
   autoUpdater.on('update-downloaded', (info) => {
     sendStatusToWindow('Update downloaded');
     // quit and update
-    MAIN_WINDOW.destroy();
-    app.quit();
+    helper.appQuit();
     autoUpdater.quitAndInstall();
   });
 

+ 40 - 0
electron/lib/helper.js

@@ -1,12 +1,52 @@
 'use strict';
 
+const is = require('electron-is');
 const { app } = require('electron');
 
 /**
  * application quit
+ * 
  * @return {undefined}
  */
 exports.appQuit = function () {
 	MAIN_WINDOW.destroy();
 	app.quit();
+}
+
+/**
+ * get Platform
+ * 
+ * @return {Object}
+ */
+exports.getPlatform = function () {
+	let platform = null;
+	let arch = null;
+	if (is.windows()) {
+		platform = 'windows';
+	} else if (is.macOS()) {
+		platform = 'macOS';
+	} else if (is.linux()) {
+		platform = 'linux';
+	} else {
+		platform = 'other';
+	}
+
+	if (is.x86()) {
+		arch = '32';
+	} else if (is.x64()) {
+		arch = '64';
+	} else if (process.arch == 'arm') {
+		arch = 'arm32';
+	} else if (process.arch == 'arm64') {
+		arch = 'arm64';
+	} else {
+		arch = 'other';
+	}
+
+	const platfromObj = {
+		platform: platform,
+		arch: arch
+	};
+
+	return platfromObj;
 }