Documentation
¶
Overview ¶
Package notifications is a pure-Go (CGO_ENABLED=0) implementation of the freedesktop.org Desktop Notifications Specification -- the D-Bus service org.freedesktop.Notifications that desktop applications call (via notify-send, libnotify, GLib.Notification, ...) to post transient notification bubbles.
The package is split into a platform-neutral core (this file plus notification.go, hints.go and image.go) that models a Notification and decodes the wire-level hint dictionary and image payloads, a Linux D-Bus server (server_linux.go) that exports the four spec methods and emits the two spec signals over the owned pure-Go github.com/go-freedesktop/dbus, and a pure bridge (./toast) that turns a decoded Notification into a github.com/go-widgets Toast widget so a go-widgets desktop can act as the notification daemon.
Specification: https://specifications.freedesktop.org/notification-spec/latest/
Index ¶
Constants ¶
const ( // BusName is the well-known bus name a notification daemon owns. BusName = "org.freedesktop.Notifications" // ObjectPath is the object path the service is exported at. ObjectPath = "/org/freedesktop/Notifications" // Interface is the D-Bus interface the four methods and two signals // belong to. Interface = "org.freedesktop.Notifications" )
Well-known D-Bus name, object path and interface of the notification service, as mandated by the specification.
const ( MethodNotify = "Notify" MethodCloseNotification = "CloseNotification" MethodGetCapabilities = "GetCapabilities" MethodGetServerInfo = "GetServerInformation" SignalNotificationClosed = "NotificationClosed" SignalActionInvoked = "ActionInvoked" )
The four method member names of the interface.
const ( ServerName = "go-widgets-notifyd" VendorName = "go-freedesktop" Version = "0.3.0" SpecVersion = "1.2" )
Server-information values reported by GetServerInformation. SpecVersion is the version of the notification specification the server implements.
Variables ¶
var ( // ErrBadImageData is returned by decodeImageData when the inline // image-data hint is not a well-formed (iiibiiay) payload. ErrBadImageData = errors.New("notifications: malformed image-data hint") // ErrVectorIcon is returned by LoadImagePath for a scalable (SVG) path: // this pure-raster decoder does not rasterise vector art, so the caller // should fall back to an icon-theme raster lookup or drop the image. ErrVectorIcon = errors.New("notifications: vector (svg) icon path not rasterised") )
Errors returned by the image decoders.
var ErrNameTaken = errors.New("notifications: another daemon already owns " + BusName)
ErrNameTaken is returned by a Server's Export/ExportReplace when another process already owns the org.freedesktop.Notifications name (a notification daemon is already running and, for ExportReplace, refused to yield it). It is defined platform-neutrally so portable callers can classify the outcome on every GOOS.
var ErrUnsupported = errors.New("notifications: D-Bus server is only supported on GOOS=linux")
ErrUnsupported is returned by every Server operation on a non-Linux build. The freedesktop notification service is a Linux desktop-bus service; this stub exists only so the package (and portable callers) cross-compile cleanly for the other desktop targets, GOOS=darwin and windows.
Functions ¶
func Capabilities ¶
func Capabilities() []string
Capabilities returns the notification capabilities this implementation advertises through GetCapabilities. The list is deliberately TRUTHFUL: it names only what the ./toast bridge actually renders --
- "body" : the notification carries a body text distinct from the summary (rendered as a second Toast line);
- "actions" : action buttons are rendered and ActionInvoked is emitted when one is clicked;
- "body-markup" : the body may contain the small hypertext-subset markup the spec defines (the bridge strips the tags to plain text);
- "icon-static" : a static (non-animated) icon or image is rendered beside the text;
- "persistence" : a notification with an infinite / resident lifetime stays on screen until dismissed (a sticky Toast).
Capabilities we do NOT render (sound, action-icons, icon-multi, ...) are omitted so a client is never misled about what the daemon can do.
func DecodeHints ¶
func DecodeHints(n *Notification, hints map[string]dbus.Variant)
DecodeHints folds the Notify hint dictionary into n. Every field is decoded defensively: a missing key leaves the corresponding field at its zero value, and a value of the wrong D-Bus type is ignored rather than propagated as an error, so a malformed client can never break decoding. A nil map is a no-op.
func LoadImagePath ¶
LoadImagePath decodes an on-disk image referenced by a notification "image-path" hint (or a resolved app_icon path) into an *image.RGBA. A "file://" URI prefix is accepted and stripped. Raster formats (PNG, JPEG, GIF) are decoded through the standard library; a ".svg" path returns ErrVectorIcon because this decoder is deliberately pure-raster and drags in no SVG rasteriser. A missing or undecodable file returns the underlying error.
Types ¶
type Action ¶
Action is one entry of the Notify "actions" array: a machine Key the client keys ActionInvoked on, plus the human-readable Label rendered on the button. The reserved key "default" marks the action taken on a plain activation (a click on the notification body rather than a specific button).
type CloseReason ¶
type CloseReason uint32
CloseReason is the reason code carried by the NotificationClosed signal, as enumerated by the specification.
const ( // ReasonExpired: the notification's timeout elapsed. ReasonExpired CloseReason = 1 // ReasonDismissed: the user dismissed the notification. ReasonDismissed CloseReason = 2 // ReasonClosed: the notification was closed by a CloseNotification call. ReasonClosed CloseReason = 3 // ReasonUndefined: closed for some other/undefined reason. ReasonUndefined CloseReason = 4 )
func (CloseReason) String ¶
func (r CloseReason) String() string
String names the close reason for diagnostics.
type Handler ¶
type Handler interface {
OnNotify(n *Notification) uint32
OnClose(id uint32, reason CloseReason)
}
Handler mirrors the Linux Handler interface so portable code compiles on every platform. See the Linux build for the operative documentation.
type Notification ¶
type Notification struct {
// ID is the notification id assigned by the server (0 until assigned).
ID uint32
// AppName is the optional application name (first Notify argument).
AppName string
// ReplacesID is the id of a notification this one replaces (0 = none).
ReplacesID uint32
// AppIcon is the app_icon argument: an icon name (to resolve through an
// icon theme) or a file/URI path.
AppIcon string
// Summary is the single-line title (required by the spec).
Summary string
// Body is the optional multi-line body; it may carry the spec's
// hypertext-subset markup.
Body string
// Actions are the parsed action pairs, in order.
Actions []Action
// ExpireMS is the requested timeout in milliseconds: -1 = server
// default, 0 = never expire (persist until dismissed / closed).
ExpireMS int32
// Urgency is the decoded "urgency" hint (defaults to UrgencyNormal).
Urgency Urgency
// Category is the decoded "category" hint (may be empty).
Category string
// DesktopEntry is the decoded "desktop-entry" hint (may be empty).
DesktopEntry string
// Resident is the decoded "resident" hint: the notification is not
// removed after an action is invoked.
Resident bool
// Transient is the decoded "transient" hint: bypass any persistence.
Transient bool
// Image is the inline image supplied through an "image-data" /
// "image_data" / "icon_data" hint (nil when none was supplied).
Image *image.RGBA
// ImagePath is the decoded "image-path" / "image_path" hint: a path or
// icon name pointing at an image on disk (may be empty).
ImagePath string
}
Notification is a decoded org.freedesktop.Notifications.Notify request: the spec's positional arguments plus everything unpacked from its hint dictionary. It is the platform-neutral value the server hands to a Handler and the ./toast bridge turns into a Toast.
func Decode ¶
func Decode(appName string, replacesID uint32, appIcon, summary, body string, actions []string, hints map[string]dbus.Variant, expireMS int32) *Notification
Decode assembles a Notification from the raw positional arguments of a Notify call and its hint dictionary. It never fails: malformed hints are ignored field by field (see DecodeHints) so a hostile or buggy client can never break the daemon.
func (*Notification) Sticky ¶
func (n *Notification) Sticky() bool
Sticky reports whether the notification should persist on screen until the user acts, rather than auto-expiring: an explicit zero timeout, a resident hint, or critical urgency all make it sticky (unless it is transient).
type Server ¶
type Server struct{}
Server is the non-Linux stand-in for the Linux D-Bus server. Every method is a no-op returning ErrUnsupported.
func (*Server) EmitActionInvoked ¶
EmitActionInvoked reports ErrUnsupported.
func (*Server) EmitClosed ¶
func (s *Server) EmitClosed(id uint32, reason CloseReason) error
EmitClosed reports ErrUnsupported.
func (*Server) Export ¶
Export reports ErrUnsupported: there is no session bus service to export to.
func (*Server) ExportReplace ¶ added in v0.3.0
ExportReplace reports ErrUnsupported (there is no session bus to claim).
type Urgency ¶
type Urgency byte
Urgency is the freedesktop "urgency" hint: a byte ranking how much the notification demands attention. The spec defines exactly three levels.
const ( // UrgencyLow is background information the user need not act on. UrgencyLow Urgency = 0 // UrgencyNormal is the default level for ordinary notifications. UrgencyNormal Urgency = 1 // UrgencyCritical must stay visible until the user acts (it maps to a // resident, error-coloured Toast). UrgencyCritical Urgency = 2 )
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
notifyd
command
Command notifyd is the reference go-widgets notification daemon: it owns the org.freedesktop.Notifications name on the session bus and renders each incoming notification as a go-widgets Toast, driven by the github.com/go-freedesktop/notifications server and its ./toast bridge.
|
Command notifyd is the reference go-widgets notification daemon: it owns the org.freedesktop.Notifications name on the session bus and renders each incoming notification as a go-widgets Toast, driven by the github.com/go-freedesktop/notifications server and its ./toast bridge. |
|
Package toast bridges a decoded freedesktop github.com/go-freedesktop/notifications.Notification onto a github.com/go-widgets/toolkit.Toast widget, so a go-widgets desktop can render notification bubbles and act as the notification daemon.
|
Package toast bridges a decoded freedesktop github.com/go-freedesktop/notifications.Notification onto a github.com/go-widgets/toolkit.Toast widget, so a go-widgets desktop can render notification bubbles and act as the notification daemon. |