From 2f2bbd0a276e595980613b2388ae9156f738a3b9 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Tue, 6 Aug 2024 16:08:49 -0700 Subject: [PATCH] Check for updates always if user requests it, add comments --- emain/updater.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/emain/updater.ts b/emain/updater.ts index cac9a97f9..3c9013dc1 100644 --- a/emain/updater.ts +++ b/emain/updater.ts @@ -92,20 +92,25 @@ export class Updater { async checkForUpdates(userInput: boolean) { const autoUpdateOpts = (await services.FileService.GetSettingsConfig()).autoupdate; - if (!autoUpdateOpts.enabled) { + // If there's an active update check interval, check that the user still has auto update checks enabled. If not, remove the interval. + if (this.interval && !autoUpdateOpts.enabled) { console.log("Auto update is disabled in settings. Removing the auto update interval."); clearInterval(this.interval); this.interval = null; - return; } + const now = new Date(); + + // Run an update check always if the user requests it, otherwise only if there's an active update check interval and enough time has elapsed. if ( userInput || - !this.lastUpdateCheck || - Math.abs(now.getTime() - this.lastUpdateCheck.getTime()) > autoUpdateOpts.intervalms + (this.interval && + (!this.lastUpdateCheck || + Math.abs(now.getTime() - this.lastUpdateCheck.getTime()) > autoUpdateOpts.intervalms)) ) { const result = await autoUpdater.checkForUpdates(); - console.log("check for updates result:", result.updateInfo.version, result); + + // If the user requested this check and we do not have an available update, let them know with a popup dialog. No need to tell them if there is an update, because we show a banner once the update is ready to install. if (userInput && !result.downloadPromise) { const dialogOpts: Electron.MessageBoxOptions = { type: "info", @@ -113,6 +118,8 @@ export class Updater { }; electron.dialog.showMessageBox(electron.BrowserWindow.getFocusedWindow(), dialogOpts); } + + // Only update the last check time if this is an automatic check. This ensures the interval remains consistent. if (!userInput) this.lastUpdateCheck = now; } }