Skip to content

Commit

Permalink
Fix default notification center.
Browse files Browse the repository at this point in the history
  • Loading branch information
kailuo committed Oct 15, 2024
1 parent f4cf342 commit ef90ab0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Planet/PlanetAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ef90ab0

Please sign in to comment.