@@ -28,7 +28,7 @@ import { createElectronFileInputBackend } from '@mongodb-js/compass-components';
2828import { CompassRendererConnectionStorage } from '@mongodb-js/connection-storage/renderer' ;
2929import type { SettingsTabId } from '@mongodb-js/compass-settings' ;
3030import type { AutoConnectPreferences } from '../main/auto-connect' ;
31- import { injectCSP } from './utils/csp' ;
31+
3232const { log, mongoLogId } = createLogger ( 'COMPASS-APP' ) ;
3333const track = createIpcTrack ( ) ;
3434
@@ -206,21 +206,6 @@ class Application {
206206 document . querySelector ( '#loading-placeholder' ) ?. remove ( ) ;
207207 }
208208
209- private async updateAppVersion ( ) {
210- const { lastKnownVersion, highestInstalledVersion } =
211- defaultPreferencesInstance . getPreferences ( ) ;
212- this . previousVersion = lastKnownVersion || DEFAULT_APP_VERSION ;
213- this . highestInstalledVersion =
214- semver . sort ( [
215- highestInstalledVersion || DEFAULT_APP_VERSION ,
216- this . version ,
217- ] ) ?. [ 1 ] ?? this . version ;
218- await defaultPreferencesInstance . savePreferences ( {
219- lastKnownVersion : this . version ,
220- highestInstalledVersion : this . highestInstalledVersion ,
221- } ) ;
222- }
223-
224209 private setupDataRefreshListener ( ) {
225210 ipcRenderer ?. on ( 'app:refresh-data' , ( ) =>
226211 globalAppRegistry . emit ( 'refresh-data' )
@@ -454,20 +439,15 @@ class Application {
454439 // unhandled errors are properly logged and reported
455440 this . setupGlobalErrorHandling ( ) ;
456441
457- // Inject CSP first to prevent any CSP violations.
458- injectCSP ( ) ;
459-
460- this . allowDevFeatureFlagsFromDevTools ( ) ;
461- this . preventDefaultBrowserBehaviorForDragAndDrop ( ) ;
462-
463442 // Setup development environment
464443 this . enableDevelopmentDebug ( ) ;
444+ this . allowDevFeatureFlagsFromDevTools ( ) ;
445+
465446 this . patchNODE4281 ( ) ;
466447 this . setupWebVitals ( ) ;
467448
468449 // Initialize preferences and version
469- await defaultPreferencesInstance . refreshPreferences ( ) ;
470- await this . updateAppVersion ( ) ;
450+ await this . initializePreferencesAndVersion ( ) ;
471451
472452 void this . setupIntercomAndLogError ( ) ;
473453
@@ -476,6 +456,7 @@ class Application {
476456 this . setupAutoUpdateListeners ( ) ;
477457 this . setupConnectInNewWindowListeners ( ) ;
478458 this . setupZoomControls ( ) ;
459+ this . preventDefaultBrowserBehaviorForDragAndDrop ( ) ;
479460
480461 // Render the application
481462 await this . render ( ) ;
@@ -488,6 +469,27 @@ class Application {
488469 this . logVersionInfo ( ) ;
489470 this . showUpdateToastIfNeeded ( ) ;
490471 }
472+
473+ private async initializePreferencesAndVersion ( ) {
474+ await defaultPreferencesInstance . refreshPreferences ( ) ;
475+
476+ // This code updates the last known version and highest installed version in preferences after
477+ // the first installation, or a potential update or downgrade.
478+ // This is useful so that we can track the version history of the application, and
479+ // handle auto-updates differently in case of downgrades.
480+ const { lastKnownVersion, highestInstalledVersion } =
481+ defaultPreferencesInstance . getPreferences ( ) ;
482+ this . previousVersion = lastKnownVersion || DEFAULT_APP_VERSION ;
483+ this . highestInstalledVersion =
484+ semver . sort ( [
485+ highestInstalledVersion || DEFAULT_APP_VERSION ,
486+ this . version ,
487+ ] ) ?. [ 1 ] ?? this . version ;
488+ await defaultPreferencesInstance . savePreferences ( {
489+ lastKnownVersion : this . version ,
490+ highestInstalledVersion : this . highestInstalledVersion ,
491+ } ) ;
492+ }
491493}
492494
493495export const app = Application . getInstance ( ) ;
0 commit comments