diff --git a/electron/config.js b/electron/config.js index a251916..0c40c80 100644 --- a/electron/config.js +++ b/electron/config.js @@ -52,12 +52,14 @@ const config = { workers: 1 }, autoUpdate: { - windows: false, // windows可以开启;macOs 需要签名验证 + force: false, // 强制更新 + autoDownload: false, // 是否自动下载 + windows: true, // windows可以开启;macOs 需要签名验证 macOS: false, linux: false, options: { provider: 'generic', // or github, s3, bintray - url: 'http://kodo.qiniu.com/' // resource dir, end with '/' + url: 'https://kaka996.coding.net/p/resource/d/tx-resource2/git/raw/master/ee' // resource dir, end with '/' } }, awakeProtocol: { diff --git a/electron/ipc/example.js b/electron/ipc/example.js index fcf4faa..73362fb 100644 --- a/electron/ipc/example.js +++ b/electron/ipc/example.js @@ -12,15 +12,17 @@ const {app, dialog, BrowserWindow, BrowserView, Notification, powerMonitor, screen, nativeTheme} = require('electron'); const path = require('path'); const _ = require('lodash'); +const is = require('electron-is'); +const config = require('../config'); let myTimer = null; let browserViewObj = null; let notificationObj = null; -exports.hello = function (event, channel, msg) { - let newMsg = msg + " +1" +exports.hello = function (event, channel, arg) { + let newMsg = arg + " +1" let reply = '' - reply = '收到:' + msg + ',返回:' + newMsg + reply = '收到:' + arg + ',返回:' + newMsg return reply } @@ -303,4 +305,18 @@ exports.setTheme = function (event, channel, arg) { nativeTheme.themeSource = arg; return arg; +} + +/** + * 检查是否有新版本 + */ +exports.checkForUpdater = 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.checkUpdate(); + } + + return; } \ No newline at end of file diff --git a/electron/lib/autoUpdater.js b/electron/lib/autoUpdater.js index 848300b..47abd75 100644 --- a/electron/lib/autoUpdater.js +++ b/electron/lib/autoUpdater.js @@ -14,14 +14,18 @@ exports.setup = function () { console.log('[electron-lib-autoUpater] [setup]'); const version = app.getVersion(); eLogger.info('[autoUpdater] [setup] current version: ', version); - const platformObj = helper.getPlatform(); + // 设置下载服务器地址 const updateConfig = config.get('autoUpdate'); let server = updateConfig.options.url; - server = `${server}${platformObj.platform}/`; + let lastChar = server.substring(server.length - 1); + server = lastChar === '/' ? server : server + "/"; eLogger.info('[autoUpdater] [setup] server: ', server); updateConfig.options.url = server; + // 是否自动下载 + autoUpdater.autoDownload = updateConfig.force ? true : false; + try { autoUpdater.setFeedURL(updateConfig.options); } catch (error) { @@ -29,39 +33,41 @@ exports.setup = function () { } autoUpdater.on('checking-for-update', () => { - sendStatusToWindow('Checking for update...'); + sendStatusToWindow('正在检查更新...'); }) autoUpdater.on('update-available', (info) => { - sendStatusToWindow('Update available.'); + sendStatusToWindow('有可用更新'); }) autoUpdater.on('update-not-available', (info) => { - sendStatusToWindow('Update not available.'); + sendStatusToWindow('没有可用更新'); }) autoUpdater.on('error', (err) => { - sendStatusToWindow('Error in auto-updater. ' + err); + sendStatusToWindow('更新异常: ' + err); }) autoUpdater.on('download-progress', (progressObj) => { - let log_message = "Download speed: " + progressObj.bytesPerSecond; - log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'; + let log_message = "下载进度: " + progressObj.bytesPerSecond; + log_message = log_message + ' - 已下载 ' + progressObj.percent + '%'; log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')'; sendStatusToWindow(log_message); }) autoUpdater.on('update-downloaded', (info) => { - sendStatusToWindow('Update downloaded'); + sendStatusToWindow('下载完成'); // quit and update - helper.appQuit(); - autoUpdater.quitAndInstall(); + if (updateConfig.force) { + helper.appQuit(); + autoUpdater.quitAndInstall(); + } }); }; exports.checkUpdate = function () { - autoUpdater.checkForUpdatesAndNotify(); + autoUpdater.checkForUpdates(); } function sendStatusToWindow(text) { eLogger.info(text); - MAIN_WINDOW.webContents.send('message', text); + MAIN_WINDOW.webContents.send('public.message', text); } exports = module.exports; \ No newline at end of file diff --git a/electron/preferences.js b/electron/preferences.js index 3fff6f1..400dec3 100644 --- a/electron/preferences.js +++ b/electron/preferences.js @@ -26,9 +26,11 @@ module.exports = async () => { // check update 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(); + if (updateConfig.force) { + if ((is.windows() && updateConfig.windows) || (is.macOS() && updateConfig.macOS) + || (is.linux() && updateConfig.linux)) { + const autoUpdater = require('./lib/autoUpdater'); + autoUpdater.checkUpdate(); + } } } diff --git a/frontend/src/App.vue b/frontend/src/App.vue index e904022..e7c360a 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -12,7 +12,19 @@ export default { return {}; }, watch: {}, - methods: {} + mounted () { + // 初始化一个公共消息通信频道 + this.initIpc(); + }, + methods: { + initIpc () { + const self = this; + self.$ipc.on('public.message', (event, result) => { + // 使用ant-desing-vue, message组件 + self.$message.info(result); + }) + }, + } }