commit a1588bc9486857299402a168e245056e02d87b6b
parent 8dd2fc0797e688957a0d0bafd03066cfbeca2a54
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Tue, 21 Mar 2023 14:26:19 +0800
toast: allow globally setting app data
The reason for this is twofold:
1. Registry state is fundamentally global; so a global
func that manipulates it is more correct
Consider multiple concurrent notifications, the registry
state will race.
2. Packages that import wrappers of this package (eg that
offer a cross platform api) might hide Windows-only
functionality. By offering this as a global we can set
the Windows-only functionality through a side channel,
while using the wrapping package like normal.
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Diffstat:
| M | toast.go | | | 27 | +++++++++++++++++++++++++++ |
1 file changed, 27 insertions(+), 0 deletions(-)
diff --git a/toast.go b/toast.go
@@ -259,3 +259,30 @@ func SetActivationCallback(cb func(args string, data []UserData)) {
cb(invokedArgs, userData)
})
}
+
+// AppData describes the various application metadata that can be used with Windows
+// toast notifications.
+type AppData struct {
+ // ID of the application. This should be a pretty name as it will be displayed in
+ // the notification.
+ ID string
+
+ // ExePath is the full path to an executable that Windows will invoke when
+ // the application is not running. This can be used to cold-start the application.
+ // Windows will provide an extra flag, so the named executable must be able to handle extra flags.
+ ExePath string // optional
+
+ // IconPath is the full path to an icon that Windows will display for the notification.
+ IconPath string // optional
+
+ // IconBackgroundColor is a hex encoded color code that Windows will display as the background
+ // for the named icon.
+ IconBackgroundColor string // optional
+}
+
+// SetAppData sets application metadata in the Windows Registry.
+// This is required to display the application name, as well as any branding.
+// Registry is global state, hence it makes sense to set it global.
+func SetAppData(data AppData) error {
+ return bind.SetAppData(bind.AppData(data))
+}