notifications

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 25 Imported by: 1 module, 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 notifications is the desktop notification service: the org.freedesktop.Notifications server, the stored history, the popup list with its pausable countdowns, and the sticky do-not-disturb state.

Index

Constants

View Source
const (
	LysShellName = "dev.stubbe.lys.Notifications1"
	LysShellPath = dbus.ObjectPath("/dev/stubbe/lys/Notifications")
)

lys-shell's control extension, which `lys-shell notify` drives (wayle-notification/src/lys_shell_daemon.rs).

View Source
const (
	Interface     = "org.freedesktop.Notifications"
	ObjPath       = "/org/freedesktop/Notifications"
	ServerName    = "lys-shell"
	ServerVendor  = "lys-shell"
	ServerVersion = version.Version
	SpecVersion   = "1.2"
)

D-Bus identity and server information.

View Source
const DefaultActionID = "default"

DefaultActionID is the spec's body-click action.

View Source
const DefaultPopupDuration = 5000 * time.Millisecond

DefaultPopupDuration is the popup display time until the shell sets its configured one (builder.rs's popup_duration default).

Variables

View Source
var Capabilities = []string{
	"body",
	"body-markup",
	"actions",
	"icon-static",
	"persistence",
}

Capabilities the server advertises (daemon.rs).

Functions

func ServeLysShell

func ServeLysShell(conn *dbus.Conn, svc *Service) (func(), error)

ServeLysShell exports dev.stubbe.lys.Notifications1 over svc.

func StateDir

func StateDir() (string, bool)

StateDir is the DND flag's directory, lys-shell's state dir.

func StorePath

func StorePath() (string, error)

StorePath is persistence.rs's path: $HOME/.local/share/lys-shell/ notifications.db (HOME, not XDG_DATA_HOME, as the Rust store does).

Types

type Action

type Action struct {
	ID    string
	Label string
}

Action is one notification action: the id ActionInvoked reports and its label (core/types.rs's Action).

func ParseActions

func ParseActions(raw []string) []Action

ParseActions is parse_dbus_actions: the flat id, label, ... list as pairs; a trailing id without a label labels itself.

type Clock

type Clock interface {
	Now() time.Time
	// AfterFunc runs fn once d has passed; stop disarms it, reporting
	// whether it was still armed.
	AfterFunc(d time.Duration, fn func()) (stop func() bool)
}

Clock is the service's time source: when a notification arrived, and the popup countdowns and history expiries it arms.

type ClosedReason

type ClosedReason uint32

ClosedReason is the spec's closed reason codes.

const (
	Expired    ClosedReason = 1
	Dismissed  ClosedReason = 2
	ClosedCall ClosedReason = 3
	Unknown    ClosedReason = 4
)

Closed reasons.

type Event

type Event struct {
	Kind   EventKind
	Notif  *Notification
	ID     uint32
	Reason ClosedReason
}

Event is the service's change feed.

type EventKind

type EventKind string

EventKind names a change.

const (
	EventAdd    EventKind = "add"
	EventRemove EventKind = "remove"
	EventDnd    EventKind = "dnd"
	EventAction EventKind = "action"
	// EventPopups is a popup-list change that leaves the history alone:
	// a countdown ran out or a popup was dismissed.
	EventPopups EventKind = "popups"
)

Event kinds.

type ListRow

type ListRow struct {
	ID      uint32
	App     string
	Summary string
	Body    string
}

ListRow is one List row: (id, app, summary, body).

type Notification

type Notification struct {
	ID      uint32
	AppName string
	AppIcon string
	Summary string
	Body    string
	// Actions are the parsed action pairs, the default one included.
	Actions []Action
	Expires time.Time // zero: never
	// ExpireMS is the sender's expire_timeout: negative is the server
	// default, zero never expires, positive is milliseconds.
	ExpireMS int32
	Added    time.Time
	Urgency  Urgency
	// ImagePath is the image-path hint, or the cached PNG of inline
	// image data.
	ImagePath    string
	DesktopEntry string
	// Transient notifications skip the history; resident ones stay
	// after an action is invoked.
	Transient bool
	Resident  bool
	// ReplacesID is the replaces_id the sender passed, and Hints the
	// raw hints but the inline image pixels: what the store keeps.
	ReplacesID uint32
	Hints      map[string]dbus.Variant
}

Notification is one received notification.

func (*Notification) DefaultAction

func (n *Notification) DefaultAction() (Action, bool)

DefaultAction is the "default" action, when the sender offered one.

func (*Notification) Expired

func (n *Notification) Expired(now time.Time) bool

Expired reports whether the expiry elapsed at now.

func (*Notification) String

func (n *Notification) String() string

String renders the summary for logs and tests.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves org.freedesktop.Notifications on the session bus and lys-shell's dev.stubbe.lys.Notifications1 extension beside it.

func Serve

func Serve(conn *dbus.Conn, svc *Service) (*Server, error)

Serve requests the well-known names and exports the objects; Release drops them.

func (*Server) CloseNotification

func (s *Server) CloseNotification(id uint32) *dbus.Error

CloseNotification handles the spec's CloseNotification call; an unknown id is not an error (the spec leaves it to the server).

func (*Server) GetCapabilities

func (s *Server) GetCapabilities() ([]string, *dbus.Error)

GetCapabilities handles the spec's GetCapabilities call.

func (*Server) GetServerInformation

func (s *Server) GetServerInformation() (string, string, string, string, *dbus.Error)

GetServerInformation handles the spec's information call.

func (*Server) Notify

func (s *Server) Notify(appName string, replacesID uint32, appIcon, summary, body string, actions []string, hints map[string]dbus.Variant, expireTimeout int32) (uint32, *dbus.Error)

Notify handles the spec's Notify call.

func (*Server) Release

func (s *Server) Release() error

Release drops the names.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service holds the state and serves the D-Bus interface.

func NewService

func NewService() *Service

NewService restores the DND flag from the state dir.

func (*Service) AttachStore

func (s *Service) AttachStore(st *Store) error

AttachStore persists the history in st and restores what it holds (builder.rs's load_stored_notifications): the stored notifications join the history newest first, their apps own their ids again, new ids continue past the highest stored one, and pending expiries are re-armed. Restored notifications do not pop up again.

func (*Service) Close

func (s *Service) Close(id uint32, reason ClosedReason)

Close removes a notification, emitting the closed signal. Every reason but Expired also takes it off the popup list; an expired history entry leaves its popup to its own countdown (handle_notification_removed).

func (*Service) Count

func (s *Service) Count() int

Count returns the stored count.

func (*Service) DND

func (s *Service) DND() bool

DND reports do-not-disturb.

func (*Service) DismissAll

func (s *Service) DismissAll()

DismissAll empties the history and the popups with the dismissed reason.

func (*Service) DismissPopup

func (s *Service) DismissPopup(id uint32)

DismissPopup hides a popup, keeping the notification in the history (dismiss_popup).

func (*Service) InhibitPopup

func (s *Service) InhibitPopup(id uint32)

InhibitPopup pauses a popup's countdown, keeping the time left (inhibit_popup: the pointer is over the card).

func (*Service) InvokeAction

func (s *Service) InvokeAction(id uint32, key, token string)

InvokeAction emits ActionInvoked and, unless the notification is resident, closes it with the closed reason (Notification::invoke). A token minted from the press goes first as ActivationToken, as the spec orders them, so the app can raise its window; "" sends none.

func (*Service) Notifications

func (s *Service) Notifications() []*Notification

Notifications snapshots the stored history.

func (*Service) Notify

func (s *Service) Notify(appName string, replacesID uint32, appIcon, summary, body string, actions []string, expireTimeout int32) uint32

Notify receives a notification without hints; see NotifyHints.

func (*Service) NotifyHints

func (s *Service) NotifyHints(appName string, replacesID uint32, appIcon, summary, body string, actions []string, rawHints map[string]dbus.Variant, expireTimeout int32) uint32

NotifyHints receives a notification (the D-Bus Notify call). An app may only replace an id it owns; any other replaces_id gets a new id (resolve_id). A blocked app name consumes the notification and still returns an id. A transient notification pops up but skips the history (handle_notification_added); the history is newest first.

func (*Service) Popups

func (s *Service) Popups() []*Notification

Popups snapshots the visible popup list, newest first. DND keeps new notifications off it (handle_popup_added); popups already shown when DND turns on stay until they time out or are dismissed.

func (*Service) ReleasePopup

func (s *Service) ReleasePopup(id uint32)

ReleasePopup resumes a paused countdown with the time it had left, dropping the popup at once when none remained (release_popup). A running or unknown countdown is left alone.

func (*Service) SetBlocklist

func (s *Service) SetBlocklist(patterns []string)

SetBlocklist replaces the app-name glob blocklist.

func (*Service) SetDND

func (s *Service) SetDND(on bool)

SetDND flips do-not-disturb and persists it.

func (*Service) SetEmitter

func (s *Service) SetEmitter(fn func(signal string, args ...any))

SetEmitter wires the D-Bus signal callback (server-side only).

func (*Service) SetPopupDuration

func (s *Service) SetPopupDuration(d time.Duration)

SetPopupDuration sets how long a popup shows (set_popup_duration); it applies to popups that arrive afterwards.

func (*Service) SetRemoveExpired

func (s *Service) SetRemoveExpired(on bool)

SetRemoveExpired toggles auto-removal of expired history entries.

func (*Service) Subscribe

func (s *Service) Subscribe() (<-chan Event, func())

Subscribe returns a new change feed. Every subscriber sees every event (the bar modules on each output and the popup host all follow the one service); a subscriber that falls behind drops events rather than stalling the service, and re-reads the snapshot on the next. stop ends the feed.

func (*Service) ToggleDND

func (s *Service) ToggleDND() bool

ToggleDND flips do-not-disturb, returning the new state.

func (*Service) UseClock

func (s *Service) UseClock(c Clock)

UseClock makes the service keep time by c instead of the wall clock, for a host that drives time itself; call it before the first notification.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the notification history on disk (persistence.rs): the same sqlite file, table, and column encodings the Rust shell writes, so the history survives a restart and a switch between the two.

func OpenStore

func OpenStore(path string) (*Store, error)

OpenStore opens (creating if needed) the history at path; tests pass a temporary file.

func (*Store) Add

func (st *Store) Add(n *Notification) error

Add stores or replaces one notification (INSERT OR REPLACE by id).

func (*Store) Close

func (st *Store) Close() error

Close releases the database.

func (*Store) Load

func (st *Store) Load(now time.Time, removeExpired bool) ([]*Notification, error)

Load reads the history newest first (load_all). With removeExpired, a notification whose positive timeout ran out while lys-shell was not running stays out.

func (*Store) Remove

func (st *Store) Remove(id uint32) error

Remove deletes one notification.

type Urgency

type Urgency uint8

Urgency is the spec's urgency hint (types/notification.rs's Urgency).

const (
	UrgencyLow Urgency = iota
	UrgencyNormal
	UrgencyCritical
)

Urgency levels.

func UrgencyFromByte

func UrgencyFromByte(v byte) Urgency

UrgencyFromByte is From<u8>: 0 low, 2 critical, anything else normal.

Jump to

Keyboard shortcuts

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