get update status on start, install update on quit

This commit is contained in:
Evan Simkowitz 2024-08-06 16:19:55 -07:00
parent 5f229048be
commit 61f02b27d2
No known key found for this signature in database
3 changed files with 16 additions and 5 deletions

View File

@ -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");

View File

@ -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;
});

View File

@ -106,6 +106,7 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) {
const cmdShiftDelayAtom = jotai.atom(false);
const updateStatusAtom = jotai.atom<UpdaterStatus>("up-to-date") as jotai.PrimitiveAtom<UpdaterStatus>;
try {
globalStore.set(updateStatusAtom, getApi().getUpdaterStatus());
getApi().onUpdaterStatusChange((status) => {
console.log("updater status change", status);
globalStore.set(updateStatusAtom, status);