go-toast

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

commit 53f523e3d4798c91592239eb1da3366ee09fba15
parent 3126322d89d19072d4e8b6e785173ecf4f5f737d
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Wed, 22 Mar 2023 09:37:10 +0800

toast,internal/bind: consistent field naming

Make the field names consistent.

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

Diffstat:
Minternal/bind/bind.go | 2+-
Minternal/bind/bind_test.go | 26+++++++++++++-------------
Minternal/bind/registry.go | 16++++++++--------
Mtoast.go | 12++++++------
4 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/internal/bind/bind.go b/internal/bind/bind.go @@ -46,7 +46,7 @@ func GenerateToast(appID, xml string) error { // It's a bit of a side-channel hack, however it's necessary for some of // the API flexibility that's being employed. if appID == "" { - appID = appData.ID + appID = appData.AppID } // 1. allocate ClassFactory implementation. diff --git a/internal/bind/bind_test.go b/internal/bind/bind_test.go @@ -20,7 +20,7 @@ func TestSetAppData(t *testing.T) { appData = AppData{} - input := AppData{ID: "test-id"} + input := AppData{AppID: "test-id"} if err := SetAppData(input); err != nil { t.Fatalf("error: %v", err) @@ -43,7 +43,7 @@ func TestSetAppData(t *testing.T) { return nil } - appData = AppData{ID: "test-id"} + appData = AppData{AppID: "test-id"} input := AppData{} @@ -67,7 +67,7 @@ func TestSetAppData(t *testing.T) { appData = AppData{} - input := AppData{ID: "test-id"} + input := AppData{AppID: "test-id"} if err := SetAppData(input); err == nil { t.Fatalf("expected error, got nil") @@ -92,7 +92,7 @@ func TestSetAppData(t *testing.T) { } input := AppData{ - ID: "test-id", + AppID: "test-id", } if err := SetAppData(input); err != nil { @@ -100,8 +100,8 @@ func TestSetAppData(t *testing.T) { } expect := map[string]string{ - filepath.Join(appKeyRoot, input.ID, "CustomActivator"): GUID_ImplNotificationActivationCallback.String(), - filepath.Join(appKeyRoot, input.ID, "DisplayName"): input.ID, + filepath.Join(appKeyRoot, input.AppID, "CustomActivator"): GUID_ImplNotificationActivationCallback.String(), + filepath.Join(appKeyRoot, input.AppID, "DisplayName"): input.AppID, } if !reflect.DeepEqual(expect, record) { @@ -121,10 +121,10 @@ func TestSetAppData(t *testing.T) { } input := AppData{ - ID: "test-id", + AppID: "test-id", IconPath: "path/to/icon.ico", IconBackgroundColor: "#FFFFFF", - ExePath: "path/to/exe", + ActivationExe: "path/to/exe", } if err := SetAppData(input); err != nil { @@ -132,11 +132,11 @@ func TestSetAppData(t *testing.T) { } expect := map[string]string{ - filepath.Join(appKeyRoot, input.ID, "CustomActivator"): GUID_ImplNotificationActivationCallback.String(), - filepath.Join(appKeyRoot, input.ID, "DisplayName"): input.ID, - filepath.Join(appKeyRoot, input.ID, "IconUri"): input.IconPath, - filepath.Join(appKeyRoot, input.ID, "IconBackgroundColor"): input.IconBackgroundColor, - filepath.Join(activationKey): input.ExePath, + filepath.Join(appKeyRoot, input.AppID, "CustomActivator"): GUID_ImplNotificationActivationCallback.String(), + filepath.Join(appKeyRoot, input.AppID, "DisplayName"): input.AppID, + filepath.Join(appKeyRoot, input.AppID, "IconUri"): input.IconPath, + filepath.Join(appKeyRoot, input.AppID, "IconBackgroundColor"): input.IconBackgroundColor, + filepath.Join(activationKey): input.ActivationExe, } if !reflect.DeepEqual(expect, record) { diff --git a/internal/bind/registry.go b/internal/bind/registry.go @@ -22,8 +22,8 @@ var ( // AppData describes the application to the Windows Runtime. type AppData struct { - ID string - ExePath string // optional + AppID string + ActivationExe string // optional IconPath string // optional IconBackgroundColor string // optional } @@ -41,7 +41,7 @@ func SetAppData(data AppData) (err error) { // // This allows the caller to either globally set the app data // or provide it per notification. - if appData == data || data.ID == "" { + if appData == data || data.AppID == "" { return nil } @@ -76,13 +76,13 @@ var ( const registryDefaultKey string = "" func setAppDataImpl(data AppData) error { - if data.ID == "" { + if data.AppID == "" { return fmt.Errorf("empty app ID") } - appKey := filepath.Join(appKeyRoot, data.ID) + appKey := filepath.Join(appKeyRoot, data.AppID) - if err := writeStringValue(appKey, "DisplayName", data.ID); err != nil { + if err := writeStringValue(appKey, "DisplayName", data.AppID); err != nil { return err } @@ -104,8 +104,8 @@ func setAppDataImpl(data AppData) error { } } - if data.ExePath != "" { - if err := writeStringValue(activationKey, registryDefaultKey, data.ExePath); err != nil { + if data.ActivationExe != "" { + if err := writeStringValue(activationKey, registryDefaultKey, data.ActivationExe); err != nil { return fmt.Errorf("setting activation executable: %w", err) } } diff --git a/toast.go b/toast.go @@ -156,10 +156,10 @@ func (n *Notification) Push() error { return err } if err := bind.SetAppData(bind.AppData{ - ID: n.AppID, + AppID: n.AppID, IconPath: n.Icon, IconBackgroundColor: n.IconBackgroundColor, - ExePath: n.ActivationExe, + ActivationExe: n.ActivationExe, }); err != nil { return fmt.Errorf("configuring registry: %w", err) } @@ -260,14 +260,14 @@ func SetActivationCallback(cb func(args string, data []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 + // AppID of the application. This should be a pretty name as it will be displayed in // the notification. - ID string + AppID string - // ExePath is the full path to an executable that Windows will invoke when + // ActivationExe 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 + ActivationExe string // optional // IconPath is the full path to an icon that Windows will display for the notification. IconPath string // optional