From ef90ab0eb55b8adb5adf57b1b27df370bcb69502 Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 15 Oct 2024 09:02:35 +0800 Subject: [PATCH] Fix default notification center. --- Planet/PlanetAppDelegate.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Planet/PlanetAppDelegate.swift b/Planet/PlanetAppDelegate.swift index 7530895c..86da9464 100644 --- a/Planet/PlanetAppDelegate.swift +++ b/Planet/PlanetAppDelegate.swift @@ -136,14 +136,15 @@ class PlanetAppDelegate: NSObject, NSApplicationDelegate { } // Notify API server if system is going to sleep / awake - NotificationCenter.default.addObserver(forName: NSWorkspace.willSleepNotification, object: nil, queue: nil) { _ in + let center = NSWorkspace.shared.notificationCenter + center.addObserver(forName: NSWorkspace.willSleepNotification, object: nil, queue: nil) { _ in if UserDefaults.standard.bool(forKey: .settingsAPIEnabled) { Task { @MainActor in PlanetAPIController.shared.pauseServerForSleep() } } } - NotificationCenter.default.addObserver(forName: NSWorkspace.didWakeNotification, object: nil, queue: nil) { _ in + center.addObserver(forName: NSWorkspace.didWakeNotification, object: nil, queue: nil) { _ in if UserDefaults.standard.bool(forKey: .settingsAPIEnabled) { Task.detached(priority: .utility) { try? await Task.sleep(nanoseconds: 1_000_000_000)