diff --git a/NucleicRemote/NucleicRemote/Models/RemoteStore.swift b/NucleicRemote/NucleicRemote/Models/RemoteStore.swift index 225c8e2..76be4d0 100644 --- a/NucleicRemote/NucleicRemote/Models/RemoteStore.swift +++ b/NucleicRemote/NucleicRemote/Models/RemoteStore.swift @@ -265,10 +265,29 @@ final class RemoteStore: ObservableObject { func onAppear() { if demoMode { seedDemo(); return } + // 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() if isPaired { reconnect() } } + /// A network-path change: tell each host connection to re-plan its transport now. + private func handlePathChange() { + guard !demoMode else { return } + for conn in connections.values { conn.networkPathChanged() } + } + + /// Returning to the foreground: the network may have changed while the app was suspended (and + /// path/keepalive callbacks were frozen). Re-read the path and re-dial anything not live so the + /// transport is correct by the time the UI is on screen, rather than after a backoff. + func onForeground() { + guard !demoMode, isPaired else { return } + pathMonitor.refresh() + reconnect() + } + private func seedDemo() { connectivity = .connected(.lan) hostName = "Andrew's Mac"