macOS: add --priority flag for time-sensitive notifications
Add NotificationPriority enum with passive/active/timeSensitive levels that map to UNNotificationInterruptionLevel. timeSensitive breaks through Focus modes for urgent notifications. Usage: clawdis-mac notify --title X --body Y --priority timeSensitive
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import ClawdisIPC
|
||||
import Foundation
|
||||
import UserNotifications
|
||||
|
||||
@MainActor
|
||||
struct NotificationManager {
|
||||
func send(title: String, body: String, sound: String?) async -> Bool {
|
||||
func send(title: String, body: String, sound: String?, priority: NotificationPriority? = nil) async -> Bool {
|
||||
let center = UNUserNotificationCenter.current()
|
||||
let status = await center.notificationSettings()
|
||||
if status.authorizationStatus == .notDetermined {
|
||||
@@ -20,6 +21,18 @@ struct NotificationManager {
|
||||
content.sound = UNNotificationSound(named: UNNotificationSoundName(soundName))
|
||||
}
|
||||
|
||||
// Set interruption level based on priority
|
||||
if let priority {
|
||||
switch priority {
|
||||
case .passive:
|
||||
content.interruptionLevel = .passive
|
||||
case .active:
|
||||
content.interruptionLevel = .active
|
||||
case .timeSensitive:
|
||||
content.interruptionLevel = .timeSensitive
|
||||
}
|
||||
}
|
||||
|
||||
let req = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
|
||||
do {
|
||||
try await center.add(req)
|
||||
|
||||
Reference in New Issue
Block a user