mordaunt.dev/code

code / go-toast

go-toast

Send toast notifications in Windows

  • Go
  • Library
  • Notifications
  • Windows
  • Native
  • Windows-Runtime
  • COM
  • Bindings
  • Desktop
  • Toast
clone
https://mordaunt.dev/code/go-toast
release
v2.0.32025-01-1767 commits
license
Unlicense OR MIT
activity
0 commitsthis year, since 2023

This package implements Windows toast notifications using the Windows Runtime COM API.

The XML schema used to describe such notifications is here:

https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts

Package wintoast offers a lower-level api. Package toast offers a higher-level wrapper.

wintoast uses build tags to guard Windows only code. It will still compile on non-Windows platforms, however the functions are stubbed out and will do nothing when invoked.

Usage

Basic

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.

// 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()

Changelog

full log
v2.0.32025-01-17

release

  • d322c5bwintoast: add appData symbol to noop
v2.0.22025-01-17

use global AppID if present

  • ec285b3wintoast: use global appID if set
v2.0.12024-10-28

gracefully handle Windows 7

  • c818d2awintoast.pushCOM: disable notifications when unsupported
v2.0.02024-10-07

Add extra styling features and changed SetAppData requirements

  • 637ac23toast: update to v2
  • 86a0d74toast.Notification.Push: do not auto-call SetAppData
  • 7388b44toast,wintoast: supply AppID directly
  • 51d49c7toast: support extra styling features
  • 168cffftmpl: support more styling features
  • 5652411tmpl: add xml declaration
  • and 2 more
v1.1.22024-01-26

better error message

  • 9ca375awintoast: display app id in error message
v1.1.12023-12-07

Fix broken compile.

  • df90b95toast: synchronize AppData
v1.1.02023-12-05

use auto-generated COM definitions

  • e536997wintoast: avoid clobbering existing keys
  • a452fa2wintoast: simplify init guard
  • d9dbb39wintoast: use windows utf16 helpers
  • 96c7350wintoast: use generated COM definitions
  • eb13cd6winrt: add auto-generated COM definitions
  • ec05443go mod tidy
  • and 1 more
v1.0.12023-10-03

user broader permissions

  • 61088f7wintoast: request ALL_ACCESS permissions
v1.0.02023-03-22

v1.0.0

  • 5431b83toast,wintoast: dry up AppData definition
  • cec7e6ewintoast: allow per app GUID override
  • ce23bc2wintoast: refer to toast for docs
  • fc617a9toast: explain extra flag that WinRT passes on activation
  • 6327a24toast: remove superfluous constant
  • 4d4e3c9readme: explain the packages
  • and 3 more
v0.3.02023-03-21

v0.3.0

  • 3126322toast: avoid setting default backgroundcolor
  • d1b15c7bind: use the global app.ID if set
  • a09f8f0bind: more precise early out
v0.2.02023-03-21

v0.2.0 add global function for setting app data

  • 5b500eeexamples/toast-cli: add activation exe to flag set
  • 2fb0180bind: test registry manipulation
  • 2452806bind: allow for overlapping usecases
  • a1588bctoast: allow globally setting app data
v0.1.22023-03-20

v0.1.2

    v0.1.12023-03-20

    v0.1.1

    • 8dd2fc0fixup module name
    • 9f23965ARCHITECTURE: attempt to explain the details of this package
    v0.1.02023-03-17

    v0.1.0

    • 2ed479fexamples/toast-cli: default to background activation type
    • d2b1e55toast: remove DisplayName
    • c6470b0toast: document ActivationType
    • a5c9562toast: remove obsolete generation command
    • 86718a8bind: explain cookie out param
    • e7c0fafbind: remove obsolete comment
    • and 24 more

    Mirrored to sourcehut and GitHub.