UI: scope Tor restart messages to geohash channels; skip initial foreground restart on cold launch to avoid confusing system message in #mesh

This commit is contained in:
jack
2025-09-11 13:29:17 +02:00
parent 5020190164
commit 36b5fdabc4
2 changed files with 14 additions and 4 deletions
+10 -2
View File
@@ -15,6 +15,8 @@ struct BitchatApp: App {
#if os(iOS) #if os(iOS)
@Environment(\.scenePhase) var scenePhase @Environment(\.scenePhase) var scenePhase
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
// Skip the very first .active-triggered Tor restart on cold launch
@State private var didHandleInitialActive: Bool = false
#elseif os(macOS) #elseif os(macOS)
@NSApplicationDelegateAdaptor(MacAppDelegate.self) var appDelegate @NSApplicationDelegateAdaptor(MacAppDelegate.self) var appDelegate
#endif #endif
@@ -66,8 +68,14 @@ struct BitchatApp: App {
// Restart services when becoming active // Restart services when becoming active
chatViewModel.meshService.startServices() chatViewModel.meshService.startServices()
TorManager.shared.setAppForeground(true) TorManager.shared.setAppForeground(true)
// Ensure Tor is healthy; restart deterministically, then wait until ready // On initial cold launch, Tor was just started in onAppear.
TorManager.shared.ensureRunningOnForeground() // Skip the deterministic restart the first time we become active.
if didHandleInitialActive {
// Ensure Tor is healthy; restart deterministically, then wait until ready
TorManager.shared.ensureRunningOnForeground()
} else {
didHandleInitialActive = true
}
Task.detached { Task.detached {
let _ = await TorManager.shared.awaitReady(timeout: 60) let _ = await TorManager.shared.awaitReady(timeout: 60)
await MainActor.run { await MainActor.run {
+4 -2
View File
@@ -836,7 +836,8 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
@objc private func handleTorWillRestart() { @objc private func handleTorWillRestart() {
Task { @MainActor in Task { @MainActor in
self.torRestartPending = true self.torRestartPending = true
self.addPublicSystemMessage("tor restarting to recover connectivity…") // Post only in geohash channels (queue if not active)
self.addGeohashOnlySystemMessage("tor restarting to recover connectivity…")
} }
} }
@@ -844,7 +845,8 @@ class ChatViewModel: ObservableObject, BitchatDelegate {
Task { @MainActor in Task { @MainActor in
// Only announce "restarted" if we actually restarted this session // Only announce "restarted" if we actually restarted this session
if self.torRestartPending { if self.torRestartPending {
self.addPublicSystemMessage("tor restarted. network routing restored.") // Post only in geohash channels (queue if not active)
self.addGeohashOnlySystemMessage("tor restarted. network routing restored.")
self.torRestartPending = false self.torRestartPending = false
} }
} }