diff options
Diffstat (limited to 'android/app')
| -rw-r--r-- | android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoRepository.kt | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoRepository.kt index 63ce64cd06..edf5dba131 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoRepository.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoRepository.kt @@ -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) + ) } |
