go-nativenotify

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

commit 8c592f6bb6c989964e6832c7979cc3b229e536c4
parent 95dbb7437773eaf95930456e7bb6e557c0d8dd16
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Wed, 15 Jan 2025 18:13:44 +0800

notify: [linux] capture data in callback

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

Diffstat:
Mnotify_linux.go | 29++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/notify_linux.go b/notify_linux.go @@ -16,6 +16,7 @@ func setup(cfg Config) error { if err != nil { return fmt.Errorf("getting dbus session: %w", err) } + n, err := shout.NewNotifier( conn, cfg.Linux.AppName, @@ -25,13 +26,25 @@ func setup(cfg Config) error { if !ok || fn == nil { return } - fn(err, id, nil) + data := make(map[string]string) + + data["action"] = action + data["target"] = target.String() + data["response"] = response.String() + + for k, v := range platformData { + data[k] = v.String() + } + + fn(err, id, data) }, ) if err != nil { return fmt.Errorf("building notifier: %w", err) } + notifier.Store(&n) + return nil } @@ -44,12 +57,6 @@ func push(n Notification) (err error) { id := nextID.Add(1) - defer func() { - if err == nil { - callbacksPut(&callbacks, strconv.FormatInt(id, 10), n.Callback) - } - }() - buttons := []shout.Button{} for _, a := range n.ButtonActions { @@ -75,5 +82,13 @@ func push(n Notification) (err error) { return fmt.Errorf("sending notification: %w", err) } + callbacksPut(&callbacks, strconv.FormatInt(id, 10), func(err error, id string, userData map[string]string) { + if userData == nil { + userData = make(map[string]string) + } + userData["payload"] = n.AppPayload + n.Callback(err, id, userData) + }) + return nil }