|
|
@@ -2,6 +2,9 @@ const { app } = require('electron');
|
|
|
const { autoUpdater } = require("electron-updater");
|
|
|
const is = require('electron-is');
|
|
|
const Log = require('ee-core/log');
|
|
|
+const Conf = require('ee-core/config');
|
|
|
+const Electron = require('ee-core/electron');
|
|
|
+const EE = require('ee-core/ee');
|
|
|
|
|
|
/**
|
|
|
* 自动升级插件
|
|
|
@@ -11,19 +14,18 @@ class AutoUpdaterAddon {
|
|
|
|
|
|
constructor(app) {
|
|
|
this.app = app;
|
|
|
- this.cfg = app.config.addons.autoUpdater;
|
|
|
- this.mainWindow = app.electron.mainWindow;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建
|
|
|
*/
|
|
|
create () {
|
|
|
- this.app.console.info('[addon:autoUpdater] load');
|
|
|
+ Log.info('[addon:autoUpdater] load');
|
|
|
|
|
|
- if ((is.windows() && this.cfg.windows)
|
|
|
- || (is.macOS() && this.cfg.macOS)
|
|
|
- || (is.linux() && this.cfg.linux))
|
|
|
+ const cfg = Conf.getValue('addons.autoUpdater');
|
|
|
+ if ((is.windows() && cfg.windows)
|
|
|
+ || (is.macOS() && cfg.macOS)
|
|
|
+ || (is.linux() && cfg.linux))
|
|
|
{
|
|
|
// continue
|
|
|
} else {
|
|
|
@@ -31,7 +33,7 @@ class AutoUpdaterAddon {
|
|
|
}
|
|
|
|
|
|
// 是否检查更新
|
|
|
- if (this.cfg.force) {
|
|
|
+ if (cfg.force) {
|
|
|
this.checkUpdate();
|
|
|
}
|
|
|
|
|
|
@@ -43,22 +45,21 @@ class AutoUpdaterAddon {
|
|
|
downloaded: 4,
|
|
|
}
|
|
|
|
|
|
- const updateConfig = this.cfg;
|
|
|
const version = app.getVersion();
|
|
|
Log.info('[addon:autoUpdater] current version: ', version);
|
|
|
|
|
|
// 设置下载服务器地址
|
|
|
- let server = updateConfig.options.url;
|
|
|
+ let server = cfg.options.url;
|
|
|
let lastChar = server.substring(server.length - 1);
|
|
|
server = lastChar === '/' ? server : server + "/";
|
|
|
//Log.info('[addon:autoUpdater] server: ', server);
|
|
|
- updateConfig.options.url = server;
|
|
|
+ cfg.options.url = server;
|
|
|
|
|
|
// 是否后台自动下载
|
|
|
- autoUpdater.autoDownload = updateConfig.force ? true : false;
|
|
|
+ autoUpdater.autoDownload = cfg.force ? true : false;
|
|
|
|
|
|
try {
|
|
|
- autoUpdater.setFeedURL(updateConfig.options);
|
|
|
+ autoUpdater.setFeedURL(cfg.options);
|
|
|
} catch (error) {
|
|
|
Log.error('[addon:autoUpdater] setFeedURL error : ', error);
|
|
|
}
|
|
|
@@ -105,7 +106,7 @@ class AutoUpdaterAddon {
|
|
|
info.desc = '下载完成';
|
|
|
this.sendStatusToWindow(info);
|
|
|
// quit and update
|
|
|
- this.app.appQuit();
|
|
|
+ EE.app.appQuit();
|
|
|
autoUpdater.quitAndInstall();
|
|
|
});
|
|
|
}
|
|
|
@@ -130,7 +131,7 @@ class AutoUpdaterAddon {
|
|
|
sendStatusToWindow(content = {}) {
|
|
|
const textJson = JSON.stringify(content);
|
|
|
const channel = 'app.updater';
|
|
|
- this.mainWindow.webContents.send(channel, textJson);
|
|
|
+ Electron.mainWindow.webContents.send(channel, textJson);
|
|
|
}
|
|
|
|
|
|
/**
|