mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-14 11:52:07 +08:00
1
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ out/
|
|||||||
logs/
|
logs/
|
||||||
run/
|
run/
|
||||||
.idea/
|
.idea/
|
||||||
|
package-lock.json
|
||||||
|
|||||||
@@ -1,50 +1,50 @@
|
|||||||
'use strict';
|
// 'use strict';
|
||||||
|
|
||||||
const updater = require("electron-updater");
|
// const updater = require("electron-updater");
|
||||||
const autoUpdater = updater.autoUpdater;
|
// const autoUpdater = updater.autoUpdater;
|
||||||
const config = require('./config');
|
// const config = require('./config');
|
||||||
const path = require('path');
|
// const path = require('path');
|
||||||
const {app} = require('electron');
|
// const {app} = require('electron');
|
||||||
|
|
||||||
exports.setup = function () {
|
// exports.setup = function () {
|
||||||
const pkgInfo = require(path.join(app.getAppPath(), 'package.json'));
|
// const pkgInfo = require(path.join(app.getAppPath(), 'package.json'));
|
||||||
ELog.info('[autoUpdater] [setup] current version: ', pkgInfo.version);
|
// ELog.info('[autoUpdater] [setup] current version: ', pkgInfo.version);
|
||||||
const updateConfig = config.get('autoUpdate');
|
// const updateConfig = config.get('autoUpdate');
|
||||||
autoUpdater.setFeedURL(updateConfig.options);
|
// autoUpdater.setFeedURL(updateConfig.options);
|
||||||
|
|
||||||
autoUpdater.on('checking-for-update', () => {
|
// autoUpdater.on('checking-for-update', () => {
|
||||||
sendStatusToWindow('Checking for update...');
|
// sendStatusToWindow('Checking for update...');
|
||||||
})
|
// })
|
||||||
autoUpdater.on('update-available', (info) => {
|
// autoUpdater.on('update-available', (info) => {
|
||||||
sendStatusToWindow('Update available.');
|
// sendStatusToWindow('Update available.');
|
||||||
})
|
// })
|
||||||
autoUpdater.on('update-not-available', (info) => {
|
// autoUpdater.on('update-not-available', (info) => {
|
||||||
sendStatusToWindow('Update not available.');
|
// sendStatusToWindow('Update not available.');
|
||||||
})
|
// })
|
||||||
autoUpdater.on('error', (err) => {
|
// autoUpdater.on('error', (err) => {
|
||||||
sendStatusToWindow('Error in auto-updater. ' + err);
|
// sendStatusToWindow('Error in auto-updater. ' + err);
|
||||||
})
|
// })
|
||||||
autoUpdater.on('download-progress', (progressObj) => {
|
// autoUpdater.on('download-progress', (progressObj) => {
|
||||||
let log_message = "Download speed: " + progressObj.bytesPerSecond;
|
// let log_message = "Download speed: " + progressObj.bytesPerSecond;
|
||||||
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
|
// log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
|
||||||
log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
|
// log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
|
||||||
sendStatusToWindow(log_message);
|
// sendStatusToWindow(log_message);
|
||||||
})
|
// })
|
||||||
autoUpdater.on('update-downloaded', (info) => {
|
// autoUpdater.on('update-downloaded', (info) => {
|
||||||
sendStatusToWindow('Update downloaded');
|
// sendStatusToWindow('Update downloaded');
|
||||||
// quit and update
|
// // quit and update
|
||||||
autoUpdater.quitAndInstall();
|
// autoUpdater.quitAndInstall();
|
||||||
});
|
// });
|
||||||
|
|
||||||
};
|
// };
|
||||||
|
|
||||||
exports.checkUpdate = function () {
|
// exports.checkUpdate = function () {
|
||||||
autoUpdater.checkForUpdatesAndNotify();
|
// autoUpdater.checkForUpdatesAndNotify();
|
||||||
}
|
// }
|
||||||
|
|
||||||
function sendStatusToWindow(text) {
|
// function sendStatusToWindow(text) {
|
||||||
ELog.info(text);
|
// ELog.info(text);
|
||||||
MAIN_WINDOW.webContents.send('message', text);
|
// MAIN_WINDOW.webContents.send('message', text);
|
||||||
}
|
// }
|
||||||
|
|
||||||
exports = module.exports;
|
// exports = module.exports;
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
global.ELog = require('electron-log');
|
global.ELog = require('electron-log');
|
||||||
const storage = require('./storage');
|
const storage = require('./storage');
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const autoUpdater = require('./autoUpdater');
|
// const autoUpdater = require('./autoUpdater');
|
||||||
const api = require('./api');
|
const api = require('./api');
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
storage.setup();
|
storage.setup();
|
||||||
logger();
|
logger();
|
||||||
autoUpdater.setup();
|
// autoUpdater.setup();
|
||||||
api.setup();
|
api.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
main.js
5
main.js
@@ -4,7 +4,7 @@ const eggLauncher = require('./electron/lanucher')
|
|||||||
const setup = require('./electron/setup')
|
const setup = require('./electron/setup')
|
||||||
const electronConfig = require('./electron/config')
|
const electronConfig = require('./electron/config')
|
||||||
const storage = require('./electron/storage')
|
const storage = require('./electron/storage')
|
||||||
const autoUpdater = require('./electron/autoUpdater')
|
// const autoUpdater = require('./electron/autoUpdater')
|
||||||
|
|
||||||
// main window
|
// main window
|
||||||
global.MAIN_WINDOW = null
|
global.MAIN_WINDOW = null
|
||||||
@@ -77,7 +77,8 @@ async function createWindow () {
|
|||||||
// check update
|
// check update
|
||||||
const updateConfig = electronConfig.get('autoUpdate')
|
const updateConfig = electronConfig.get('autoUpdate')
|
||||||
if (updateConfig.enable) {
|
if (updateConfig.enable) {
|
||||||
autoUpdater.checkUpdate()
|
// windows可以开启;macOs 需要签名验证
|
||||||
|
//autoUpdater.checkUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
return MAIN_WINDOW
|
return MAIN_WINDOW
|
||||||
|
|||||||
@@ -109,7 +109,6 @@
|
|||||||
"egg-view-ejs": "^2.0.0",
|
"egg-view-ejs": "^2.0.0",
|
||||||
"electron-is": "^3.0.0",
|
"electron-is": "^3.0.0",
|
||||||
"electron-log": "^4.2.2",
|
"electron-log": "^4.2.2",
|
||||||
"electron-updater": "^4.3.5",
|
|
||||||
"get-port": "^5.1.1",
|
"get-port": "^5.1.1",
|
||||||
"glob": "^7.1.6",
|
"glob": "^7.1.6",
|
||||||
"lodash": "^4.17.11",
|
"lodash": "^4.17.11",
|
||||||
|
|||||||
Reference in New Issue
Block a user