mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
5c5fdaaed5
This prevents the user from restarting the app by pressing space on MacOS, which happens frequently during the course of normal typing of a message. In the future we'll move to a less-obtrusive system a little more like Chrome, where you choose to do the restart when it is convenient for you. For now, we minimize the chance of accidental restart in the middle of typing a message.
81 lines
2 KiB
JavaScript
81 lines
2 KiB
JavaScript
const autoUpdater = require('electron-updater').autoUpdater
|
|
const { dialog } = require('electron');
|
|
|
|
const config = require('./config');
|
|
const windowState = require('./window_state');
|
|
|
|
const hour = 60 * 60;
|
|
const autoUpdaterInterval = hour * 1000;
|
|
|
|
const RESTART_BUTTON = 0;
|
|
const LATER_BUTTON = 1;
|
|
|
|
function autoUpdateDisabled() {
|
|
return process.platform === 'linux' || process.mas || config.get('disableAutoUpdate');
|
|
}
|
|
|
|
function checkForUpdates() {
|
|
autoUpdater.checkForUpdates();
|
|
}
|
|
|
|
var showingDialog = false;
|
|
function showUpdateDialog(mainWindow, messages) {
|
|
if (showingDialog) {
|
|
return;
|
|
}
|
|
showingDialog = true;
|
|
|
|
const options = {
|
|
type: 'info',
|
|
buttons: [
|
|
messages.autoUpdateRestartButtonLabel.message,
|
|
messages.autoUpdateLaterButtonLabel.message
|
|
],
|
|
title: messages.autoUpdateNewVersionTitle.message,
|
|
message: messages.autoUpdateNewVersionMessage.message,
|
|
detail: messages.autoUpdateNewVersionInstructions.message,
|
|
defaultId: LATER_BUTTON,
|
|
cancelId: RESTART_BUTTON,
|
|
}
|
|
|
|
dialog.showMessageBox(mainWindow, options, function(response) {
|
|
if (response == RESTART_BUTTON) {
|
|
// We delay these update calls because they don't seem to work in this
|
|
// callback - but only if the message box has a parent window.
|
|
// Fixes this bug: https://github.com/WhisperSystems/Signal-Desktop/issues/1864
|
|
setTimeout(function() {
|
|
windowState.markShouldQuit();
|
|
autoUpdater.quitAndInstall();
|
|
}, 200);
|
|
}
|
|
|
|
showingDialog = false;
|
|
});
|
|
}
|
|
|
|
function onError(error) {
|
|
console.log("Got an error while updating: ", error.stack);
|
|
}
|
|
|
|
function initialize(getMainWindow, messages) {
|
|
if (!messages) {
|
|
throw new Error('auto-update initialize needs localized messages');
|
|
}
|
|
|
|
if (autoUpdateDisabled()) {
|
|
return;
|
|
}
|
|
|
|
autoUpdater.addListener('update-downloaded', function() {
|
|
showUpdateDialog(getMainWindow(), messages);
|
|
});
|
|
autoUpdater.addListener('error', onError);
|
|
|
|
checkForUpdates();
|
|
|
|
setInterval(checkForUpdates, autoUpdaterInterval);
|
|
}
|
|
|
|
module.exports = {
|
|
initialize
|
|
};
|