go-nativenotify

Native notifications in Go
Log | Files | Refs | README | LICENSE

commit 3f58b254ee518eb1b1168e869979526ba191d7f1
parent 6261410571dec47ea327669f15cbcccb95ee9b4f
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Fri, 17 Jan 2025 14:28:58 +0800

notify.Push: enforce ID fields

This is important since the ID names the actions and the parent
notification.

I suppose we could provide default names (e.g. numbers), but this is
more explicit.

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>

Diffstat:
Mnotify.go | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/notify.go b/notify.go @@ -16,6 +16,8 @@ package nativenotify import ( + "fmt" + darwinnotify "git.sr.ht/~jackmordaunt/go-notify-darwin" windowsnotify "git.sr.ht/~jackmordaunt/go-toast/v2" ) @@ -115,5 +117,18 @@ func Setup(cfg Config) error { // Push a notification to the operating system. func Push(n Notification) error { + if n.ID == "" { + return fmt.Errorf("notification requires ID") + } + for ii, a := range n.ButtonActions { + if a.ID == "" { + return fmt.Errorf("buttonaction %d requires ID", ii) + } + } + for ii, a := range n.TextActions { + if a.ID == "" { + return fmt.Errorf("text action %d requires ID", ii) + } + } return push(n) }