2017-06-09 19:37:01 +00:00
|
|
|
const autoUpdater = require('electron-updater').autoUpdater
|
|
|
|
const { dialog } = require('electron');
|
|
|
|
|
2017-06-22 01:13:36 +00:00
|
|
|
const config = require('./config');
|
|
|
|
const locale = require('./locale');
|
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;
|
|
|
|
|
2017-06-22 01:04:19 +00:00
|
|
|
function autoUpdateDisabled() {
|
2017-06-09 19:37:01 +00:00
|
|
|
return process.mas || config.get('disableAutoUpdate');
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkForUpdates() {
|
|
|
|
autoUpdater.checkForUpdates();
|
|
|
|
}
|
|
|
|
|
2017-07-21 19:07:37 +00:00
|
|
|
var showingDialog = false;
|
2017-06-22 01:13:36 +00:00
|
|
|
function showUpdateDialog() {
|
2017-07-21 19:07:37 +00:00
|
|
|
if (showingDialog) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
showingDialog = true;
|
|
|
|
|
2017-06-22 01:13:36 +00:00
|
|
|
const options = {
|
|
|
|
type: 'info',
|
|
|
|
buttons: [
|
|
|
|
locale.messages.autoUpdateRestartButtonLabel.message,
|
|
|
|
locale.messages.autoUpdateLaterButtonLabel.message
|
|
|
|
],
|
|
|
|
title: locale.messages.autoUpdateNewVersionTitle.message,
|
|
|
|
message: locale.messages.autoUpdateNewVersionMessage.message,
|
|
|
|
detail: locale.messages.autoUpdateNewVersionInstructions.message,
|
|
|
|
defaultId: RESTART_BUTTON,
|
|
|
|
cancelId: LATER_BUTTON
|
2017-06-09 19:37:01 +00:00
|
|
|
}
|
2017-06-22 01:13:36 +00:00
|
|
|
|
|
|
|
dialog.showMessageBox(options, function(response) {
|
|
|
|
if (response == RESTART_BUTTON) {
|
|
|
|
windowState.markShouldQuit();
|
|
|
|
autoUpdater.quitAndInstall();
|
|
|
|
}
|
2017-07-21 19:07:37 +00:00
|
|
|
|
|
|
|
showingDialog = false;
|
2017-06-22 01:13:36 +00:00
|
|
|
});
|
2017-06-09 19:37:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onError(error) {
|
|
|
|
console.log("Got an error while updating: ", error.stack);
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:15:15 +00:00
|
|
|
function initialize() {
|
2017-06-22 01:04:19 +00:00
|
|
|
if (autoUpdateDisabled()) {
|
2017-06-09 19:37:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:13:36 +00:00
|
|
|
autoUpdater.addListener('update-downloaded', showUpdateDialog);
|
2017-06-09 19:37:01 +00:00
|
|
|
autoUpdater.addListener('error', onError);
|
|
|
|
|
|
|
|
checkForUpdates();
|
|
|
|
|
|
|
|
setInterval(checkForUpdates, autoUpdaterInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2017-06-22 01:15:15 +00:00
|
|
|
initialize
|
2017-06-09 19:37:01 +00:00
|
|
|
};
|