Fix CampusNAS recovery after VPN loss

This commit is contained in:
2026-08-13 01:15:14 +06:00
parent cd53b6a1a1
commit b08f0e8cf1
3 changed files with 53 additions and 5 deletions
@@ -12,6 +12,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
private var hosting: NSHostingController<ContentView>?
private var settingsWindow: NSWindow?
private var keyMonitor: Any?
private var wakeObserver: NSObjectProtocol?
private var cancellables = Set<AnyCancellable>()
func applicationDidFinishLaunching(_ notification: Notification) {
@@ -39,6 +40,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
.store(in: &cancellables)
installKeyMonitor()
observeWake()
model.start()
render()
@@ -51,6 +53,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {
}
}
private func observeWake() {
wakeObserver = NSWorkspace.shared.notificationCenter.addObserver(
forName: NSWorkspace.didWakeNotification, object: nil, queue: .main
) { [weak self] _ in
// NetworkExtension and Wi-Fi routes settle just after didWake.
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
Task { @MainActor in self?.model.wake() }
}
}
}
/// Launching the app again while it is already running (Finder, Spotlight,
/// `open`) brings the window up instead of doing nothing, which is what a
/// second launch is normally asking for.