fix(tor): remove broken runtime reconnect, add evictConnections

Remove the LaunchedEffect/scope.launch reconnect code that didn't
work (relay subscriptions lost after disconnect+connect cycle).
Tor toggle will use app rebuild via key() instead (next commit).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
nrobi144
2026-04-02 12:13:00 +03:00
parent 70356d541e
commit 01fc5f3ac6
3 changed files with 189 additions and 21 deletions
@@ -500,26 +500,6 @@ fun App(
}
val relayManager = remember(httpClient) { DesktopRelayConnectionManager(httpClient) }
// Reconnect relays on Tor state transitions (ON→proxy, OFF→direct)
LaunchedEffect(torManager, relayManager) {
var previousStatus: com.vitorpamplona.amethyst.commons.tor.TorServiceStatus? = null
torManager.status.collect { status ->
val changed = previousStatus != null && previousStatus != status
// Reconnect on meaningful transitions: Active (proxy ready) or Off (switch to direct)
val isTransition =
changed &&
(
status is com.vitorpamplona.amethyst.commons.tor.TorServiceStatus.Active ||
status is com.vitorpamplona.amethyst.commons.tor.TorServiceStatus.Off
)
if (isTransition) {
kotlinx.coroutines.delay(500) // Brief delay for client state to propagate
relayManager.client.reconnect(onlyIfChanged = false, ignoreRetryDelays = true)
}
previousStatus = status
}
}
// Subscriptions coordinator — uses default relay URLs for metadata indexing.
// Feed subscriptions (inside MainContent) drive actual relay pool connections.
val subscriptionsCoordinator =
@@ -56,7 +56,12 @@ class DesktopHttpClient(
/** Returns true if user expects Tor routing (INTERNAL or EXTERNAL mode). */
fun isTorExpected(): Boolean = torTypeProvider() != TorType.OFF
private val sharedConnectionPool = ConnectionPool()
val sharedConnectionPool = ConnectionPool()
/** Evict all idle connections — call on Tor state change to kill stale direct/proxy connections. */
fun evictConnections() {
sharedConnectionPool.evictAll()
}
private val directClient: OkHttpClient by lazy {
OkHttpClient