Fix CampusNAS recovery after VPN loss
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user