go-toast

Send toast notifications in Windows
Log | Files | Refs | README | LICENSE

commit d6faf9262fe99079bb0686c5f111fec31e89c335
parent adcdbf00e925bbf613aee84cb94d28f7b2ec5228
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Wed, 15 Mar 2023 14:54:14 +0800

toast: add arguments to activation callback

Allow the caller to accesse the response data.

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

Diffstat:
Mcmd/toast-cli/main.go | 4++--
Mtoast.go | 21++++++++++++++-------
2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/cmd/toast-cli/main.go b/cmd/toast-cli/main.go @@ -79,13 +79,13 @@ func main() { <-done }() - n.OnActivate = func() { + n.OnActivate = func(_ string, _ []toast.UserData) { fmt.Printf("OnActivate\n") done <- struct{}{} } } else { - n.OnActivate = func() { + n.OnActivate = func(_ string, _ []toast.UserData) { fmt.Printf("OnActivate\n") } } diff --git a/toast.go b/toast.go @@ -79,9 +79,19 @@ type Notification struct { // How long the toast should show up for (short/long) Duration toastDuration - OnActivate func() + // This is an absolute path to an executable that will launched by the + // Windows Runtime when the COM server is not running. + ActivationExe string + + // OnActivate is a global activation callback. If supplied, it will be invoked when + // any notification is activated, not necessary _this_ one. + OnActivate func(args string, data []UserData) } +// UserData contains user supplied data from the notification, such as text input +// or a selection. +type UserData = bind.UserData + // Input // // Defines an input element, generally a text input. @@ -163,14 +173,11 @@ func (n *Notification) Push() error { return err } if n.OnActivate != nil { - bind.SetActivationCallback(func(appUserModelId, invokedArgs string, userData []bind.UserData) { - fmt.Printf("appUserModelId: %q\n", appUserModelId) - fmt.Printf("invokedArgs: %q\n", invokedArgs) - fmt.Printf("userData: %q\n", userData) - n.OnActivate() + bind.SetActivationCallback(func(_, args string, data []bind.UserData) { + n.OnActivate(args, data) }) } - if err := bind.ConfigureRegistry(n.AppID, n.AppID, "FFFFFFFF", ""); err != nil { + if err := bind.ConfigureRegistry(n.AppID, n.AppID, n.IconBackgroundColor, n.ActivationExe); err != nil { return fmt.Errorf("configuring registry: %w", err) } return bind.GenerateToast(n.AppID, xml)