Files
cottongin ced6a44ed0 Add luxe Notifier: macOS menu bar app that tells you when luxe needs you
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.
2026-10-24 22:41:42 -04:00

66 lines
2.2 KiB
Swift

import AppKit
import NotifierCore
import SwiftUI
/// Bridges the socket thread to the main-thread UI.
@MainActor
final class AppState: ObservableObject {
@Published private(set) var history: [NotifyEvent] = []
@Published private(set) var unseenCount = 0
@Published var isMuted = false {
didSet { model.isMuted = isMuted }
}
@Published var launchAtLogin = LoginItem.isEnabled {
didSet { if launchAtLogin != LoginItem.isEnabled { LoginItem.set(launchAtLogin) } }
}
@Published private(set) var permission = BannerPermission.unknown
private let model = NotificationCenterModel()
/// Counts every event since launch. History length can't serve: Clear and the cap both shrink it.
private var totalReceived = 0
private var listener: NotifyListener?
func refreshPermission() {
BannerPoster.refreshStatus { [weak self] status in Task { @MainActor in self?.permission = status } }
}
func start() {
BannerClickHandler.install()
BannerPoster.requestPermission { [weak self] status in Task { @MainActor in self?.permission = status } }
let listener = NotifyListener(
path: NotifySocket.defaultPath(),
onEvent: { [weak self] event in Task { @MainActor in self?.receive(event) } },
onProblem: { NSLog("LuxeNotifier: \($0)") }
)
do { try listener.start() } catch { NSLog("LuxeNotifier: cannot listen on socket: \(error)") }
self.listener = listener
}
func markSeen() {
model.markAllSeen()
publish()
}
func clear() {
model.clear()
publish()
}
private func receive(_ event: NotifyEvent) {
totalReceived += 1
NSLog("LuxeNotifier: received \(event.kind.rawValue): \(event.message)")
StatusFile.set("last-event", "\(event.kind.rawValue) at \(event.timestamp)")
StatusFile.set("events-received", "\(totalReceived)")
let showBanner = model.receive(event)
publish()
if showBanner { BannerPoster.post(title: event.title, message: event.message, terminalBundleID: event.terminalBundleID) }
}
private func publish() {
history = model.history
unseenCount = model.unseenCount
}
}