From 7647d11a1ad47d86d98241bf59e900e0498a21a0 Mon Sep 17 00:00:00 2001 From: wallace5303 <530353222@qq.com> Date: Wed, 3 Feb 2021 14:21:25 +0800 Subject: [PATCH] 1.7.0 --- electron/autoUpdater.js | 86 ++++++++++++++++++++--------------------- electron/config.js | 4 +- electron/setup.js | 9 ++++- main.js | 11 +++--- package.json | 2 +- 5 files changed, 60 insertions(+), 52 deletions(-) diff --git a/electron/autoUpdater.js b/electron/autoUpdater.js index fba0c00..96e6f2a 100644 --- a/electron/autoUpdater.js +++ b/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; \ No newline at end of file +exports = module.exports; \ No newline at end of file diff --git a/electron/config.js b/electron/config.js index e3569bd..4896a06 100644 --- a/electron/config.js +++ b/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 diff --git a/electron/setup.js b/electron/setup.js index 7a28170..8382f32 100644 --- a/electron/setup.js +++ b/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(); } diff --git a/main.js b/main.js index 708c347..c89ee02 100644 --- a/main.js +++ b/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 diff --git a/package.json b/package.json index 364446d..824d04e 100755 --- a/package.json +++ b/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": {