Skip to content

Commit

Permalink
android: nectarine more fixes (#2121)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneschepke authored Feb 10, 2025
1 parent 8e60c54 commit 851ccf4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ import timber.log.Timber
class DataStoreGatewayRepository(private val dataStoreManager: DataStoreManager) :
GatewayRepository {
companion object {
val ENTRY_COUNTRIES = stringPreferencesKey("ENTRY_GATEWAYS")
val EXIT_COUNTRIES = stringPreferencesKey("EXIT_GATEWAYS")
val WG_COUNTRIES = stringPreferencesKey("WG_GATEWAYS")
val ENTRY_GATEWAYS = stringPreferencesKey("ENTRY_GATEWAYS")
val EXIT_GATEWAYS = stringPreferencesKey("EXIT_GATEWAYS")
val WG_GATEWAYS = stringPreferencesKey("WG_GATEWAYS")
}

override suspend fun setEntryGateways(gateways: List<NymGateway>) {
dataStoreManager.saveToDataStore(ENTRY_COUNTRIES, gateways.toString())
dataStoreManager.saveToDataStore(ENTRY_GATEWAYS, gateways.toString())
}

override suspend fun setExitGateways(gateways: List<NymGateway>) {
dataStoreManager.saveToDataStore(EXIT_COUNTRIES, gateways.toString())
dataStoreManager.saveToDataStore(EXIT_GATEWAYS, gateways.toString())
}

override suspend fun setWgGateways(gateways: List<NymGateway>) {
dataStoreManager.saveToDataStore(WG_COUNTRIES, gateways.toString())
dataStoreManager.saveToDataStore(WG_GATEWAYS, gateways.toString())
}

override val gatewayFlow: Flow<Gateways> =
dataStoreManager.preferencesFlow.map { prefs ->
prefs?.let { pref ->
try {
Gateways(
exitGateways = NymGateway.fromCollectionString(pref[EXIT_COUNTRIES]),
entryGateways = NymGateway.fromCollectionString(pref[ENTRY_COUNTRIES]),
wgGateways = NymGateway.fromCollectionString(pref[WG_COUNTRIES]),
exitGateways = NymGateway.fromCollectionString(pref[EXIT_GATEWAYS]),
entryGateways = NymGateway.fromCollectionString(pref[ENTRY_GATEWAYS]),
wgGateways = NymGateway.fromCollectionString(pref[WG_GATEWAYS]),
)
} catch (e: IllegalArgumentException) {
Timber.e(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class GatewayDataStoreCacheService @Inject constructor(
) : GatewayCacheService {
override suspend fun updateExitGatewayCache(): Result<Unit> {
return runCatching {
val countries = backend.getGateways(GatewayType.MIXNET_EXIT)
gatewayRepository.setExitGateways(countries)
val gateways = backend.getGateways(GatewayType.MIXNET_EXIT)
gatewayRepository.setExitGateways(gateways)
Timber.d("Updated mixnet exit countries cache")
}.onFailure {
Timber.e(it)
Expand All @@ -22,8 +22,8 @@ class GatewayDataStoreCacheService @Inject constructor(

override suspend fun updateEntryGatewayCache(): Result<Unit> {
return runCatching {
val countries = backend.getGateways(GatewayType.MIXNET_ENTRY)
gatewayRepository.setEntryGateways(countries)
val gateways = backend.getGateways(GatewayType.MIXNET_ENTRY)
gatewayRepository.setEntryGateways(gateways)
Timber.d("Updated mixnet entry countries cache")
}.onFailure {
Timber.e(it)
Expand All @@ -32,8 +32,8 @@ class GatewayDataStoreCacheService @Inject constructor(

override suspend fun updateWgGatewayCache(): Result<Unit> {
return kotlin.runCatching {
val countries = backend.getGateways(GatewayType.WG)
gatewayRepository.setWgGateways(countries)
val gateways = backend.getGateways(GatewayType.WG)
gatewayRepository.setWgGateways(gateways)
Timber.d("Updated wg countries cache")
}.onFailure {
Timber.e(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.QuestionMark
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.rounded.Search
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -160,7 +159,7 @@ fun HopScreen(gatewayLocation: GatewayLocation, appViewModel: AppViewModel, appU
}
}

val gateways = remember {
val gateways = remember(appUiState.gateways) {
when (gatewayType) {
GatewayType.MIXNET_ENTRY -> appUiState.gateways.entryGateways
GatewayType.MIXNET_EXIT -> appUiState.gateways.exitGateways
Expand Down Expand Up @@ -217,8 +216,8 @@ fun HopScreen(gatewayLocation: GatewayLocation, appViewModel: AppViewModel, appU
Score.HIGH -> ImageVector.vectorResource(R.drawable.bars_3)
Score.MEDIUM -> ImageVector.vectorResource(R.drawable.bars_2)
Score.LOW -> ImageVector.vectorResource(R.drawable.bar_1)
Score.NONE -> Icons.Default.QuestionMark
null -> Icons.Default.QuestionMark
Score.NONE -> ImageVector.vectorResource(R.drawable.faq)
null -> ImageVector.vectorResource(R.drawable.faq)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import net.nymtech.vpn.backend.Tunnel

@Composable
fun MainScreen(appViewModel: AppViewModel, appUiState: AppUiState, autoStart: Boolean, viewModel: MainViewModel = hiltViewModel()) {
val uiState = remember(appUiState) {
val uiState = remember(appUiState.managerState, appUiState.networkStatus) {
with(appUiState) {
val connectionState = when {
managerState.tunnelState != Tunnel.State.Down && networkStatus == NetworkStatus.Disconnected -> ConnectionState.WaitingForConnection
Expand Down Expand Up @@ -364,7 +364,7 @@ fun MainScreen(appViewModel: AppViewModel, appUiState: AppUiState, autoStart: Bo
leading = {
val image = appUiState.exitPointCountry?.let {
ImageVector.vectorResource(context.getFlagImageVectorByName(it))
} ?: Icons.Default.QuestionMark
} ?: ImageVector.vectorResource(R.drawable.faq)
Image(
image,
image.name,
Expand Down

0 comments on commit 851ccf4

Please sign in to comment.