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,
});
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", () => {

View File

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

View File

@ -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<T> = { state: "loading" } | { state: "hasData"; data: T } | { state: "hasError"; error: unknown };