diff --git a/NucleicRemote/NucleicRemote/NucleicRemoteApp.swift b/NucleicRemote/NucleicRemote/NucleicRemoteApp.swift index 3546d9a..0337176 100644 --- a/NucleicRemote/NucleicRemote/NucleicRemoteApp.swift +++ b/NucleicRemote/NucleicRemote/NucleicRemoteApp.swift @@ -31,11 +31,18 @@ struct NucleicRemoteApp: App { // activity flag current so it only notifies for background transitions. .onChange(of: scenePhase) { _, phase in store.setScenePhaseActive(phase == .active) - if phase == .active { + switch phase { + case .active: // Re-plan transports immediately on foreground — the network may have // changed while suspended, so don't wait for a dead socket to notice. store.onForeground() Task { await HeartbeatReporter.reportIfDue() } + case .background: + // Hold the process (and its live sockets) briefly so a quick app-switch + // doesn't drop the connection and force a cold reconnect on return. + store.onBackground() + default: + break } } }