Network Type Transition Optimization

Nucleic-Session: 40F8C53A-F001-423A-8607-EAE181DBE14B
Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
2026-07-04 23:39:54 -07:00
co-authored by Nucleic
parent d80e94fc24
commit 087f49d592
@@ -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"