From 087f49d592a7d4e8e5106fec6ea22f7919862248 Mon Sep 17 00:00:00 2001 From: Andrew Blakeslee Moore Date: Sat, 4 Jul 2026 23:39:54 -0700 Subject: [PATCH] Network Type Transition Optimization Nucleic-Session: 40F8C53A-F001-423A-8607-EAE181DBE14B Co-authored-by: Nucleic --- .../NucleicRemote/Models/RemoteStore.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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"