A luxe hook runs luxe-notify, which sends one JSON line over a Unix socket to a SwiftUI menu bar app. The app shows a banner, keeps a badge count and history, and brings the terminal forward when you click a banner. Notifies on approvals (PermissionRequested), question prompts (BeforeToolUse, matched to the question tool), errors, and turns that run at least --min-seconds (default 30, timed from BeforeAgentStart to AgentEnd). The menu warns when macOS has notifications blocked for the app. The app writes status.txt beside its socket for debugging. Known limits are in README.md and PLAN.md: a crowded menu bar can hide the icon, and the first test build after a change can fail with a TestingMacros error under Command Line Tools, which make test retries once.
29 lines
1.4 KiB
Swift
29 lines
1.4 KiB
Swift
import Foundation
|
|
import UserNotifications
|
|
|
|
/// Focuses the terminal when a banner is clicked. The delegate must be set before the app finishes
|
|
/// launching or macOS drops the click, so it is installed from AppState.start().
|
|
final class BannerClickHandler: NSObject, UNUserNotificationCenterDelegate {
|
|
static let terminalKey = "terminalBundleID"
|
|
static let shared = BannerClickHandler()
|
|
|
|
static func install() {
|
|
guard Bundle.main.bundleIdentifier != nil else { return }
|
|
UNUserNotificationCenter.current().delegate = shared
|
|
}
|
|
|
|
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse,
|
|
withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
let id = response.notification.request.content.userInfo[Self.terminalKey] as? String
|
|
StatusFile.set("last-banner-click", "terminal=\(id ?? "none")")
|
|
DispatchQueue.main.async { TerminalFocuser.focus(bundleID: id) }
|
|
completionHandler()
|
|
}
|
|
|
|
/// Show banners even while the app is frontmost (e.g. its menu is open); otherwise macOS hides them.
|
|
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification,
|
|
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
completionHandler([.banner, .sound])
|
|
}
|
|
}
|