Electron App: fix autoUpdater to actually install on quit (#551)
- call quitAndInstall() if an update is available - support updating prerelease versions to other prerelease versions - deps: update electron-builder to 27.0.0 alpha 7 - bump to 2.5.2
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
app,
|
||||
session,
|
||||
BrowserWindow,
|
||||
type Event,
|
||||
ipcMain,
|
||||
protocol,
|
||||
screen,
|
||||
@@ -60,6 +61,8 @@ class ElectronReplayApp {
|
||||
|
||||
origUA: string | null = null;
|
||||
|
||||
hasAutoUpdate = false;
|
||||
|
||||
constructor({ staticPath = "./", profileName = "" } = {}) {
|
||||
this.staticContentPath = staticPath;
|
||||
this.profileName = profileName;
|
||||
@@ -153,19 +156,54 @@ class ElectronReplayApp {
|
||||
void app.whenReady().then(() => this.onAppReady());
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on("window-all-closed", function () {
|
||||
app.on("window-all-closed", () => {
|
||||
// On macOS it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
//if (process.platform !== 'darwin')
|
||||
app.quit();
|
||||
});
|
||||
|
||||
let isUpdating = false;
|
||||
|
||||
app.on("before-quit", (event: Event) => {
|
||||
if (isUpdating) {
|
||||
console.log("app before-quit: already installing update");
|
||||
return;
|
||||
}
|
||||
|
||||
//install the autoupdate and let autoUpdater exit
|
||||
if (this.hasAutoUpdate) {
|
||||
event.preventDefault();
|
||||
isUpdating = true;
|
||||
|
||||
console.log("app before-quit: install update and quit");
|
||||
|
||||
setImmediate(() => {
|
||||
autoUpdater.quitAndInstall();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
checkUpdates() {
|
||||
const version = app.getVersion();
|
||||
const isPrerelease = /-(alpha|beta|rc)/i.test(version);
|
||||
|
||||
console.log(`Current Version: ${version} - Prerelease? ${isPrerelease}`);
|
||||
|
||||
if (isPrerelease) {
|
||||
autoUpdater.allowPrerelease = true;
|
||||
}
|
||||
|
||||
autoUpdater.logger = log;
|
||||
// @ts-expect-error - TS2339 - Property 'transports' does not exist on type 'Logger'.
|
||||
autoUpdater.logger.transports.file.level = "info";
|
||||
void autoUpdater.checkForUpdatesAndNotify();
|
||||
|
||||
autoUpdater.on("update-downloaded", () => {
|
||||
console.log("autoupdater found update!");
|
||||
this.hasAutoUpdate = true;
|
||||
});
|
||||
}
|
||||
|
||||
onAppReady() {
|
||||
|
||||
Reference in New Issue
Block a user