fix check for updates, ensure quitAndInstall is not interrupted

This commit is contained in:
Evan Simkowitz 2024-08-06 15:13:59 -07:00
parent 7420044f2f
commit 335ab6d55d
No known key found for this signature in database
3 changed files with 16 additions and 12 deletions

View File

@ -153,7 +153,7 @@ function runWaveSrv(): Promise<boolean> {
env: envCopy, env: envCopy,
}); });
proc.on("exit", (e) => { proc.on("exit", (e) => {
if (globalIsQuitting) { if (globalIsQuitting || updater?.status == "installing") {
return; return;
} }
console.log("wavesrv exited, shutting down"); console.log("wavesrv exited, shutting down");
@ -412,7 +412,7 @@ function createBrowserWindow(
win.webContents.send("fullscreen-change", false); win.webContents.send("fullscreen-change", false);
}); });
win.on("close", (e) => { win.on("close", (e) => {
if (globalIsQuitting) { if (globalIsQuitting || updater?.status == "installing") {
return; return;
} }
const choice = electron.dialog.showMessageBoxSync(win, { const choice = electron.dialog.showMessageBoxSync(win, {
@ -426,7 +426,7 @@ function createBrowserWindow(
} }
}); });
win.on("closed", () => { win.on("closed", () => {
if (globalIsQuitting) { if (globalIsQuitting || updater?.status == "installing") {
return; return;
} }
services.WindowService.CloseWindow(waveWindow.oid); services.WindowService.CloseWindow(waveWindow.oid);
@ -623,8 +623,8 @@ function makeAppMenu() {
}, },
{ {
label: "Check for Updates", label: "Check for Updates",
click: () => { click: async () => {
fireAndForget(() => updater?.checkForUpdates(true)); await updater?.checkForUpdates(true);
}, },
}, },
{ {
@ -807,7 +807,7 @@ async function appMain() {
console.log("wavesrv ready signal received", ready, Date.now() - startTs, "ms"); console.log("wavesrv ready signal received", ready, Date.now() - startTs, "ms");
await electronApp.whenReady(); await electronApp.whenReady();
relaunchBrowserWindows(); relaunchBrowserWindows();
configureAutoUpdater(); await configureAutoUpdater();
globalIsStarting = false; globalIsStarting = false;
electronApp.on("activate", () => { electronApp.on("activate", () => {

View File

@ -4,15 +4,13 @@ import { autoUpdater } from "electron-updater";
import * as services from "../frontend/app/store/services"; import * as services from "../frontend/app/store/services";
import { fireAndForget } from "../frontend/util/util"; import { fireAndForget } from "../frontend/util/util";
let autoUpdateLock = false;
export let updater: Updater; export let updater: Updater;
export class Updater { export class Updater {
interval: NodeJS.Timeout | null; interval: NodeJS.Timeout | null;
availableUpdateReleaseName: string | null; availableUpdateReleaseName: string | null;
availableUpdateReleaseNotes: string | null; availableUpdateReleaseNotes: string | null;
_status: UpdaterStatus; private _status: UpdaterStatus;
lastUpdateCheck: Date; lastUpdateCheck: Date;
constructor() { constructor() {
@ -102,6 +100,7 @@ export class Updater {
} }
const now = new Date(); const now = new Date();
if ( if (
userInput ||
!this.lastUpdateCheck || !this.lastUpdateCheck ||
Math.abs(now.getTime() - this.lastUpdateCheck.getTime()) > autoUpdateOpts.intervalms Math.abs(now.getTime() - this.lastUpdateCheck.getTime()) > autoUpdateOpts.intervalms
) { ) {
@ -135,7 +134,10 @@ export class Updater {
await electron.dialog await electron.dialog
.showMessageBox(electron.BrowserWindow.getFocusedWindow() ?? allWindows[0], dialogOpts) .showMessageBox(electron.BrowserWindow.getFocusedWindow() ?? allWindows[0], dialogOpts)
.then(({ response }) => { .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; event.returnValue = updater?.status;
}); });
let autoUpdateLock = false;
/** /**
* Configures the auto-updater based on the user's preference * Configures the auto-updater based on the user's preference
* @param enabled Whether the auto-updater should be enabled * @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() { export async function configureAutoUpdater() {
if (isDev()) { if (isDev()) {
console.log("skipping auto-updater in dev mode"); 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 // simple lock to prevent multiple auto-update configuration attempts, this should be very rare

View File

@ -182,7 +182,7 @@ declare global {
giveFocus?: () => boolean; 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 :/ // jotai doesn't export this type :/
type Loadable<T> = { state: "loading" } | { state: "hasData"; data: T } | { state: "hasError"; error: unknown }; type Loadable<T> = { state: "loading" } | { state: "hasData"; data: T } | { state: "hasError"; error: unknown };