diff --git a/emain/emain.ts b/emain/emain.ts index b0c77329f..33be2242f 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -153,7 +153,7 @@ function runWaveSrv(): Promise { env: envCopy, }); proc.on("exit", (e) => { - if (globalIsQuitting) { + if (globalIsQuitting || updater?.status == "installing") { return; } console.log("wavesrv exited, shutting down"); @@ -412,7 +412,7 @@ function createBrowserWindow( win.webContents.send("fullscreen-change", false); }); win.on("close", (e) => { - if (globalIsQuitting) { + if (globalIsQuitting || updater?.status == "installing") { return; } const choice = electron.dialog.showMessageBoxSync(win, { @@ -426,7 +426,7 @@ function createBrowserWindow( } }); win.on("closed", () => { - if (globalIsQuitting) { + if (globalIsQuitting || updater?.status == "installing") { return; } services.WindowService.CloseWindow(waveWindow.oid); @@ -623,8 +623,8 @@ function makeAppMenu() { }, { label: "Check for Updates", - click: () => { - fireAndForget(() => updater?.checkForUpdates(true)); + click: async () => { + await updater?.checkForUpdates(true); }, }, { @@ -807,7 +807,7 @@ async function appMain() { console.log("wavesrv ready signal received", ready, Date.now() - startTs, "ms"); await electronApp.whenReady(); relaunchBrowserWindows(); - configureAutoUpdater(); + await configureAutoUpdater(); globalIsStarting = false; electronApp.on("activate", () => { diff --git a/emain/updater.ts b/emain/updater.ts index 70fcb358b..48b146c74 100644 --- a/emain/updater.ts +++ b/emain/updater.ts @@ -4,15 +4,13 @@ import { autoUpdater } from "electron-updater"; import * as services from "../frontend/app/store/services"; import { fireAndForget } from "../frontend/util/util"; -let autoUpdateLock = false; - export let updater: Updater; export class Updater { interval: NodeJS.Timeout | null; availableUpdateReleaseName: string | null; availableUpdateReleaseNotes: string | null; - _status: UpdaterStatus; + private _status: UpdaterStatus; lastUpdateCheck: Date; constructor() { @@ -102,6 +100,7 @@ export class Updater { } const now = new Date(); if ( + userInput || !this.lastUpdateCheck || Math.abs(now.getTime() - this.lastUpdateCheck.getTime()) > autoUpdateOpts.intervalms ) { @@ -135,7 +134,10 @@ export class Updater { await electron.dialog .showMessageBox(electron.BrowserWindow.getFocusedWindow() ?? allWindows[0], dialogOpts) .then(({ response }) => { - if (response === 0) autoUpdater.quitAndInstall(); + if (response === 0) { + this.status = "installing"; + autoUpdater.quitAndInstall(); + } }); } } @@ -146,6 +148,8 @@ electron.ipcMain.on("get-app-update-status", (event) => { event.returnValue = updater?.status; }); +let autoUpdateLock = false; + /** * Configures the auto-updater based on the user's preference * @param enabled Whether the auto-updater should be enabled @@ -153,7 +157,7 @@ electron.ipcMain.on("get-app-update-status", (event) => { export async function configureAutoUpdater() { if (isDev()) { console.log("skipping auto-updater in dev mode"); - return null; + return; } // simple lock to prevent multiple auto-update configuration attempts, this should be very rare diff --git a/frontend/types/custom.d.ts b/frontend/types/custom.d.ts index e26cbab2d..5eeeae710 100644 --- a/frontend/types/custom.d.ts +++ b/frontend/types/custom.d.ts @@ -182,7 +182,7 @@ declare global { giveFocus?: () => boolean; } - type UpdaterStatus = "up-to-date" | "checking" | "downloading" | "ready" | "error"; + type UpdaterStatus = "up-to-date" | "checking" | "downloading" | "ready" | "error" | "installing"; // jotai doesn't export this type :/ type Loadable = { state: "loading" } | { state: "hasData"; data: T } | { state: "hasError"; error: unknown };