diff options
Diffstat (limited to 'internal/notify')
| -rw-r--r-- | internal/notify/control.go | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/internal/notify/control.go b/internal/notify/control.go index 4783711..a42a14b 100644 --- a/internal/notify/control.go +++ b/internal/notify/control.go @@ -11,14 +11,45 @@ package notify -import "github.com/godbus/dbus/v5" +import ( + "errors" -// control is the private interface notifyctl drives. + "github.com/godbus/dbus/v5" +) + +// control is the private interface notifyctl drives. It exists because the +// freedesktop spec has no close-all, no way to invoke an action, and no +// history to clear. type control struct { svc *Service } +// CloseAll dismisses every live notification, reason 2. func (c *control) CloseAll() *dbus.Error { c.svc.store.DismissAll() return nil } + +// Dismiss closes one live notification, reason 2, which is what a click on the +// X means. +func (c *control) Dismiss(id uint32) *dbus.Error { + c.svc.stopTimer(id) + c.svc.store.Dismiss(id, 2) + return nil +} + +// InvokeAction emits ActionInvoked for a live notification. An inert entry has +// no client left, so it is an error rather than a silent no-op. +func (c *control) InvokeAction(id uint32, key string) *dbus.Error { + if !c.svc.store.Actionable(id) { + return dbus.MakeFailedError(errors.New("notification is no longer live")) + } + c.svc.conn.Emit(dbus.ObjectPath(objPath), iface+".ActionInvoked", id, key) + return nil +} + +// ClearHistory empties the history ring. +func (c *control) ClearHistory() *dbus.Error { + c.svc.store.ClearHistory() + return nil +} |
