Documentation
¶
Overview ¶
Package notify is a wrapper around godbus for dbus notification interface See: https://developer.gnome.org/notification-spec/ and https://github.com/godbus/dbus
The package provides exported methods for simple usage, e.g. just show a notification. It also provides the interface Notifier that includes event delivery for notifications. Note that if you use New() to create a notifier, it is the caller responsibility to also drain the channels for ActionInvoked() and NotificationClosed().
Each notification created is allocated a unique ID by the server (see Notification). This ID is unique within the dbus session, and is an increasing number. While the notification server is running, the ID will not be recycled unless the capacity of a uint32 is exceeded.
The ID can be used to hide the notification before the expiration timeout is reached (see CloseNotification).
The ID can also be used to atomically replace the notification with another (Notification.ReplaceID). This allows you to (for instance) modify the contents of a notification while it's on-screen.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCapabilities ¶
GetCapabilities gets the capabilities of the notification server. This call takes no parameters. It returns an array of strings. Each string describes an optional capability implemented by the server.
See also: https://developer.gnome.org/notification-spec/ GetCapabilities provide an exported method for this operation
func SendNotification ¶
func SendNotification(conn *dbus.Conn, note Notification) (uint32, error)
SendNotification is provided for convenience. Use if you only want to deliver a notification and dont care about events.
Types ¶
type ActionInvokedSignal ¶
type Notification ¶
type Notification struct { AppName string ReplacesID uint32 // (atomically) replaces notification with this ID. Optional. AppIcon string // See icons here: http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html Optional. Summary string Body string Actions []string // tuples of (action_key, label), e.g.: []string{"cancel", "Cancel", "open", "Open"} Hints map[string]dbus.Variant ExpireTimeout int32 // milliseconds to show notification }
Notification holds all information needed for creating a notification
type Notifier ¶
type Notifier interface { SendNotification(n Notification) (uint32, error) GetCapabilities() ([]string, error) GetServerInformation() (ServerInformation, error) CloseNotification(id int) (bool, error) NotificationClosed() <-chan *NotificationClosedSignal ActionInvoked() <-chan *ActionInvokedSignal Close() error }
Notifier is an interface for implementing the operations supported by the freedesktop DBus Notifications object.
New() sets up a Notifier that listens on dbus' signals regarding Notifications: NotificationClosed and ActionInvoked.
Note this also means the caller MUST consume output from these channels, given in methods NotificationClosed() and ActionInvoked(). Users that only want to send a simple notification, but don't care about interactions, see exported method: SendNotification(conn, Notification)
Caller is also responsible to call Close() before exiting, to shut down event loop and cleanup.
type Reason ¶
type Reason uint32
Reason for the closed notification
const ( // ReasonExpired when a notification expired ReasonExpired Reason = 1 // ReasonDismissedByUser when a notification has been dismissed by a user ReasonDismissedByUser Reason = 2 // ReasonClosedByCall when a notification has been closed by a call to CloseNotification ReasonClosedByCall Reason = 3 // ReasonUnknown when as notification has been closed for an unknown reason ReasonUnknown Reason = 4 )
type ServerInformation ¶
ServerInformation is a holder for information returned by GetServerInformation call.
func GetServerInformation ¶
func GetServerInformation(conn *dbus.Conn) (ServerInformation, error)
GetServerInformation returns the information on the server.
org.freedesktop.Notifications.GetServerInformation
GetServerInformation Return Values Name Type Description name STRING The product name of the server. vendor STRING The vendor name. For example, "KDE," "GNOME," "freedesktop.org," or "Microsoft." version STRING The server's version number. spec_version STRING The specification version the server is compliant with.