restart interval in checkForUpdates if update setting changes

This commit is contained in:
Evan Simkowitz 2024-08-06 16:13:14 -07:00
parent acb6a87ca4
commit 5f229048be
No known key found for this signature in database

View File

@ -75,14 +75,15 @@ export class Updater {
/** /**
* Starts the auto update check interval. * Starts the auto update check interval.
* @param [runCheckNow=true] Determines whether the update check should run immediately. Defaults to true.
* @returns The timeout object for the auto update checker. * @returns The timeout object for the auto update checker.
*/ */
startAutoUpdateInterval(): NodeJS.Timeout { startInterval(runCheckNow = true): NodeJS.Timeout {
// check for updates right away and keep checking later // check for updates right away and keep checking later
this.checkForUpdates(false); if (runCheckNow) this.checkForUpdates(false);
return setInterval(() => { return setInterval(() => {
this.checkForUpdates(false); this.checkForUpdates(false);
}, 600000); // intervals are unreliable when an app is suspended so we will check every 10 mins if an hour has passed. }, 600000); // intervals are unreliable when an app is suspended so we will check every 10 mins if the interval has passed.
} }
/** /**
@ -97,6 +98,8 @@ export class Updater {
console.log("Auto update is disabled in settings. Removing the auto update interval."); console.log("Auto update is disabled in settings. Removing the auto update interval.");
clearInterval(this.interval); clearInterval(this.interval);
this.interval = null; this.interval = null;
} else if (!this.interval && autoUpdateOpts.enabled) {
this.startInterval(false);
} }
const now = new Date(); const now = new Date();
@ -187,7 +190,7 @@ export async function configureAutoUpdater() {
if (autoUpdateEnabled && updater?.interval == null) { if (autoUpdateEnabled && updater?.interval == null) {
try { try {
console.log("configuring auto update interval"); console.log("configuring auto update interval");
updater?.startAutoUpdateInterval(); updater?.startInterval();
} catch (e) { } catch (e) {
console.log("error configuring auto update interval", e.toString()); console.log("error configuring auto update interval", e.toString());
} }