Documentation
¶
Overview ¶
Package notify sends desktop notifications over org.freedesktop.Notifications and reports the actions the user takes on them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Action ¶
type Action struct {
Key, Label string
}
Action is one notification action: Key is what the server reports back in ActionInvoked, Label is what the user sees. The key "default" is the action taken when the notification itself is clicked.
type Event ¶
type Event struct {
NoticeID, Action, ActivationToken string
}
Event is an action the user took on a notification this Notifier sent. ActivationToken is the token the server issued for that notification just before the action, or empty when it issued none.
type Message ¶
type Message struct {
NoticeID, Summary, Body string
Urgency byte
Actions []Action
// Covers lists the notice IDs a summary message stands for, so the caller
// can mark each of them notified once it is sent. It is empty for a
// single-notice message and never sent on the wire: Send ignores it.
Covers []string
}
Message is one notification. A summary message has an empty NoticeID. Summary and Body are notice-supplied plain text: Send passes the summary as is and escapes the body only for a server that advertises body-markup. Urgency is the spec's urgency hint: 0 low, 1 normal, 2 critical.
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier sends notifications on one connection and reports the actions taken on them. It is safe for concurrent use; concurrent Sends do not wait for one another.
The ID a signal names is recorded by Send only after the Notify reply reaches it, and godbus hands that reply to Send and a signal right behind it to the reader concurrently. So while a Send is in flight, a signal from the server for an unknown ID is parked rather than dropped; the Send that records the ID replays the parked signals that name it, and once no Send is in flight the rest are known to be foreign and are discarded. No lock is ever held across a bus call.
func New ¶
New subscribes to the notification server's signals on conn and starts the reader that turns them into Events. No server needs to be on the bus: one that appears later is heard. conn must stay open for as long as the Notifier is used (some servers withdraw an application's notifications when its connection goes away); New never closes it. A nil log discards.
func (*Notifier) Events ¶
Events reports the actions taken on this Notifier's notifications. The channel is never closed; it simply goes quiet when the connection ends.
func (*Notifier) Send ¶
Send shows m and returns the ID the server assigned to it. The summary is sent as plain text; the body is escaped only when the server advertises body-markup, and sent as is otherwise. m.Actions are sent in order as key/label pairs. Errors name the notice.
ctx should carry a deadline: a server that accepts the call and never answers is otherwise waited for up to 25 s. A slow or hung server delays only this Send, never another Send or the delivery of Events.