fix(desktop): stop the updater button flickering after download (#2089)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-29 17:44:43 +02:00
1 parent 96c5db3f5d
commit 9b8659a40b
3 files changed
+60 -1

No files matched your search

+23 -1
View File
@@ -308,6 +308,8 @@ function registerVelopackUpdater(getMainWindow: () => BrowserWindow | null): voi
function registerElectronUpdater(getMainWindow: () => BrowserWindow | null): void {
let electronUpdateDownloading = false;
let electronDownloadRetries = 0;
let electronUpdateDownloaded = false;
let electronDownloadedVersion: string | null = null;
const {UpdateSourceType, updateElectronApp} = requireModule(
'update-electron-app',
) as typeof import('update-electron-app');
@@ -323,7 +325,14 @@ function registerElectronUpdater(getMainWindow: () => BrowserWindow | null): voi
autoUpdater.on('checking-for-update', () => {
send(getMainWindow(), {type: 'checking', context: lastContext});
});
const sendPendingRestart = () => {
send(getMainWindow(), {type: 'downloaded', context: lastContext, version: electronDownloadedVersion});
};
autoUpdater.on('update-available', () => {
if (electronUpdateDownloaded) {
sendPendingRestart();
return;
}
electronUpdateDownloading = true;
send(getMainWindow(), {
type: 'available',
@@ -334,10 +343,19 @@ function registerElectronUpdater(getMainWindow: () => BrowserWindow | null): voi
});
});
autoUpdater.on('update-not-available', () => {
if (electronUpdateDownloaded) {
sendPendingRestart();
return;
}
send(getMainWindow(), {type: 'not-available', context: lastContext});
});
autoUpdater.on('update-downloaded', (_event, _releaseNotes, releaseName) => {
send(getMainWindow(), {type: 'downloaded', context: lastContext, version: releaseName ?? null});
electronUpdateDownloading = false;
electronUpdateDownloaded = true;
if (releaseName) {
electronDownloadedVersion = releaseName;
}
sendPendingRestart();
});
autoUpdater.on('error', (err: Error) => {
const message = err?.message ?? String(err);
@@ -360,6 +378,10 @@ function registerElectronUpdater(getMainWindow: () => BrowserWindow | null): voi
return;
}
electronUpdateDownloading = false;
if (electronUpdateDownloaded) {
sendPendingRestart();
return;
}
send(getMainWindow(), {type: 'error', context: lastContext, phase, message});
});
ipcMain.handle('updater-check', async (_e, context: UpdaterContext) => {