Retry updater when in-call app close is cancelled

This commit is contained in:
ayumi-signal 2024-02-26 16:18:50 -08:00 committed by GitHub
parent ab1ae26489
commit 9d2a043191
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 50 additions and 7 deletions

View file

@ -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
//