diff --git a/bitchat/BitchatApp.swift b/bitchat/BitchatApp.swift index fd22c16b..c633b5be 100644 --- a/bitchat/BitchatApp.swift +++ b/bitchat/BitchatApp.swift @@ -15,6 +15,8 @@ struct BitchatApp: App { #if os(iOS) @Environment(\.scenePhase) var scenePhase @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) @NSApplicationDelegateAdaptor(MacAppDelegate.self) var appDelegate #endif @@ -66,8 +68,14 @@ struct BitchatApp: App { // Restart services when becoming active chatViewModel.meshService.startServices() TorManager.shared.setAppForeground(true) - // Ensure Tor is healthy; restart deterministically, then wait until ready - TorManager.shared.ensureRunningOnForeground() + // On initial cold launch, Tor was just started in onAppear. + // 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 { let _ = await TorManager.shared.awaitReady(timeout: 60) await MainActor.run { diff --git a/bitchat/ViewModels/ChatViewModel.swift b/bitchat/ViewModels/ChatViewModel.swift index edb3d5b0..5089d738 100644 --- a/bitchat/ViewModels/ChatViewModel.swift +++ b/bitchat/ViewModels/ChatViewModel.swift @@ -836,7 +836,8 @@ class ChatViewModel: ObservableObject, BitchatDelegate { @objc private func handleTorWillRestart() { Task { @MainActor in 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 // Only announce "restarted" if we actually restarted this session 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 } }