mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
Drive HttpClientManager proxy from socksPort flow in TorManager
Instead of calling HttpClientManager.setDefaultProxyOnPort() directly inside the kmp-tor LISTENERS observer, collect _socksPort changes in a single long-lived coroutine (guarded by portCollectorStarted flag) so that any port change — including a circuit restart — automatically updates the OkHttp proxy. https://claude.ai/code/session_01JwcwxdYrDnr3QyHqTBz33a
This commit is contained in:
@@ -42,6 +42,9 @@ object TorManager {
|
||||
@Volatile
|
||||
private var torRuntime: TorRuntime? = null
|
||||
|
||||
@Volatile
|
||||
private var portCollectorStarted = false
|
||||
|
||||
private val _isRunning = MutableStateFlow(false)
|
||||
val isRunning: StateFlow<Boolean> = _isRunning.asStateFlow()
|
||||
|
||||
@@ -101,6 +104,16 @@ object TorManager {
|
||||
appContext = context.applicationContext
|
||||
createNotificationChannel()
|
||||
}
|
||||
if (!portCollectorStarted) {
|
||||
portCollectorStarted = true
|
||||
scope.launch(Dispatchers.IO) {
|
||||
_socksPort.collect { port ->
|
||||
if (port > 0) {
|
||||
HttpClientManager.setDefaultProxyOnPort(port)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (torRuntime != null) return
|
||||
showNotification(context.getString(R.string.tor_starting))
|
||||
scope.launch(Dispatchers.IO) {
|
||||
@@ -126,7 +139,6 @@ object TorManager {
|
||||
val port = addr.port.value
|
||||
Log.i(TAG, "Built-in Tor SOCKS proxy on port $port")
|
||||
_socksPort.value = port
|
||||
HttpClientManager.setDefaultProxyOnPort(port)
|
||||
_isRunning.value = true
|
||||
appContext?.let { showNotification(it.getString(R.string.builtin_tor_active)) }
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in New Issue
Block a user