Skip to content

Commit

Permalink
Allow error on getVersionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Jul 29, 2024
1 parent 514a5c9 commit bd2a625
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
package net.mullvad.mullvadvpn.ui.serviceconnection

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import net.mullvad.mullvadvpn.lib.daemon.grpc.ManagementService
import net.mullvad.mullvadvpn.lib.model.BuildVersion
import net.mullvad.mullvadvpn.ui.VersionInfo

class AppVersionInfoRepository(
private val buildVersion: BuildVersion,
private val managementService: ManagementService
private val managementService: ManagementService,
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
) {
fun versionInfo(): Flow<VersionInfo> =
managementService.versionInfo.map { appVersionInfo ->
VersionInfo(currentVersion = buildVersion.name, isSupported = appVersionInfo.supported)
}
fun versionInfo(): StateFlow<VersionInfo> =
managementService.versionInfo
.map { appVersionInfo ->
VersionInfo(
currentVersion = buildVersion.name,
isSupported = appVersionInfo.supported
)
}
.stateIn(
CoroutineScope(dispatcher),
WhileSubscribed(),
// By default we assume we are supported
VersionInfo(currentVersion = buildVersion.name, isSupported = true)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import net.mullvad.mullvadvpn.lib.model.GetAccountDataError
import net.mullvad.mullvadvpn.lib.model.GetAccountHistoryError
import net.mullvad.mullvadvpn.lib.model.GetDeviceListError
import net.mullvad.mullvadvpn.lib.model.GetDeviceStateError
import net.mullvad.mullvadvpn.lib.model.GetVersionInfoError
import net.mullvad.mullvadvpn.lib.model.LoginAccountError
import net.mullvad.mullvadvpn.lib.model.NewAccessMethodSetting
import net.mullvad.mullvadvpn.lib.model.ObfuscationSettings
Expand Down Expand Up @@ -279,8 +280,11 @@ class ManagementService(
private suspend fun getRelayList(): ModelRelayList =
grpc.getRelayLocations(Empty.getDefaultInstance()).toDomain()

private suspend fun getVersionInfo(): ModelAppVersionInfo =
grpc.getVersionInfo(Empty.getDefaultInstance()).toDomain()
// On release build this will return error until services have published the new beta, daemon
// will get 404 until the api have been published, thus we need to ignore error downstream.
private suspend fun getVersionInfo(): Either<GetVersionInfoError, ModelAppVersionInfo> =
Either.catch { grpc.getVersionInfo(Empty.getDefaultInstance()).toDomain() }
.mapLeft { GetVersionInfoError.Unknown(it) }

suspend fun logoutAccount() {
grpc.logoutAccount(Empty.getDefaultInstance())
Expand Down Expand Up @@ -320,7 +324,7 @@ class ManagementService(
async { _mutableTunnelState.update { getTunnelState() } },
async { _mutableDeviceState.update { getDeviceState() } },
async { _mutableSettings.update { getSettings() } },
async { _mutableVersionInfo.update { getVersionInfo() } },
async { _mutableVersionInfo.update { getVersionInfo().getOrNull() } },
async { _mutableRelayList.update { getRelayList() } },
async { _mutableCurrentAccessMethod.update { getCurrentApiAccessMethod() } }
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.mullvad.mullvadvpn.lib.model

sealed interface GetVersionInfoError {
data class Unknown(val error: Throwable) : GetVersionInfoError
}

0 comments on commit bd2a625

Please sign in to comment.