2017-06-09 19:37:01 +00:00
|
|
|
const autoUpdater = require('electron-updater').autoUpdater
|
|
|
|
const { dialog } = require('electron');
|
|
|
|
|
2017-06-22 00:26:05 +00:00
|
|
|
const windowState = require('./window_state');
|
|
|
|
|
2017-06-09 19:37:01 +00:00
|
|
|
const hour = 60 * 60;
|
|
|
|
const autoUpdaterInterval = hour * 1000;
|
|
|
|
|
|
|
|
const RESTART_BUTTON = 0;
|
|
|
|
const LATER_BUTTON = 1;
|
|
|
|
|
|
|
|
function autoUpdateDisabled(config) {
|
|
|
|
return process.mas || config.get('disableAutoUpdate');
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkForUpdates() {
|
|
|
|
autoUpdater.checkForUpdates();
|
|
|
|
}
|
|
|
|
|
|
|
|
function showUpdateDialog(localeMessages) {
|
|
|
|
return function() {
|
|
|
|
const options = {
|
|
|
|
type: 'info',
|
|
|
|
buttons: [
|
|
|
|
localeMessages.autoUpdateRestartButtonLabel.message,
|
|
|
|
localeMessages.autoUpdateLaterButtonLabel.message
|
|
|
|
],
|
|
|
|
title: localeMessages.autoUpdateNewVersionTitle.message,
|
|
|
|
message: localeMessages.autoUpdateNewVersionMessage.message,
|
|
|
|
detail: localeMessages.autoUpdateNewVersionInstructions.message,
|
|
|
|
defaultId: RESTART_BUTTON,
|
|
|
|
cancelId: LATER_BUTTON
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.showMessageBox(options, function(response) {
|
|
|
|
if (response == RESTART_BUTTON) {
|
2017-06-22 00:26:05 +00:00
|
|
|
windowState.markShouldQuit();
|
2017-06-09 19:37:01 +00:00
|
|
|
autoUpdater.quitAndInstall();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onError(error) {
|
|
|
|
console.log("Got an error while updating: ", error.stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
function initializeAutoUpdater(config, localeMessages) {
|
|
|
|
if (autoUpdateDisabled(config)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const onUpdateDownloaded = showUpdateDialog(localeMessages);
|
|
|
|
|
|
|
|
autoUpdater.addListener('update-downloaded', onUpdateDownloaded);
|
|
|
|
autoUpdater.addListener('error', onError);
|
|
|
|
|
|
|
|
checkForUpdates();
|
|
|
|
|
|
|
|
setInterval(checkForUpdates, autoUpdaterInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
initializeAutoUpdater
|
|
|
|
};
|