diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-15 13:53:34 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-15 13:53:34 +0200 |
| commit | bcf15590f9e43f2d8978cf7cccfbdf3bb66e376f (patch) | |
| tree | bf6d77460dc7025582fc9a486d9271b176cb6e1b /internal/notify | |
| parent | 3bdd5a50c3b8fa0a885dc58a3d0ec64880f95619 (diff) | |
| download | notifyd-bcf15590f9e43f2d8978cf7cccfbdf3bb66e376f.tar.gz notifyd-bcf15590f9e43f2d8978cf7cccfbdf3bb66e376f.zip | |
feat: add the control interface and notifyctl
The private interface carries what the spec cannot: close-all, invoke action
and clear history. notifyctl reads the published files for list and history,
because the files are the interface, and uses D-Bus only for the mutations.
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 +} |
