diff --git a/emain/emain.ts b/emain/emain.ts index 25f401073..af989f460 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -731,6 +731,7 @@ electronApp.on("window-all-closed", () => { }); electronApp.on("before-quit", () => { globalIsQuitting = true; + updater?.installUpdate(); }); process.on("SIGINT", () => { console.log("Caught SIGINT, shutting down"); diff --git a/emain/updater.ts b/emain/updater.ts index b2ea1f2de..a8bacf5a7 100644 --- a/emain/updater.ts +++ b/emain/updater.ts @@ -47,7 +47,7 @@ export class Updater { body: "A new version of Wave Terminal is ready to install.", }); updateNotification.on("click", () => { - fireAndForget(() => this.installAppUpdate()); + fireAndForget(() => this.promptToInstallUpdate()); }); updateNotification.show(); }); @@ -130,7 +130,7 @@ export class Updater { /** * Prompts the user to install the downloaded application update and restarts the application */ - async installAppUpdate() { + async promptToInstallUpdate() { const dialogOpts: Electron.MessageBoxOptions = { type: "info", buttons: ["Restart", "Later"], @@ -145,15 +145,24 @@ export class Updater { .showMessageBox(electron.BrowserWindow.getFocusedWindow() ?? allWindows[0], dialogOpts) .then(({ response }) => { if (response === 0) { - this.status = "installing"; - autoUpdater.quitAndInstall(); + this.installUpdate(); } }); } } + + /** + * Restarts the app and installs an update if it is available. + */ + installUpdate() { + if (this.status == "ready") { + this.status = "installing"; + autoUpdater.quitAndInstall(); + } + } } -electron.ipcMain.on("install-app-update", () => fireAndForget(() => updater?.installAppUpdate())); +electron.ipcMain.on("install-app-update", () => fireAndForget(() => updater?.promptToInstallUpdate())); electron.ipcMain.on("get-app-update-status", (event) => { event.returnValue = updater?.status; }); diff --git a/frontend/app/store/global.ts b/frontend/app/store/global.ts index 94d8f4267..0b2bc916b 100644 --- a/frontend/app/store/global.ts +++ b/frontend/app/store/global.ts @@ -106,6 +106,7 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) { const cmdShiftDelayAtom = jotai.atom(false); const updateStatusAtom = jotai.atom("up-to-date") as jotai.PrimitiveAtom; try { + globalStore.set(updateStatusAtom, getApi().getUpdaterStatus()); getApi().onUpdaterStatusChange((status) => { console.log("updater status change", status); globalStore.set(updateStatusAtom, status);