Documentation
¶
Overview ¶
Package notify sends desktop notifications: the xdg-desktop-portal Notification interface when a portal owns the desktop, org.freedesktop.Notifications (the GNOME spec every daemon implements) as the fallback, and nothing at all without a session bus - the appearance.md failure model, inert and logged at Debug. Pure Go over the existing godbus dependency.
Threading matches internal/portalsettings: Notify blocks on the bus call and belongs off the Wayland loop goroutine; OnAction and OnClosed callbacks run serialized on the notifier's own goroutine, and the application bridges onto its loop with Invoke. Every method is safe from any goroutine once New returned.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
Action is one notification action: the key the daemon reports back on activation and the label its button shows.
type CloseReason ¶
type CloseReason uint8
CloseReason names why a notification closed, from the classic spec's reason codes (the portal reports no reasons).
const ( ReasonExpired CloseReason = 1 ReasonDismissed CloseReason = 2 ReasonClosedByCall CloseReason = 3 ReasonUnspecified CloseReason = 4 )
Close reasons, the classic spec's codes.
type Notification ¶
type Notification struct {
Title string
Body string
Icon string
Priority Priority
Timeout time.Duration
Actions []Action
// DefaultAction, when set with a key, makes the notification body
// itself activatable; the portal wire also carries its label.
DefaultAction Action
HasDefault bool
}
Notification is one desktop notification. Title and Body are plain text (markup is the daemon's business, not the spec's); Icon is an icon-theme name or a file path, resolved by whoever shows it; Timeout of zero means the server default, negative means never expire (classic spec behavior; portals may ignore it).
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier owns one session-bus connection and sends notifications through the best transport it found at startup. Without a bus (or with neither name owned) it is inert: Notify is a no-op that still returns an id, callbacks never fire, and Close is a no-op.
func New ¶
func New() *Notifier
New probes the session bus once and returns the notifier: portal transport when the desktop portal owns its name, the classic spec when its daemon does, and an inert notifier without a bus. The probe itself is bounded by callTimeout; New blocks that long at most.
func (*Notifier) Close ¶
Close withdraws a still-shown notification; unknown ids and inert notifiers are no-ops.
func (*Notifier) Notify ¶
func (n *Notifier) Notify(nf Notification) string
Notify sends nf and returns its id: stable across transports, safe to hand to Close. It blocks on the bus call (bounded); without a transport it returns the id without sending. The body is capped at maxBodyRunes runes.
func (*Notifier) OnAction ¶
OnAction registers the activation callback (id, action key); nil disables. It fires on the signal goroutine.
func (*Notifier) OnClosed ¶
func (n *Notifier) OnClosed(fn func(id string, reason CloseReason))
OnClosed registers the close callback; nil disables.