2020-04-24 14:10:37 +00:00
|
|
|
const os = require('os');
|
2020-06-03 17:37:50 +00:00
|
|
|
const { dialog } = require('electron');
|
2020-04-24 14:10:37 +00:00
|
|
|
const log = require('electron-log');
|
2020-08-26 14:50:20 +00:00
|
|
|
const settings = require('electron-settings');
|
2020-06-03 17:37:50 +00:00
|
|
|
|
2020-04-24 14:10:37 +00:00
|
|
|
const { autoUpdater } = require("electron-updater");
|
|
|
|
|
|
|
|
// This logging setup is not required for auto-updates to work,
|
|
|
|
// but it sure makes debugging easier :)
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
|
|
autoUpdater.autoDownload = false
|
|
|
|
autoUpdater.logger = log;
|
|
|
|
autoUpdater.logger.transports.file.level = 'info';
|
|
|
|
log.info('App starting...');
|
|
|
|
|
|
|
|
let initialized = false;
|
|
|
|
let downloadProgress = 0;
|
|
|
|
|
|
|
|
function init(mainWindow) {
|
|
|
|
|
2020-06-03 17:37:50 +00:00
|
|
|
if(initialized) return;
|
2020-04-24 14:10:37 +00:00
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
|
|
|
|
autoUpdater.on('error', (error) => {
|
2020-05-15 16:32:35 +00:00
|
|
|
log.error(error == null ? "unknown" : (error.stack || error).toString());
|
2020-04-24 14:10:37 +00:00
|
|
|
});
|
|
|
|
|
2020-06-03 17:37:50 +00:00
|
|
|
autoUpdater.on('update-available', (info) => {
|
|
|
|
if(info.version === settings.get('release.version')) {
|
|
|
|
log.info(`Skipped version ${info.version}`);
|
|
|
|
return;
|
|
|
|
}
|
2020-04-24 14:10:37 +00:00
|
|
|
dialog.showMessageBox({
|
|
|
|
type: 'info',
|
|
|
|
title: 'Found Updates',
|
|
|
|
message: 'There is a newer version of this app available. Do you want to update now?',
|
2020-06-03 17:37:50 +00:00
|
|
|
detail: info.releaseNotes.replace(/(<([^>]+)>)/g, ""),
|
|
|
|
buttons: ['Install Update', 'Remind me later','Skip this version'],
|
2020-04-24 14:10:37 +00:00
|
|
|
cancelId:1,
|
2020-06-08 01:23:05 +00:00
|
|
|
}).then(result => {
|
2020-04-24 14:10:37 +00:00
|
|
|
if(result.response === 0){
|
|
|
|
autoUpdater.downloadUpdate();
|
|
|
|
}
|
2020-06-03 17:37:50 +00:00
|
|
|
if(result.response === 2) {
|
2020-06-08 01:23:05 +00:00
|
|
|
settings.set('release', {version: info.version });
|
2020-06-03 17:37:50 +00:00
|
|
|
}
|
2020-04-24 14:10:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
|
|
|
|
autoUpdater.logger.info("Update Downloaded...");
|
|
|
|
dialog.showMessageBox({
|
|
|
|
title: 'Install Updates',
|
2020-06-03 17:37:50 +00:00
|
|
|
message: releaseName,
|
2020-04-24 14:10:37 +00:00
|
|
|
detail: 'A new version has been downloaded. Restart the application to apply the updates.',
|
|
|
|
buttons: ['Restart', 'Cancel'],
|
|
|
|
cancelId:1,
|
|
|
|
}).then(result => {
|
|
|
|
if(result.response === 0){
|
|
|
|
autoUpdater.quitAndInstall();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.on("download-progress", (d) => {
|
|
|
|
downloadProgress = d.percent;
|
|
|
|
autoUpdater.logger.info(downloadProgress);
|
|
|
|
});
|
|
|
|
|
|
|
|
autoUpdater.checkForUpdates();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init,
|
|
|
|
};
|