Skip to content

Commit 52486d6

Browse files
committed
Allow the autoupdater to quit the app normally.
Forcing it to quit would prematurely terminate the update on some platforms. Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 73441d7 commit 52486d6

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

app/main/autoupdater.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {shell} from "electron/common";
22
import {app, dialog, session} from "electron/main";
33
import process from "node:process";
4-
import util from "node:util";
54

65
import log from "electron-log";
76
import type {UpdateDownloadedEvent, UpdateInfo} from "electron-updater";
@@ -11,7 +10,11 @@ import * as ConfigUtil from "../common/config-util";
1110

1211
import {linuxUpdateNotification} from "./linuxupdater"; // Required only in case of linux
1312

14-
const sleep = util.promisify(setTimeout);
13+
let quitting = false;
14+
15+
export function shouldQuitForUpdate(): boolean {
16+
return quitting;
17+
}
1518

1619
export async function appUpdater(updateFromMenu = false): Promise<void> {
1720
// Don't initiate auto-updates in development
@@ -104,10 +107,8 @@ Current Version: ${app.getVersion()}`,
104107
detail: "It will be installed the next time you restart the application",
105108
});
106109
if (response === 0) {
107-
await sleep(1000);
110+
quitting = true;
108111
autoUpdater.quitAndInstall();
109-
// Force app to quit. This is just a workaround, ideally autoUpdater.quitAndInstall() should relaunch the app.
110-
app.quit();
111112
}
112113
});
113114
// Init for updates

app/main/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as ConfigUtil from "../common/config-util";
1010
import type {RendererMessage} from "../common/typed-ipc";
1111
import type {MenuProps} from "../common/types";
1212

13-
import {appUpdater} from "./autoupdater";
13+
import {appUpdater, shouldQuitForUpdate} from "./autoupdater";
1414
import * as BadgeSettings from "./badge-settings";
1515
import handleExternalLink from "./handle-external-link";
1616
import * as AppMenu from "./menu";
@@ -91,7 +91,7 @@ function createMainWindow(): BrowserWindow {
9191
app.quit();
9292
}
9393

94-
if (!isQuitting) {
94+
if (!isQuitting && !shouldQuitForUpdate()) {
9595
event.preventDefault();
9696

9797
if (process.platform === "darwin") {

0 commit comments

Comments
 (0)