// Show sends the information in the notification object to the server to be // displayed. func (n Notification) Show() (id uint32, err error) { conn, err := dbus.SessionBus() if err != nil { return } // We need to convert the interface type of the map to dbus.Variant as // people dont want to have to import the dbus package just to make use // of the notification hints. hints := map[string]dbus.Variant{} for k, v := range n.Hints { hints[k] = dbus.MakeVariant(v) } obj := conn.Object(DbusInterfacePath, DbusObjectPath) call := obj.Call( CallNotify, 0, n.AppName, n.ReplacesID, n.AppIcon, n.Summary, n.Body, n.Actions, hints, n.Timeout) if err = call.Err; err != nil { return } err = call.Store(&id) return }
// CloseNotification closes the notification if it exists using its id. func CloseNotification(id uint32) (err error) { conn, err := dbus.SessionBus() if err != nil { return } obj := conn.Object(DbusInterfacePath, DbusObjectPath) call := obj.Call(CallCloseNotification, 0, id) err = call.Err return }
// GetCapabilities returns the capabilities of the notification server. func GetCapabilities() (c Capabilities, err error) { conn, err := dbus.SessionBus() if err != nil { return } obj := conn.Object(DbusInterfacePath, DbusObjectPath) call := obj.Call(CallGetCapabilities, 0) if err = call.Err; err != nil { return } s := []string{} if err = call.Store(&s); err != nil { return } for _, v := range s { switch v { case "action-icons": c.ActionIcons = true break case "actions": c.Actions = true break case "body": c.Body = true break case "body-hyperlinks": c.BodyHyperlinks = true break case "body-images": c.BodyImages = true break case "body-markup": c.BodyMarkup = true break case "icon-multi": c.IconMulti = true break case "icon-static": c.IconStatic = true break case "persistence": c.Persistence = true break case "sound": c.Sound = true break } } return }
func newDesktopNotifications() *desktopNotifications { if _, err := dbus.SessionBus(); err != nil { log.Printf("Error enabling dbus based notifications! %+v\n", err) return nil } dn := new(desktopNotifications) dn.notifications = make(map[string]uint32) dn.notificationStyle = "with-author-but-no-content" dn.notificationUrgent = true dn.notificationExpires = false return dn }
// GetServerInformation returns information about the notification server such // as its name and version. func GetServerInformation() (i ServerInformation, err error) { conn, err := dbus.SessionBus() if err != nil { return } obj := conn.Object(DbusInterfacePath, DbusObjectPath) call := obj.Call(CallGetServerInformation, 0) if err = call.Err; err != nil { return } err = call.Store(&i.Name, &i.Vendor, &i.Version, &i.SpecVersion) return }