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 do-not-disturb with its focus rules: a schedule, sharing and fullscreen, and what still pops up.
Index ¶
- Constants
- Variables
- func ServeLysShell(conn *dbus.Conn, svc *Service) (func(), error)
- func StorePath() (string, error)
- type Action
- type ActionInvocation
- type Clock
- type ClosedReason
- type Closure
- type Event
- type EventKind
- type Focus
- type FocusReason
- type InlineReply
- type Key
- type ListRow
- type Notification
- type Progress
- type Server
- func (s *Server) CloseNotification(id uint32) *dbus.Error
- func (s *Server) GetCapabilities() ([]string, *dbus.Error)
- func (s *Server) GetServerInformation() (string, string, string, string, *dbus.Error)
- func (s *Server) Notify(appName string, replacesID uint32, appIcon, summary, body string, ...) (uint32, *dbus.Error)
- func (s *Server) Release() error
- type Service
- func (s *Service) AttachStore(st *Store) error
- func (s *Service) Audible(n *Notification) bool
- func (s *Service) ClockJumped()
- func (s *Service) Close(id uint32, reason ClosedReason)
- func (s *Service) Count() int
- func (s *Service) DND() bool
- func (s *Service) Detach(change func())
- func (s *Service) Dismiss(ids []uint32)
- func (s *Service) DismissAll()
- func (s *Service) DismissPopup(id uint32)
- func (s *Service) FlushWrites(timeout time.Duration)
- func (s *Service) Focus() Focus
- func (s *Service) HistoryChanges() (<-chan struct{}, func())
- func (s *Service) InhibitPopup(id uint32)
- func (s *Service) InvokeAction(id uint32, key, token string)
- func (s *Service) Notify(appName string, replacesID uint32, appIcon, summary, body string, ...) uint32
- func (s *Service) NotifyHints(appName string, replacesID uint32, appIcon, summary, body string, ...) uint32
- func (s *Service) Page(before *Key, limit int) ([]*Notification, error)
- func (s *Service) Popups() []*Notification
- func (s *Service) ReleasePopup(id uint32)
- func (s *Service) Reply(id uint32, text string) bool
- func (s *Service) SetBlocklist(patterns []string)
- func (s *Service) SetDND(on bool)
- func (s *Service) SetDNDUntil(until time.Time)
- func (s *Service) SetEmitter(fn func(signal string, args ...any))
- func (s *Service) SetFocusRules(r notifypolicy.FocusRules)
- func (s *Service) SetFullscreen(on bool)
- func (s *Service) SetHistoryLimits(memory notifypolicy.MemoryLimit, stored notifypolicy.StoredLimit)
- func (s *Service) SetPopupDuration(d time.Duration)
- func (s *Service) SetRemoveExpired(on bool)
- func (s *Service) SetSharing(on bool)
- func (s *Service) Shutdown(timeout time.Duration) error
- func (s *Service) Subscribe() (<-chan Event, func())
- func (s *Service) ToggleDND() bool
- func (s *Service) UseClock(c Clock)
- func (s *Service) Verdict(n *Notification) Verdict
- type Store
- func (st *Store) Add(n *Notification, prune int) error
- func (st *Store) Close() error
- func (st *Store) Count() (int, error)
- func (st *Store) Find(id uint32) (*Notification, bool, error)
- func (st *Store) MaxID() (uint32, error)
- func (st *Store) Page(before *Key, limit int) ([]*Notification, error)
- func (st *Store) Prune(n int) (int, error)
- func (st *Store) Remove(ids []uint32) ([]uint32, error)
- func (st *Store) RemoveAll() error
- func (st *Store) SweepExpired(now time.Time) (int, error)
- type TokenGrant
- type Urgency
- type Verdict
Constants ¶
const ( LysShellName = "dev.stubbe.lys.Notifications1" LysShellPath = dbus.ObjectPath("/dev/stubbe/lys/Notifications") )
lys-shell's control extension, which `lys-shell notify` drives.
const ( Interface = "org.freedesktop.Notifications" ObjPath = "/org/freedesktop/Notifications" ServerName = identity.Name ServerVendor = identity.Name SpecVersion = "1.2" )
D-Bus identity and server information.
const ActionPurposesHint = "x-lys-action-purposes"
ActionPurposesHint is lys-shell's a{ss} hint from action id to the button purpose a portal notification gave it (call.accept, call.decline, call.hang-up).
const DefaultActionID = "default"
DefaultActionID is the spec's body-click action.
const DefaultPopupDuration = 5000 * time.Millisecond
DefaultPopupDuration is the popup display time until the shell sets its configured one.
const InlineReplyActionID = "inline-reply"
InlineReplyActionID is KDE's inline-reply action key: the card shows a reply field for it, and the reply comes back as NotificationReplied.
const MaxPage = 500
MaxPage is the most notifications one page returns.
Variables ¶
var ( ActionInvoked = dbusx.NewSignal[ActionInvocation](Interface, "ActionInvoked") ActivationToken = dbusx.NewSignal[TokenGrant](Interface, "ActivationToken") NotificationReplied = dbusx.NewSignal[InlineReply](Interface, "NotificationReplied") NotificationClosed = dbusx.NewSignal[Closure](Interface, "NotificationClosed") )
The signals a notification server sends from ObjPath.
var Capabilities = []string{
"body",
"body-markup",
"body-hyperlinks",
"actions",
"icon-static",
"persistence",
"inline-reply",
"sound",
}
Capabilities the server advertises.
var ServerVersion = buildinfo.Version()
ServerVersion is the release GetServerInformation reports.
Functions ¶
func ServeLysShell ¶
ServeLysShell exports dev.stubbe.lys.Notifications1 over svc.
Types ¶
type Action ¶
Action is one notification action: the id ActionInvoked reports, its label, and what the button does when the sender said (ActionPurposesHint), which styles it.
func ParseActions ¶
ParseActions reads the flat id, label, ... list as pairs; a trailing id without a label labels itself.
type ActionInvocation ¶
ActionInvocation is what ActionInvoked carries: the notification and the key of the action the user picked.
type Clock ¶
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
// IDs names what one EventRemove took out of the history, in the
// order it was asked to. Entries a clear-all found only on disk are
// not named, so it can be empty.
IDs []uint32
Reason ClosedReason
// Replaced is an EventAdd that took the place of a notification the
// app already had (replaces_id or a stack tag).
Replaced bool
}
Event is the service's change feed.
type Focus ¶
type Focus struct {
On bool
Reason FocusReason
Until time.Time
}
Focus is the do-not-disturb state as the shell shows it: on or off, why, and until when (zero when it lasts until something else changes).
type FocusReason ¶
type FocusReason uint8
FocusReason is why do-not-disturb is on or off.
const ( FocusOff FocusReason = iota FocusManual FocusUntil FocusOverride FocusScheduled FocusSharing FocusFullscreen )
The reasons.
func (FocusReason) String ¶
func (r FocusReason) String() string
type InlineReply ¶
InlineReply is what NotificationReplied carries: the notification and the text the user typed into it.
type Key ¶
Key orders the history, the store's (timestamp, id) index: arrival in Unix milliseconds, then id, which breaks ties within a millisecond.
type ListRow ¶
ListRow is one List row: (id, arrival in Unix milliseconds, app, summary, body). The last row's (Stamp, ID) is the next page's cursor.
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.
ReplacesID uint32
// Progress is the value hint.
Progress Progress
// StackTag is the x-dunst-stack-tag or x-canonical-private-synchronous
// hint: a new notification with the same tag from the same app
// replaces this one.
StackTag string
// ReplyPlaceholder is x-kde-reply-placeholder-text, the reply field's
// hint text.
ReplyPlaceholder string
// SoundFile and SoundName are the sound-file and sound-name hints:
// a file to play, or a sound theme name.
SoundFile string
SoundName string
// SuppressSound is the suppress-sound hint.
SuppressSound bool
}
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) InlineReply ¶
func (n *Notification) InlineReply() (Action, bool)
InlineReply is the inline-reply action, when the sender offered one.
func (*Notification) Key ¶
func (n *Notification) Key() Key
Key is the notification's place in the history.
func (*Notification) String ¶
func (n *Notification) String() string
String renders the summary for logs and tests.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress is the value hint: a share of 0-100 percent, or none.
func NewProgress ¶
NewProgress is percent, clamped to 0-100 as every server draws it.
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 (*Server) CloseNotification ¶
CloseNotification handles the spec's CloseNotification call; an unknown id is not an error (the spec leaves it to the server).
func (*Server) GetCapabilities ¶
GetCapabilities handles the spec's GetCapabilities call.
func (*Server) GetServerInformation ¶
GetServerInformation handles the spec's information call.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service holds the state and serves the D-Bus interface.
func NewService ¶
NewService restores the manual do-not-disturb flag from the state dir and keeps time by c, whose zone the do-not-disturb schedule is read in.
func (*Service) AttachStore ¶
AttachStore persists the history in st and restores what it holds, before the first notification arrives: with remove-expired, what expired while lys-shell was down leaves the store, and the rest arms its expiry; the newest entries up to the memory limit fill the in-memory window, the rest stay on disk; a lowered stored limit prunes the oldest; new ids continue past the highest stored one. Restored notifications do not pop up again.
func (*Service) Audible ¶
func (s *Service) Audible(n *Notification) bool
Audible reports whether n may make a sound now: do-not-disturb lets it pop up and the screen is not shared or recorded, whatever the rules say about popups while sharing.
func (*Service) ClockJumped ¶
func (s *Service) ClockJumped()
ClockJumped re-evaluates the schedule after the wall clock jumped (a resume, a step, a time-zone change).
func (*Service) Close ¶
func (s *Service) Close(id uint32, reason ClosedReason)
Close removes a notification, in memory or only in the store, 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.
func (*Service) Detach ¶
func (s *Service) Detach(change func())
Detach runs change, a call that changes the service, on its own goroutine: a caller on the UI loop waits for neither the store queue nor the bus. FlushWrites waits for it as for the writes it queues.
func (*Service) Dismiss ¶
Dismiss closes every notification ids names with the dismissed reason, in memory, on the popup list and in the store in one write: a popup stack's clear all and a history group's clear.
func (*Service) DismissAll ¶
func (s *Service) DismissAll()
DismissAll empties the history, the store included, and the popup list with the dismissed reason. The closed signal goes out for the in-memory window: the entries only on disk are past any app's interest, and a signal each would flood the bus.
func (*Service) DismissPopup ¶
DismissPopup hides a popup, keeping the notification in the history.
func (*Service) FlushWrites ¶
FlushWrites waits for the detached changes running and the writes queued so far, theirs included, or for timeout. It is for shutdown, off the loop.
func (*Service) HistoryChanges ¶
func (s *Service) HistoryChanges() (<-chan struct{}, func())
HistoryChanges ticks after the history changed. A pending tick absorbs the next, so nothing is dropped: whoever rereads the history on a tick has seen the last change. stop ends the feed.
func (*Service) InhibitPopup ¶
InhibitPopup pauses a popup's countdown, keeping the time left, while the pointer is over the card.
func (*Service) InvokeAction ¶
InvokeAction emits ActionInvoked and, unless the notification is resident, closes it with the closed reason. A token minted from the press goes first as ActivationToken, as the spec orders them, so the app can raise its window; "" sends none. An entry only in the store is read from it.
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, in memory or in the store; any other replaces_id gets a new id. A blocked app name consumes the notification and still returns an id. A transient notification pops up but skips the history. The hints are parsed into the typed fields and not kept.
func (*Service) Page ¶
func (s *Service) Page(before *Key, limit int) ([]*Notification, error)
Page reads up to limit history entries strictly older than before (nil: from the newest), newest first: from memory, then, past the in-memory window, from the store by its (timestamp, id) index. A short page is the end of the history.
func (*Service) Popups ¶
func (s *Service) Popups() []*Notification
Popups snapshots the visible popup list, newest first. DND keeps new notifications off it; popups already shown when DND turns on stay until they time out or are dismissed.
func (*Service) ReleasePopup ¶
ReleasePopup resumes a paused countdown with the time it had left, dropping the popup at once when none remained. A running or unknown countdown is left alone.
func (*Service) Reply ¶
Reply sends text as the reply to id's inline-reply action (NotificationReplied) and closes it as dismissed; false when id names no notification offering one.
func (*Service) SetBlocklist ¶
SetBlocklist replaces the app-name glob blocklist.
func (*Service) SetDND ¶
SetDND turns do-not-disturb on or off by hand. While a rule holds it on (a schedule, a share, a fullscreen window), the choice overrides the rules until their state next changes; otherwise it is the sticky manual state, persisted across restarts.
func (*Service) SetDNDUntil ¶
SetDNDUntil turns do-not-disturb on until until, after which the rules and the manual state apply again.
func (*Service) SetEmitter ¶
SetEmitter wires the D-Bus signal callback (server-side only).
func (*Service) SetFocusRules ¶
func (s *Service) SetFocusRules(r notifypolicy.FocusRules)
SetFocusRules replaces the do-not-disturb rules.
func (*Service) SetFullscreen ¶
SetFullscreen tells whether a window is fullscreen. A change ends an override that lasted until the rules changed.
func (*Service) SetHistoryLimits ¶
func (s *Service) SetHistoryLimits(memory notifypolicy.MemoryLimit, stored notifypolicy.StoredLimit)
SetHistoryLimits bounds the history: memory newest entries stay in memory, stored on disk. Lowering either applies at once.
func (*Service) SetPopupDuration ¶
SetPopupDuration sets how long a popup shows; it applies to popups that arrive afterwards.
func (*Service) SetRemoveExpired ¶
SetRemoveExpired toggles auto-removal of expired history entries.
func (*Service) SetSharing ¶
SetSharing tells whether the screen is shared or recorded. A change ends an override that lasted until the rules changed.
func (*Service) Shutdown ¶
Shutdown ends the history's persistence: the store is let go, the changes and writes queued so far land as FlushWrites waits for them, and the store closes. The history carries on in memory.
func (*Service) Subscribe ¶
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, so one that acts only on some kinds follows HistoryChanges instead. stop ends the feed.
func (*Service) UseClock ¶
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.
func (*Service) Verdict ¶
func (s *Service) Verdict(n *Notification) Verdict
Verdict is what do-not-disturb lets n do now.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the notification history on disk, a sqlite file, so the history survives a restart.
func OpenStore ¶
OpenStore opens (creating or migrating if needed) the history at path; tests pass a temporary file.
func (*Store) Add ¶
func (st *Store) Add(n *Notification, prune int) error
Add stores or replaces one notification (INSERT OR REPLACE by id) and, in the same transaction, drops the prune oldest rows the retention limit no longer keeps.
func (*Store) Count ¶
Count is how many notifications the store holds; read once, when the service attaches.
func (*Store) Find ¶
func (st *Store) Find(id uint32) (*Notification, bool, error)
Find reads one notification by id.
func (*Store) Page ¶
func (st *Store) Page(before *Key, limit int) ([]*Notification, error)
Page reads up to limit notifications strictly older than before (nil: from the newest), newest first.
func (*Store) Prune ¶
Prune deletes the n oldest notifications in batches of deleteBatch, each its own transaction, reporting how many it deleted.
type TokenGrant ¶
TokenGrant is what ActivationToken carries: the notification and the token minted from the press on it.
type Urgency ¶
type Urgency uint8
Urgency is the spec's urgency hint.
func UrgencyFromByte ¶
UrgencyFromByte reads the urgency hint: 0 low, 2 critical, anything else normal.