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: every method returns at once and is safe from any goroutine, including the Wayland loop. The dial, the probe and every bus call run in order on the notifier's worker; OnAction and OnClosed callbacks run serialized on the signal goroutine, and the application bridges onto its loop with Invoke.
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 Bus ¶
type Bus interface {
Call(ctx context.Context, dest string, path dbus.ObjectPath, method string, flags dbus.Flags, ret any, args ...any) error
Watch(ctx context.Context, from dbusx.Sender, failed func(error), routes ...dbusx.Route) (stop func() error, err error)
Close() error
}
Bus is the session-bus connection a Notifier sends through. Watch follows the routes' signals from from until ctx ends or stop is called, as dbusx.WatchSignals does.
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 its worker finds on the first send. 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. A queue full of a stuck daemon's work drops the notification with a log.
func New ¶
func New() *Notifier
New returns a notifier over the session bus. It touches no bus: the worker dials and picks the transport on the first send, portal when the desktop portal owns its name, the classic spec when its daemon does, and inert otherwise.
func NewWithDial ¶
NewWithDial is New over another bus.
func (*Notifier) Close ¶
Close queues the withdrawal of a still-shown notification; unknown ids and inert notifiers are no-ops.
func (*Notifier) Notify ¶
func (n *Notifier) Notify(nf Notification) string
Notify queues nf for the worker and returns its id at once: generated here, stable across transports, safe to hand to Close. 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.
func (*Notifier) Shutdown ¶
func (n *Notifier) Shutdown()
Shutdown lets queued notifications go out, within callTimeout in all, then closes the connection; the notifier goes inert. A worker stuck past that keeps its goroutine until the stuck call returns, and the connection closes without waiting for it.