notify

package
v0.2.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

type Action struct {
	Key   string
	Label string
}

Action is one notification action: the key the daemon reports back on activation and the label its button shows.

type Bus added in v0.2.5

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 added in v0.2.5

func NewWithDial(dial func() (Bus, error)) *Notifier

NewWithDial is New over another bus.

func (*Notifier) Close

func (n *Notifier) Close(id string)

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

func (n *Notifier) OnAction(fn func(id, action string))

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.

type Priority

type Priority uint8

Priority is the notification's importance, mapped to the portal's priority strings and the classic spec's urgency byte.

const (
	// Low is background information.
	Low Priority = iota
	// Normal is the default.
	Normal
	// High demands attention; classic daemons may let it through
	// do-not-disturb.
	High
	// Critical is High plus (on the classic spec) a request to not
	// expire.
	Critical
)

Priorities.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL