-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
9 deletions.
There are no files selected for viewing
28 changes: 22 additions & 6 deletions
28
...p/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/GetVersionInfoError.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |