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:
Peter Steinberger
2025-12-12 18:27:12 +00:00
parent 8ca240fb2c
commit c86cb4e9a5
4 changed files with 34 additions and 9 deletions

View File

@@ -14,9 +14,9 @@ enum ControlRequestHandler {
}
switch request {
case let .notify(title, body, sound):
case let .notify(title, body, sound, priority):
let chosenSound = sound?.trimmingCharacters(in: .whitespacesAndNewlines)
let ok = await notifier.send(title: title, body: body, sound: chosenSound)
let ok = await notifier.send(title: title, body: body, sound: chosenSound, priority: priority)
return ok ? Response(ok: true) : Response(ok: false, message: "notification not authorized")
case let .ensurePermissions(caps, interactive):

View File

@@ -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)