notify

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 7 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 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

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 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

func (n *Notifier) Close(id string)

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

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 closes the connection; the notifier goes inert.

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