diff options
| author | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-03-26 20:27:21 +0100 |
|---|---|---|
| committer | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-05-28 10:28:14 +0200 |
| commit | 33bfc12ae2585d3680a515f9f88bf740fc072517 (patch) | |
| tree | adeaeed67a95d00c9f246d1fd59fc3ba505069a4 | |
| parent | 4c2dc2c893892e42079df7a86b39593272ca1b78 (diff) | |
| download | mullvadvpn-33bfc12ae2585d3680a515f9f88bf740fc072517.tar.xz mullvadvpn-33bfc12ae2585d3680a515f9f88bf740fc072517.zip | |
Add methods to handle subscriptions for Daemon's AppUpgradeEvent stream
| -rw-r--r-- | desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts b/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts index 8169688fcf..a8675f6d24 100644 --- a/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts +++ b/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts @@ -12,6 +12,7 @@ import { BridgeState, CustomListError, CustomProxy, + DaemonAppUpgradeEvent, DaemonEvent, DeviceState, IAppVersionInfo, @@ -31,6 +32,7 @@ import { import { ConnectionObserver, GrpcClient, noConnectionError } from './grpc-client'; import { convertFromApiAccessMethodSetting, + convertFromAppUpgradeEvent, convertFromDaemonEvent, convertFromDevice, convertFromDeviceState, @@ -91,6 +93,38 @@ export class DaemonRpc extends GrpcClient { super.disconnect(); } + public subscribeAppUpgradeEventListener(listener: SubscriptionListener<DaemonAppUpgradeEvent>) { + const call = this.isConnected && this.client.appUpgradeEventsListen(new Empty()); + if (!call) { + throw noConnectionError; + } + const subscriptionId = this.subscriptionId(); + listener.subscriptionId = subscriptionId; + this.subscriptions.set(subscriptionId, call); + + call.on('data', (data: grpcTypes.AppUpgradeEvent) => { + try { + const appUpgradeEvent = convertFromAppUpgradeEvent(data); + listener.onEvent(appUpgradeEvent); + } catch (e) { + const error = e as Error; + listener.onError(error); + } + }); + + call.on('error', (error) => { + listener.onError(error); + this.removeSubscription(subscriptionId); + }); + } + + public unsubscribeAppUpgradeEventListener(listener: SubscriptionListener<DaemonAppUpgradeEvent>) { + const id = listener.subscriptionId; + if (id !== undefined) { + this.removeSubscription(id); + } + } + public subscribeDaemonEventListener(listener: SubscriptionListener<DaemonEvent>) { const call = this.isConnected && this.client.eventsListen(new Empty()); if (!call) { |
