From 7f683bb3f4bdd2ecac89b0197e126b60758ffd2f Mon Sep 17 00:00:00 2001 From: samosvalishe Date: Mon, 1 Jun 2026 15:39:39 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83?= =?UTF-8?q?=D0=B7=D0=BA=D0=B8=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BF=D1=80=D0=B8=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=80=D1=82=D0=B5=20=D0=BF=D1=80=D0=BE=D0=BA=D1=81?= =?UTF-8?q?=D0=B8/=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/freeturn/app/viewmodel/ProxyViewModel.kt | 4 +++- .../com/freeturn/app/viewmodel/ServerViewModel.kt | 2 +- .../freeturn/app/viewmodel/SettingsViewModel.kt | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/freeturn/app/viewmodel/ProxyViewModel.kt b/app/src/main/java/com/freeturn/app/viewmodel/ProxyViewModel.kt index 186f7c3..1b5beb4 100644 --- a/app/src/main/java/com/freeturn/app/viewmodel/ProxyViewModel.kt +++ b/app/src/main/java/com/freeturn/app/viewmodel/ProxyViewModel.kt @@ -8,6 +8,7 @@ import com.freeturn.app.data.ClientConfig import com.freeturn.app.domain.LocalProxyManager import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch @@ -31,7 +32,8 @@ class ProxyViewModel( fun startProxy() { viewModelScope.launch { - proxyManager.startProxy(clientConfig.value) + val config = prefs.clientConfigFlow.first() + proxyManager.startProxy(config) } } diff --git a/app/src/main/java/com/freeturn/app/viewmodel/ServerViewModel.kt b/app/src/main/java/com/freeturn/app/viewmodel/ServerViewModel.kt index 6e80931..05de2f3 100644 --- a/app/src/main/java/com/freeturn/app/viewmodel/ServerViewModel.kt +++ b/app/src/main/java/com/freeturn/app/viewmodel/ServerViewModel.kt @@ -100,7 +100,7 @@ class ServerViewModel( return@launch } val tcpMode = prefs.clientConfigFlow.first().tcpForward - val opts = serverOpts.value + val opts = prefs.serverOptsFlow.first() sshRepository.startServer( listen = l, connect = c, tcpMode = tcpMode, diff --git a/app/src/main/java/com/freeturn/app/viewmodel/SettingsViewModel.kt b/app/src/main/java/com/freeturn/app/viewmodel/SettingsViewModel.kt index d10b3a7..9c96dd0 100644 --- a/app/src/main/java/com/freeturn/app/viewmodel/SettingsViewModel.kt +++ b/app/src/main/java/com/freeturn/app/viewmodel/SettingsViewModel.kt @@ -260,7 +260,7 @@ class SettingsViewModel( val storedMatches = current.obfProfile == profile val effectiveMatches = known?.obfProfile?.let { it == profile } ?: true if (storedMatches && effectiveMatches) return@launch - val sync = clientConfig.value.syncServerSwitches + val sync = prefs.clientConfigFlow.first().syncServerSwitches var next = current.copy(obfProfile = profile) if (profile != ObfProfile.NONE && next.obfKey.isBlank() && sync) { val key = sshRepository.generateObfKey() @@ -294,18 +294,18 @@ class SettingsViewModel( if (current.obfKey == trimmed) return@launch val next = current.copy(obfKey = trimmed) profileMutex.withLock { prefs.saveServerOpts(next) } - if (clientConfig.value.syncServerSwitches) restartServerIfRunning() + if (prefs.clientConfigFlow.first().syncServerSwitches) restartServerIfRunning() restartProxyIfRunning() } } fun setTcpForward(enabled: Boolean) { - val current = clientConfig.value - val known = sshRepository.serverState.value as? ServerState.Known - val storedMatches = current.tcpForward == enabled - val effectiveMatches = known?.tcpMode?.let { it == enabled } ?: true - if (storedMatches && effectiveMatches) return viewModelScope.launch { + val current = prefs.clientConfigFlow.first() + val known = sshRepository.serverState.value as? ServerState.Known + val storedMatches = current.tcpForward == enabled + val effectiveMatches = known?.tcpMode?.let { it == enabled } ?: true + if (storedMatches && effectiveMatches) return@launch if (!storedMatches) { val next = current.copy(tcpForward = enabled) profileMutex.withLock { prefs.saveClientConfig(next) }