Skip to content

Commit

Permalink
fix: countries and locale bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneschepke committed Jan 15, 2025
1 parent 06a0310 commit e3c4832
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
12 changes: 9 additions & 3 deletions nym-vpn-android/app/src/main/java/net/nymtech/nymvpn/NymVpn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.nymtech.logcatutil.LogReader
import net.nymtech.nymvpn.data.SettingsRepository
import net.nymtech.nymvpn.module.qualifiers.ApplicationScope
import net.nymtech.nymvpn.module.qualifiers.IoDispatcher
import net.nymtech.nymvpn.module.qualifiers.MainDispatcher
import net.nymtech.nymvpn.util.LocaleUtil
import net.nymtech.nymvpn.util.extensions.requestTileServiceStateUpdate
import net.nymtech.nymvpn.util.timber.ReleaseTree
Expand All @@ -34,6 +36,10 @@ class NymVpn : Application() {
@IoDispatcher
lateinit var ioDispatcher: CoroutineDispatcher

@Inject
@MainDispatcher
lateinit var mainDispatcher: CoroutineDispatcher

@Inject
lateinit var settingsRepository: SettingsRepository

Expand Down Expand Up @@ -66,10 +72,10 @@ class NymVpn : Application() {
logReader.initialize()

applicationScope.launch {
val env = settingsRepository.getEnvironment()
backend.get().init(env, settingsRepository.isCredentialMode())
settingsRepository.getLocale()?.let {
LocaleUtil.changeLocale(it)
withContext(mainDispatcher) {
LocaleUtil.changeLocale(it)
}
}
}
requestTileServiceStateUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ constructor(
}

fun onAppStartup() = viewModelScope.launch {
val env = settingsRepository.getEnvironment()
backend.init(env, settingsRepository.isCredentialMode())
val theme = settingsRepository.getTheme()
uiState.takeWhile { it.settings.theme != theme }.onCompletion {
_isAppReady.emit(true)
}.collect()
launch {
Timber.d("Updating exit country cache")
countryCacheService.updateExitCountriesCache().onSuccess {
Expand All @@ -167,9 +173,5 @@ constructor(
Timber.d("Updating account links")
tunnelManager.refreshAccountLinks()
}
val theme = settingsRepository.getTheme()
uiState.takeWhile { it.settings.theme != theme }.onCompletion {
_isAppReady.emit(true)
}.collect()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import net.nymtech.nymvpn.util.extensions.isCurrentRoute
import net.nymtech.nymvpn.util.extensions.requestTileServiceStateUpdate
import net.nymtech.nymvpn.util.extensions.resetTile
import javax.inject.Inject
import kotlin.system.exitProcess

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
Expand Down Expand Up @@ -121,8 +122,8 @@ class MainActivity : AppCompatActivity() {
if (configurationChange) {
// Restart activity for built-in translation of country names
Intent(this@MainActivity, MainActivity::class.java).also {
finish()
startActivity(it)
exitProcess(0)
}
}
}
Expand Down

0 comments on commit e3c4832

Please sign in to comment.