diff options
| author | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-03-11 16:30:26 +0100 |
|---|---|---|
| committer | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-05-28 10:28:14 +0200 |
| commit | 01483b65df53b2a50e2c2c309e5c37a5c5c55153 (patch) | |
| tree | ae7046a1030d11be406334491000285b2e3d29a5 | |
| parent | 19a45b8fef1fec9fffe6bfc45d04a3c415df0b09 (diff) | |
| download | mullvadvpn-01483b65df53b2a50e2c2c309e5c37a5c5c55153.tar.xz mullvadvpn-01483b65df53b2a50e2c2c309e5c37a5c5c55153.zip | |
Add function to convert AppUpgrade gRCPC events to Electron IPC variant
| -rw-r--r-- | desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts b/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts index 96334cc435..44f1c8b3a6 100644 --- a/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts +++ b/desktop/packages/mullvad-vpn/src/main/grpc-type-convertions.ts @@ -14,6 +14,8 @@ import { Constraint, CustomLists, CustomProxy, + DaemonAppUpgradeError, + DaemonAppUpgradeEvent, DaemonEvent, DeviceEvent, DeviceState, @@ -713,6 +715,65 @@ function convertFromObfuscationSettings( }; } +function convertFromAppUpgradeError(error: grpcTypes.AppUpgradeError.Error): DaemonAppUpgradeError { + switch (error) { + case grpcTypes.AppUpgradeError.Error.DOWNLOAD_FAILED: + return 'DOWNLOAD_FAILED'; + case grpcTypes.AppUpgradeError.Error.VERFICATION_FAILED: + return 'VERIFICATION_FAILED'; + default: + return 'GENERAL_ERROR'; + } +} + +export function convertFromAppUpgradeEvent(data: grpcTypes.AppUpgradeEvent): DaemonAppUpgradeEvent { + const downloadStartingData = data.getDownloadStarting(); + if (downloadStartingData !== undefined) { + return { type: 'APP_UPGRADE_STATUS_DOWNLOAD_STARTED' }; + } + + const downloadProgressData = data.getDownloadProgress(); + if (downloadProgressData !== undefined) { + const [server, progress, timeLeftDuration] = [ + downloadProgressData.getServer(), + downloadProgressData.getProgress(), + downloadProgressData.getTimeLeft(), + ]; + + const timeLeft = timeLeftDuration?.getSeconds() || 0; + + return { type: 'APP_UPGRADE_STATUS_DOWNLOAD_PROGRESS', server, progress, timeLeft }; + } + + if (data.hasUpgradeAborted()) { + return { type: 'APP_UPGRADE_STATUS_ABORTED' }; + } + + if (data.hasVerifyingInstaller()) { + return { type: 'APP_UPGRADE_STATUS_VERIFYING_INSTALLER' }; + } + + if (data.hasVerifiedInstaller()) { + return { type: 'APP_UPGRADE_STATUS_VERIFIED_INSTALLER' }; + } + + const errorData = data.getError(); + if (errorData !== undefined) { + const error = errorData.getError(); + + return { + type: 'APP_UPGRADE_ERROR', + error: convertFromAppUpgradeError(error), + }; + } + + // Handle unknown AppUpgradeEvent messages + const keys = Object.entries(data.toObject()) + .filter(([, value]) => value !== undefined) + .map(([key]) => key); + throw new Error(`Unknown app upgrade event received containing ${keys}`); +} + export function convertFromDaemonEvent(data: grpcTypes.DaemonEvent): DaemonEvent { const tunnelState = data.getTunnelState(); if (tunnelState !== undefined) { |
