From 745ed4ee314b1364792c0dffba1b6b97d593efc2 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Wed, 20 Sep 2023 10:41:50 +0100 Subject: [PATCH] fix: more auto-update logging, disable if not supported COMPASS-7220 (#4868) * more auto-update logging, disable if not supported * add ticket numbers, remove extra logging * tweak comment --- .../compass/src/main/auto-update-manager.ts | 48 ++++++++++++++----- packages/compass/src/main/auto-updater.ts | 2 +- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/packages/compass/src/main/auto-update-manager.ts b/packages/compass/src/main/auto-update-manager.ts index 502f7fda870..188528d97ea 100644 --- a/packages/compass/src/main/auto-update-manager.ts +++ b/packages/compass/src/main/auto-update-manager.ts @@ -5,7 +5,7 @@ import COMPASS_ICON from './icon'; import type { FeedURLOptions } from 'electron'; import { app, dialog, BrowserWindow } from 'electron'; import { setTimeout as wait } from 'timers/promises'; -import autoUpdater from './auto-updater'; +import autoUpdater, { supportsAutoupdater } from './auto-updater'; import preferences from 'compass-preferences-model'; import fetch from 'node-fetch'; import dl from 'electron-dl'; @@ -579,9 +579,41 @@ class CompassAutoUpdateManager { ...options, }; + // TODO(COMPASS-7232): If auto-updates are not supported, then there is + // still a menu item to check for updates and then if it finds an update but + // auto-updates aren't supported it will still display a popup with an + // Install button that does nothing. + compassApp.on('check-for-updates', () => { + this.setState(AutoUpdateManagerState.ManualCheck); + }); + + const supported = supportsAutoupdater(); const enabled = !!preferences.getPreferences().autoUpdates; + log.info( + mongoLogId(1001000133), + 'AutoUpdateManager', + 'Setting up updateManager', + { ...this.autoUpdateOptions, supported, enabled } + ); + + if (!supported) { + this.setState(AutoUpdateManagerState.Disabled); + return; + } + + // If autoupdate is supported, then enable/disable it depending on preferences + preferences.onPreferenceValueChanged('autoUpdates', (enabled) => { + log.info( + mongoLogId(1_001_000_247), + 'AutoUpdateManager', + `autoUpdate preference toggled to ${enabled ? 'enabled' : 'disabled'}`, + { + enabled, + } + ); + if (enabled) { track('Autoupdate Enabled'); this.setState(AutoUpdateManagerState.CheckingForUpdates); @@ -591,17 +623,9 @@ class CompassAutoUpdateManager { } }); - compassApp.on('check-for-updates', () => { - this.setState(AutoUpdateManagerState.ManualCheck); - }); - - log.info( - mongoLogId(1001000133), - 'AutoUpdateManager', - 'Setting up updateManager', - { ...this.autoUpdateOptions, enabled } - ); - + // TODO(COMPASS-7233): This is kinda pointless at the moment because the + // preferences start as disabled and then become enabled the moment they are + // loaded. Which would immediately kick off the state change. if (enabled) { // Do not kick off update check immediately, wait a little before that so // that we 1) don't waste time checking on the application start 2) don't diff --git a/packages/compass/src/main/auto-updater.ts b/packages/compass/src/main/auto-updater.ts index 25b7af61945..7fa37d20648 100644 --- a/packages/compass/src/main/auto-updater.ts +++ b/packages/compass/src/main/auto-updater.ts @@ -38,7 +38,7 @@ function hasSquirrel() { return fs.existsSync(updateExe); } -function supportsAutoupdater() { +export function supportsAutoupdater() { if (process.platform === 'linux') { return false; }