Skip to content

Commit

Permalink
fix: more auto-update logging, disable if not supported COMPASS-7220 (#…
Browse files Browse the repository at this point in the history
…4868)

* more auto-update logging, disable if not supported

* add ticket numbers, remove extra logging

* tweak comment
  • Loading branch information
lerouxb authored Sep 20, 2023
1 parent a23fde8 commit 745ed4e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
48 changes: 36 additions & 12 deletions packages/compass/src/main/auto-update-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/compass/src/main/auto-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function hasSquirrel() {
return fs.existsSync(updateExe);
}

function supportsAutoupdater() {
export function supportsAutoupdater() {
if (process.platform === 'linux') {
return false;
}
Expand Down

0 comments on commit 745ed4e

Please sign in to comment.