go-toast

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

commit 31c31b9b5f48ef5f06d7896f2dfe42e632b225a3
parent ca66597e00d8ff8c034188582deeb9ec66af643a
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Thu, 16 Mar 2023 17:33:31 +0800

readme: update with usage

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

Diffstat:
MREADME.md | 82++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 77 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md @@ -1,8 +1,79 @@ -# Build +# go-toast -`env CC="gcc" go build .` +This package implements Windows toast notifications using the Windows Runtime COM API. -## Pre-requisites +The XML schema used to describe such notifications is here: -- `mingw-w64-gcc` to build the Go code -- MSVC build tools to recompile the .dll +https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts + +## Usage + +### Basic + +```go +noti := toast.Notification{ + AppID: "My cool app", + Title: "Title", + Body: "Body", +} + +err := noti.Push() +``` + +### Actions / Inputs with Callback + +Additionally, we can respond to notification activation with a callback. + +```go +// Set the callback that receives the data from the notification. +// Any data from actions or inputs will be accessible here. +toast.SetActivationCallback(func(args string, data []UserData) { + fmt.Printf("args: %q, data: %v\n", args, data) +}) + +n := toast.Notification{ + AppID: "My cool app", + Title: "Title", + Body: "Body", +} + +n.Inputs = append(n.Inputs, toast.Input{ + ID: "reply-to:john-doe", + Title: "Reply", + Placeholder: "Reply to John Doe", +}) + +n.Inputs = append(n.Inputs, toast.Input{ + ID: "select-action", + Title: "Selection Action", + Placeholder: "Pick an action to perform", + Selections: []toast.InputSelection{ + { + ID: "1", + Content: "do thing one", + }, + { + ID: "2", + Content: "do thing two", + }, + { + ID: "3", + Content: "do thing three", + }, + }, +}) + +n.Actions = append(n.Actions, toast.Action{ + Type: toast.Foreground, + Content: "Send", + Arguments: "send", +}) + +n.Actions = append(n.Actions, toast.Action{ + Type: toast.Foreground, + Content: "Close", + Arguments: "close", +}) + +err := n.Push() +``` +\ No newline at end of file