Retry updater when in-call app close is cancelled
This commit is contained in:
parent
ab1ae26489
commit
9d2a043191
6 changed files with 50 additions and 7 deletions
|
@ -871,6 +871,7 @@ async function createWindow() {
|
|||
);
|
||||
}
|
||||
if (!shouldClose) {
|
||||
updater.onRestartCancelled();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@ export function markShouldQuit(): void {
|
|||
shouldQuitFlag = true;
|
||||
}
|
||||
|
||||
export function markShouldNotQuit(): void {
|
||||
shouldQuitFlag = false;
|
||||
}
|
||||
|
||||
export function shouldQuit(): boolean {
|
||||
return shouldQuitFlag;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import { app, ipcMain } from 'electron';
|
|||
|
||||
import * as durations from '../util/durations';
|
||||
import { getTempPath, getUpdateCachePath } from '../../app/attachments';
|
||||
import { markShouldNotQuit, markShouldQuit } from '../../app/window_state';
|
||||
import { DialogType } from '../types/Dialogs';
|
||||
import * as Errors from '../types/errors';
|
||||
import { isAlpha, isBeta, isStaging } from '../util/version';
|
||||
|
@ -117,6 +118,8 @@ export abstract class Updater {
|
|||
|
||||
private markedCannotUpdate = false;
|
||||
|
||||
private restarting = false;
|
||||
|
||||
private readonly canRunSilently: () => boolean;
|
||||
|
||||
constructor({
|
||||
|
@ -148,6 +151,26 @@ export abstract class Updater {
|
|||
return this.checkForUpdatesMaybeInstall(true);
|
||||
}
|
||||
|
||||
// If the updater was about to restart the app but the user cancelled it, show dialog
|
||||
// to let them retry the restart
|
||||
public onRestartCancelled(): void {
|
||||
if (!this.restarting) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.info(
|
||||
'updater/onRestartCancelled: restart was cancelled. showing update dialog.'
|
||||
);
|
||||
this.restarting = false;
|
||||
markShouldNotQuit();
|
||||
|
||||
const mainWindow = this.getMainWindow();
|
||||
mainWindow?.webContents.send(
|
||||
'show-update-dialog',
|
||||
DialogType.DownloadedUpdate
|
||||
);
|
||||
}
|
||||
|
||||
public async start(): Promise<void> {
|
||||
this.logger.info('updater/start: starting checks...');
|
||||
|
||||
|
@ -173,7 +196,7 @@ export abstract class Updater {
|
|||
//
|
||||
|
||||
protected setUpdateListener(
|
||||
performUpdateCallback: () => Promise<void>
|
||||
performUpdateCallback: () => Promise<void> | void
|
||||
): void {
|
||||
ipcMain.removeHandler('start-update');
|
||||
ipcMain.handleOnce('start-update', performUpdateCallback);
|
||||
|
@ -209,6 +232,11 @@ export abstract class Updater {
|
|||
});
|
||||
}
|
||||
|
||||
protected markRestarting(): void {
|
||||
this.restarting = true;
|
||||
markShouldQuit();
|
||||
}
|
||||
|
||||
//
|
||||
// Private methods
|
||||
//
|
||||
|
|
|
@ -64,6 +64,12 @@ export async function force(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
export function onRestartCancelled(): void {
|
||||
if (updater) {
|
||||
updater.onRestartCancelled();
|
||||
}
|
||||
}
|
||||
|
||||
function autoUpdateDisabled() {
|
||||
return (
|
||||
process.platform === 'linux' || process.mas || !config.get('updatesEnabled')
|
||||
|
|
|
@ -9,7 +9,6 @@ import { join } from 'path';
|
|||
import { Updater, createTempDir, deleteTempDir } from './common';
|
||||
import { explodePromise } from '../util/explodePromise';
|
||||
import * as Errors from '../types/errors';
|
||||
import { markShouldQuit } from '../../app/window_state';
|
||||
import { DialogType } from '../types/Dialogs';
|
||||
|
||||
export class MacOSUpdater extends Updater {
|
||||
|
@ -41,7 +40,7 @@ export class MacOSUpdater extends Updater {
|
|||
|
||||
this.setUpdateListener(async () => {
|
||||
logger.info('downloadAndInstall: restarting...');
|
||||
markShouldQuit();
|
||||
this.markRestarting();
|
||||
autoUpdater.quitAndInstall();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import { app } from 'electron';
|
|||
import pify from 'pify';
|
||||
|
||||
import { Updater } from './common';
|
||||
import { markShouldQuit } from '../../app/window_state';
|
||||
|
||||
const readdir = pify(readdirCallback);
|
||||
const unlink = pify(unlinkCallback);
|
||||
|
@ -61,9 +60,9 @@ export class WindowsUpdater extends Updater {
|
|||
throw error;
|
||||
}
|
||||
|
||||
logger.info('downloadAndInstall: restarting...');
|
||||
markShouldQuit();
|
||||
app.quit();
|
||||
// If interrupted at this point, we only want to restart (not reattempt install)
|
||||
this.setUpdateListener(this.restart);
|
||||
this.restart();
|
||||
};
|
||||
|
||||
if (isSilent) {
|
||||
|
@ -75,6 +74,12 @@ export class WindowsUpdater extends Updater {
|
|||
this.setUpdateListener(doInstall);
|
||||
}
|
||||
|
||||
protected restart(): void {
|
||||
this.logger.info('downloadAndInstall: restarting...');
|
||||
this.markRestarting();
|
||||
app.quit();
|
||||
}
|
||||
|
||||
private async install(filePath: string, isSilent: boolean): Promise<void> {
|
||||
if (this.installing) {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue