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');
|
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-10-23 17:44:05 +00:00
|
|
|
return process.platform === 'linux' || process.mas || config.get('disableAutoUpdate');
|
2017-06-09 19:37:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkForUpdates() {
|
|
|
|
autoUpdater.checkForUpdates();
|
|
|
|
}
|
|
|
|
|
2017-07-21 19:07:37 +00:00
|
|
|
var showingDialog = false;
|
2017-11-21 23:23:18 +00:00
|
|
|
function showUpdateDialog(mainWindow, messages) {
|
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: [
|
2017-07-25 18:40:23 +00:00
|
|
|
messages.autoUpdateRestartButtonLabel.message,
|
|
|
|
messages.autoUpdateLaterButtonLabel.message
|
2017-06-22 01:13:36 +00:00
|
|
|
],
|
2017-07-25 18:40:23 +00:00
|
|
|
title: messages.autoUpdateNewVersionTitle.message,
|
|
|
|
message: messages.autoUpdateNewVersionMessage.message,
|
|
|
|
detail: messages.autoUpdateNewVersionInstructions.message,
|
2017-06-22 01:13:36 +00:00
|
|
|
defaultId: RESTART_BUTTON,
|
|
|
|
cancelId: LATER_BUTTON
|
2017-06-09 19:37:01 +00:00
|
|
|
}
|
2017-06-22 01:13:36 +00:00
|
|
|
|
2017-11-21 23:23:18 +00:00
|
|
|
dialog.showMessageBox(mainWindow, options, function(response) {
|
2017-06-22 01:13:36 +00:00
|
|
|
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-11-21 23:23:18 +00:00
|
|
|
function initialize(getMainWindow, messages) {
|
2017-07-25 18:40:23 +00:00
|
|
|
if (!messages) {
|
|
|
|
throw new Error('auto-update initialize needs localized messages');
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:04:19 +00:00
|
|
|
if (autoUpdateDisabled()) {
|
2017-06-09 19:37:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-25 18:40:23 +00:00
|
|
|
autoUpdater.addListener('update-downloaded', function() {
|
2017-11-21 23:23:18 +00:00
|
|
|
showUpdateDialog(getMainWindow(), messages);
|
2017-07-25 18:40:23 +00:00
|
|
|
});
|
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
|
|
|
};
|