From ee4d414853e62c0484d7e5848d229f2742c118e7 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 11 Feb 2021 09:21:12 -0500 Subject: [PATCH] Fix auto update on quit with newer version - If the user specifies that Lens should auto update on quit to a specific version, and before they quit the auto-updater finds a newer version. Then disregard the previous request to update Signed-off-by: Sebastian Malton --- src/main/app-updater.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/app-updater.ts b/src/main/app-updater.ts index 618f714b49..2efda414a1 100644 --- a/src/main/app-updater.ts +++ b/src/main/app-updater.ts @@ -5,6 +5,8 @@ import { delay } from "../common/utils"; import { areArgsUpdateAvailableToBackchannel, AutoUpdateLogPrefix, broadcastMessage, onceCorrect, UpdateAvailableChannel, UpdateAvailableToBackchannel } from "../common/ipc"; import { ipcMain } from "electron"; +let installVersion: null | string = null; + function handleAutoUpdateBackChannel(event: Electron.IpcMainEvent, ...[arg]: UpdateAvailableToBackchannel) { if (arg.doUpdate) { if (arg.now) { @@ -38,9 +40,26 @@ export function startUpdateChecking(interval = 1000 * 60 * 60 * 24): void { autoUpdater .on("update-available", (args: UpdateInfo) => { + if (autoUpdater.autoInstallOnAppQuit) { + // a previous auto-update loop was completed with YES+LATER, check if same version + if (installVersion === args.version) { + // same version, don't broadcast + return; + } + } + + /** + * This should be always set to false here because it is the reasonable + * default. Namely, if a don't auto update to a version that the user + * didn't ask for. + */ + autoUpdater.autoInstallOnAppQuit = false; + try { const backchannel = `auto-update:${args.version}`; + installVersion = args.version; + ipcMain.removeAllListeners(backchannel); // only one handler should be present // make sure that the handler is in place before broadcasting (prevent race-condition)