fix: исправление загрузки конфигурации при старте прокси/сервера
This commit is contained in:
1 parent
0f5584d1b1
commit
7f683bb3f4
3 files changed
+11
-9
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) }
|
||||
|
||||
Reference in new issue
Block a user