go-toast

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

commit d2b1e55846a07bcd3d814784a3ed1745b0208e88
parent c6470b0dcd8fc78f92a0eff60019044674fe110b
Author: Jack Mordaunt <jackmordaunt@gmail.com>
Date:   Fri, 17 Mar 2023 17:14:50 +0800

toast: remove DisplayName

The registry entry for DisplayName appears to be useless, at
least as tested by me on Windows 11.

For now, we can simplify things and just the the AppID.

I tested using special characters for the AppID and it renders
them correctly on Windows 11. Windows 10 I'm not sure about.

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

Diffstat:
Mexamples/toast-cli/main.go | 2+-
Minternal/bind/registry.go | 6+-----
Mtoast.go | 6++----
3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/examples/toast-cli/main.go b/examples/toast-cli/main.go @@ -14,7 +14,7 @@ func main() { showActions bool ) - flag.StringVar(&n.AppID, "app-id", "Windows Toast CLI", "Application ID that identifies this app") + flag.StringVar(&n.AppID, "app-id", "com.windows.toast.cli", "Application ID that identifies this app") flag.StringVar(&n.Title, "title", "title", "Title") flag.StringVar(&n.Body, "body", "body", "Body") flag.StringVar(&n.Icon, "icon", "", "Icon") diff --git a/internal/bind/registry.go b/internal/bind/registry.go @@ -14,7 +14,6 @@ import ( // AppData describes the application to the Windows Runtime. type AppData struct { ID string - DisplayName string // optional, if empty the ID will be used ExePath string // optional IconPath string // optional IconBackgroundColor string // optional @@ -26,9 +25,6 @@ func SetAppData(data AppData) error { if data.ID == "" { return fmt.Errorf("empty app ID") } - if data.DisplayName == "" { - data.DisplayName = data.ID - } appIDKey, _, err := registry.CreateKey(registry.CURRENT_USER, filepath.Join("SOFTWARE", "Classes", "AppUserModelId", data.ID), registry.SET_VALUE) if err != nil { return fmt.Errorf("opening registry: %w", err) @@ -36,7 +32,7 @@ func SetAppData(data AppData) error { defer func() { err = errors.Join(err, appIDKey.Close()) }() - if err := appIDKey.SetStringValue("DisplayName", data.DisplayName); err != nil { + if err := appIDKey.SetStringValue("DisplayName", data.ID); err != nil { return fmt.Errorf("setting DisplayName: %w", err) } // CustomActivator teaches Window what COM class to use as the callback when diff --git a/toast.go b/toast.go @@ -49,9 +49,8 @@ import ( // // err := toast.Push() type Notification struct { - // The name of your app. This value shows up in Windows 10's Action Centre, so make it - // something readable for your users. It can contain spaces, however special characters - // (eg. é) are not supported. + // The name of your app. This value shows up in Windows Action Centre, so make it + // something readable for your users. AppID string // The main title/heading for the toast notification. @@ -158,7 +157,6 @@ func (n *Notification) Push() error { } if err := bind.SetAppData(bind.AppData{ ID: n.AppID, - DisplayName: n.AppID, IconPath: n.Icon, IconBackgroundColor: n.IconBackgroundColor, ExePath: n.ActivationExe,