From 2f5db84f6df1d14c97c5dc4ae0a32cd749624d48 Mon Sep 17 00:00:00 2001 From: Ivan Prodanov Date: Sat, 1 Oct 2022 17:49:43 +0300 Subject: [PATCH] fix: The update toggle button in the menu does not apply until the app is restarted --- app.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app.js b/app.js index 6538aac..1a401d7 100644 --- a/app.js +++ b/app.js @@ -21,10 +21,8 @@ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); autoUpdater.logger = logger; logger.catchErrors(); -logger.info(app.name + ' started'); -logger.info('Platform: ' + process.platform); - -app.disableHardwareAcceleration(); +logger.info(`${app.name} started`); +logger.info(`Platform: ${process.platform} ${process.arch}`); // hide dock icon on macOS if (process.platform === 'darwin') { @@ -41,6 +39,7 @@ let forceQuit = false; let resizeEvent = false; let mainWindow; let tray; +let updateCheckerInterval; let availabilityCheckerInterval; function registerKeyboardShortcut() { @@ -68,13 +67,11 @@ function useAutoUpdater() { autoUpdater.quitAndInstall(); }); - setInterval(() => { - if (config.get('autoUpdate')) { + if (!updateCheckerInterval && config.get('autoUpdate')) { + updateCheckerInterval = setInterval(() => { autoUpdater.checkForUpdates(); - } - }, 1000 * 60 * 60); + }, 1000 * 60 * 60 * 4); - if (config.get('autoUpdate')) { autoUpdater.checkForUpdates(); } } @@ -357,7 +354,15 @@ function getMenu() { type: 'checkbox', checked: config.get('autoUpdate'), click: () => { - config.set('autoUpdate', !config.get('autoUpdate')); + const currentStatus = config.get('autoUpdate'); + config.set('autoUpdate', !currentStatus); + + if (currentStatus) { + clearInterval(updateCheckerInterval); + updateCheckerInterval = null; + } else { + useAutoUpdater(); + } }, }, {