Skip to content

Commit

Permalink
Merge pull request #388 from Planetable/fixes-vapor-api-sleep-notific…
Browse files Browse the repository at this point in the history
…ation

Fix default notification center.
  • Loading branch information
livid authored Oct 15, 2024
2 parents a7f32ab + ef90ab0 commit 0cef138
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 0cef138

Please sign in to comment.