From 45a9156127a4db95491ce325522906c01525dc3e Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 3 Jul 2022 16:38:17 +0100 Subject: [PATCH] Don't check for updates if we already have one downloaded and queued This is a punt at fixing https://github.com/vector-im/element-web/issues/12433, on the assumption that multiple update checks might collide with a download which are already queued to install. It also avoids repeatedly re-downloading the same update on every check, as per the Note: on https://github.com/electron/electron/blob/main/docs/api/auto-updater.md#autoupdatercheckforupdates However, it means that you may have to upgrade twice if you wait more than 24h to install a new build - and if you cancel an upgrade prompt, you'll have to either restart the app or explicitly check for a new version to get upgrades working again. However, this is less annoying than having the app fail to relaunch after upgrading. --- src/updater.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/updater.ts b/src/updater.ts index f41e0cf9e..e42197da8 100644 --- a/src/updater.ts +++ b/src/updater.ts @@ -28,7 +28,20 @@ function installUpdate(): void { function pollForUpdates(): void { try { - autoUpdater.checkForUpdates(); + // If we've already got a new update downloaded, then stop + // trying to check for new ones, as according to the doc + // at https://github.com/electron/electron/blob/main/docs/api/auto-updater.md#autoupdatercheckforupdates + // we'll just keep re-downloading the same update. + // As a hunch, this might also be causing + // https://github.com/vector-im/element-web/issues/12433 + // due to the update checks colliding with the pending install + // somehow + if (!latestUpdateDownloaded) { + autoUpdater.checkForUpdates(); + } + else { + console.log("Skipping update check as download already present"); + } } catch (e) { console.log('Couldn\'t check for update', e); }