Launch Activity Logic

Nucleic-Session: EBB24271-3AB2-4CBD-A47A-59FC73500371
Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
2026-07-06 14:03:36 -07:00
co-authored by Nucleic
parent 7aa202f3ad
commit c362480c8a
@@ -320,11 +320,7 @@ final class RemoteStore: ObservableObject {
func onAppear() { func onAppear() {
setupLiveActivityBridge() setupLiveActivityBridge()
if demoMode { seedDemo(); return } if demoMode { seedDemo(); return }
// Re-plan every connection the moment the network path changes (left Wi-Fi, joined a startNetworkingIfNeeded()
// network, cellular⇄Wi-Fi) — the proactive half of "immediate switchover".
pathMonitor.onChange = { [weak self] in self?.handlePathChange() }
pathMonitor.start()
discovery.start()
if isPaired { if isPaired {
// Show the saved chat history immediately, before any host connects. // Show the saved chat history immediately, before any host connects.
if sessions.isEmpty { sessions = cachedSummaries } if sessions.isEmpty { sessions = cachedSummaries }
@@ -332,6 +328,22 @@ final class RemoteStore: ObservableObject {
} }
} }
/// Whether `startNetworkingIfNeeded` has already wired up path monitoring + LAN discovery.
private var networkingStarted = false
/// Start the shared network-path monitor and LAN discovery once. Factored out of `onAppear` so
/// the background push handler — which runs when `onAppear` never fired (silent launch, no scene)
/// — can bring the same machinery up before it dials.
private func startNetworkingIfNeeded() {
guard !networkingStarted else { return }
networkingStarted = true
// Re-plan every connection the moment the network path changes (left Wi-Fi, joined a
// network, cellular⇄Wi-Fi) — the proactive half of "immediate switchover".
pathMonitor.onChange = { [weak self] in self?.handlePathChange() }
pathMonitor.start()
discovery.start()
}
/// A network-path change: tell each host connection to re-plan its transport now. /// A network-path change: tell each host connection to re-plan its transport now.
private func handlePathChange() { private func handlePathChange() {
guard !demoMode else { return } guard !demoMode else { return }