diff options
| author | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-03-25 14:46:13 +0100 |
|---|---|---|
| committer | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-05-28 10:28:14 +0200 |
| commit | 8a1a7d8d9b34fcac8e261f457f3e65ce3ac599f0 (patch) | |
| tree | 094ad862827061be1a626cbfb0d94ecd8812a927 | |
| parent | 3318e8d33da061cabe5f9081b03a347b6f18670a (diff) | |
| download | mullvadvpn-8a1a7d8d9b34fcac8e261f457f3e65ce3ac599f0.tar.xz mullvadvpn-8a1a7d8d9b34fcac8e261f457f3e65ce3ac599f0.zip | |
Use the AppUpgrade class to integrate Daemon's events with Main IPC
| -rw-r--r-- | desktop/packages/mullvad-vpn/src/main/index.ts | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/desktop/packages/mullvad-vpn/src/main/index.ts b/desktop/packages/mullvad-vpn/src/main/index.ts index 57a0bf3dc9..34d9d5e95d 100644 --- a/desktop/packages/mullvad-vpn/src/main/index.ts +++ b/desktop/packages/mullvad-vpn/src/main/index.ts @@ -12,6 +12,7 @@ import { import { urls } from '../shared/constants'; import { AccessMethodSetting, + DaemonAppUpgradeEvent, DaemonEvent, DeviceEvent, ErrorStateCause, @@ -30,6 +31,7 @@ import { SystemNotificationCategory, } from '../shared/notifications/notification'; import Account, { AccountDelegate, LocaleProvider } from './account'; +import AppUpgrade from './app-upgrade'; import { getOpenAtLogin } from './autostart'; import { readChangelog } from './changelog'; import { @@ -96,10 +98,12 @@ class ApplicationMain private version: Version; private settings: Settings; private account: Account; + private appUpgrade: AppUpgrade; private userInterface?: UserInterface; private tunnelState = new TunnelStateHandler(this); private daemonEventListener?: SubscriptionListener<DaemonEvent>; + private daemonAppUpgradeEventListener?: SubscriptionListener<DaemonAppUpgradeEvent>; private reconnectBackoff = new ReconnectionBackoff(); private beforeFirstDaemonConnection = true; private isPerformingPostUpgrade = false; @@ -141,6 +145,7 @@ class ApplicationMain this.version = new Version(this, this.daemonRpc, UPDATE_NOTIFICATION_DISABLED); this.settings = new Settings(this, this.daemonRpc, this.version.currentVersion); this.account = new Account(this, this.daemonRpc); + this.appUpgrade = new AppUpgrade(this.daemonRpc); } public run() { @@ -527,6 +532,16 @@ class ApplicationMain return this.handleBootstrapError(error); } + // subscribe to app upgrade events + try { + this.daemonAppUpgradeEventListener = this.appUpgrade.subscribeEvents(); + } catch (e) { + const error = e as Error; + log.error(`Failed to subscribe to app upgrade events: ${error.message}`); + + return this.handleBootstrapError(error); + } + if (firstDaemonConnection) { // check if daemon is performing post upgrade tasks the first time it's connected to try { @@ -650,8 +665,12 @@ class ApplicationMain if (this.daemonEventListener) { this.daemonRpc.unsubscribeDaemonEventListener(this.daemonEventListener); } - // Reset the daemon event listener since it's going to be invalidated on disconnect + if (this.daemonAppUpgradeEventListener) { + this.daemonRpc.unsubscribeAppUpgradeEventListener(this.daemonAppUpgradeEventListener); + } + // Reset the daemon and app upgrade event listeners since they're going to be invalidated on disconnect this.daemonEventListener = undefined; + this.daemonAppUpgradeEventListener = undefined; this.notificationController.closeNotificationsInCategory( SystemNotificationCategory.tunnelState, @@ -699,10 +718,14 @@ class ApplicationMain } private handleBootstrapError(_error?: Error) { - // Unsubscribe from daemon events when encountering errors during initial data retrieval. + // Unsubscribe from daemon and app upgrade events when encountering errors during initial data retrieval. if (this.daemonEventListener) { this.daemonRpc.unsubscribeDaemonEventListener(this.daemonEventListener); } + + if (this.daemonAppUpgradeEventListener) { + this.daemonRpc.unsubscribeAppUpgradeEventListener(this.daemonAppUpgradeEventListener); + } } private subscribeEvents(): SubscriptionListener<DaemonEvent> { @@ -897,6 +920,7 @@ class ApplicationMain this.userInterface!.registerIpcListeners(); this.settings.registerIpcListeners(); this.account.registerIpcListeners(); + this.appUpgrade.registerIpcListeners(); if (this.splitTunneling) { this.settings.gui.browsedForSplitTunnelingApplications.forEach((application) => { |
