Network Type Transition Optimization
Nucleic-Session: 40F8C53A-F001-423A-8607-EAE181DBE14B Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
@@ -265,10 +265,29 @@ final class RemoteStore: ObservableObject {
|
|||||||
|
|
||||||
func onAppear() {
|
func onAppear() {
|
||||||
if demoMode { seedDemo(); return }
|
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()
|
discovery.start()
|
||||||
if isPaired { reconnect() }
|
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() {
|
private func seedDemo() {
|
||||||
connectivity = .connected(.lan)
|
connectivity = .connected(.lan)
|
||||||
hostName = "Andrew's Mac"
|
hostName = "Andrew's Mac"
|
||||||
|
|||||||
Reference in New Issue
Block a user