commit e10a42b65df41d825a16058e4607f42f4366b000
parent 3ef5edabcbb24ca04b26245315f0185cd02834ef
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Fri, 17 Jan 2025 14:20:26 +0800
notify: use consistent data naming
The parent notification payload will be named "default". The action
payloads are named after the action itself. The id argument to the
callback will be the parent notification ID.
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Diffstat:
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/notify_darwin.go b/notify_darwin.go
@@ -56,7 +56,7 @@ func push(n Notification) (err error) {
userData = make(darwinnotify.UserData)
)
- userData["payload"] = n.AppPayload
+ userData["default"] = n.AppPayload
for _, button := range n.ButtonActions {
buttons = append(buttons, darwinnotify.Action{
diff --git a/notify_linux.go b/notify_linux.go
@@ -24,12 +24,16 @@ func setup(cfg Config) error {
func(id, action string, platformData map[string]dbus.Variant, target, response dbus.Variant, err error) {
data := make(map[string]string)
- data["action"] = action
- data["target"] = target.String()
- data["response"] = response.String()
+ data[action] = target.String()
+
+ if r := response.String(); r != "" {
+ data["response"] = r
+ }
for k, v := range platformData {
- data[k] = v.String()
+ if s := v.String(); s != "" {
+ data[k] = s
+ }
}
fn, ok := callbacksTake(&callbacks, id)
@@ -62,8 +66,9 @@ func push(n Notification) (err error) {
for _, a := range n.ButtonActions {
buttons = append(buttons, shout.Button{
- Action: a.AppPayload,
+ Action: a.ID,
Label: a.LabelText,
+ Target: a.AppPayload,
})
}
@@ -74,9 +79,9 @@ func push(n Notification) (err error) {
Markup: false,
IconPath: n.Icon,
Priority: shout.Normal,
- DefaultAction: "default",
+ DefaultAction: n.ID,
DefaultActionLabel: "",
- DefaultActionTarget: dbus.Variant{},
+ DefaultActionTarget: dbus.MakeVariant(n.AppPayload),
Buttons: buttons,
ExpirationTimeout: 0,
}); err != nil {
@@ -87,7 +92,7 @@ func push(n Notification) (err error) {
if userData == nil {
userData = make(map[string]string)
}
- userData["payload"] = n.AppPayload
+ userData["default"] = n.AppPayload
n.Callback(err, n.ID, userData)
})
diff --git a/notify_windows.go b/notify_windows.go
@@ -94,7 +94,7 @@ func push(n Notification) (err error) {
// The action data will appear in [userData].
callbacksPut(&callbacks, strconv.FormatInt(id, 10), func(err error, args string, userData map[string]string) {
if n.AppPayload != "" {
- userData["payload"] = n.AppPayload
+ userData["default"] = n.AppPayload
}
n.Callback(err, n.ID, userData)
})