fix(tor): reconnect relays on Tor OFF too, not just ON

Relay reconnect was only triggered when Tor transitioned to Active.
When toggling OFF, relays stayed on the dead SOCKS proxy and never
reconnected over clearnet — feed went blank.

Now triggers reconnect on both Active and Off transitions, so relays
switch between proxy and direct connections when toggling Tor.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
nrobi144
2026-04-02 09:48:03 +03:00
parent 566a4bf452
commit 70356d541e
@@ -500,16 +500,23 @@ fun App(
}
val relayManager = remember(httpClient) { DesktopRelayConnectionManager(httpClient) }
// Reconnect relays through Tor when it becomes active (prevents stale clearnet connections)
// Reconnect relays on Tor state transitions (ON→proxy, OFF→direct)
LaunchedEffect(torManager, relayManager) {
var previouslyActive = false
var previousStatus: com.vitorpamplona.amethyst.commons.tor.TorServiceStatus? = null
torManager.status.collect { status ->
val nowActive = status is com.vitorpamplona.amethyst.commons.tor.TorServiceStatus.Active
if (nowActive && !previouslyActive) {
kotlinx.coroutines.delay(500) // Brief delay for proxy client to propagate
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)
}
previouslyActive = nowActive
previousStatus = status
}
}