Files
AmolithandGitHub f8da538c50 feat(notification): alert on turn completion and permission request (#1356)
* feat(notification): add em'

Assisted-by: Claude Sonnet 4.5 via Crush

* refactor(permission): check allowlist first

* docs(notification): correct example, fix rendering

* fix(notification): bump godbus/dbus to v5.2.2

v5.1.0's FreeBSD SendNullByte() was in a CGO file, so it was excluded
when building with CGO_ENABLED=0, causing the freebsd/amd64 cross-build
to fail. v5.2.2 rewrites it in pure Go.
2026-03-11 18:12:11 +03:00

50 lines
1.3 KiB
Go

package notification
import (
"log/slog"
"github.com/gen2brain/beeep"
)
// NativeBackend sends desktop notifications using the native OS notification
// system via beeep.
type NativeBackend struct {
// icon is the notification icon data (platform-specific).
icon any
// notifyFunc is the function used to send notifications (swappable for testing).
notifyFunc func(title, message string, icon any) error
}
// NewNativeBackend creates a new native notification backend.
func NewNativeBackend(icon any) *NativeBackend {
beeep.AppName = "Crush"
return &NativeBackend{
icon: icon,
notifyFunc: beeep.Notify,
}
}
// Send sends a desktop notification using the native OS notification system.
func (b *NativeBackend) Send(n Notification) error {
slog.Debug("Sending native notification", "title", n.Title, "message", n.Message)
err := b.notifyFunc(n.Title, n.Message, b.icon)
if err != nil {
slog.Error("Failed to send notification", "error", err)
} else {
slog.Debug("Notification sent successfully")
}
return err
}
// SetNotifyFunc allows replacing the notification function for testing.
func (b *NativeBackend) SetNotifyFunc(fn func(title, message string, icon any) error) {
b.notifyFunc = fn
}
// ResetNotifyFunc resets the notification function to the default.
func (b *NativeBackend) ResetNotifyFunc() {
b.notifyFunc = beeep.Notify
}