Files
talk/internal/notify/protocol_windows.go
T

36 lines
1.2 KiB
Go
Raw Normal View History

//go:build windows
package notify
import (
"fmt"
"golang.org/x/sys/windows/registry"
)
// RegisterProtocol registers the talk: URL protocol for the current user
// (HKCU\Software\Classes\talk, no admin rights needed) so that a toast
// button with a talk: link starts `<exe> uri <link>`. Idempotent; the
// command is rewritten on every call so it follows the binary's location.
func RegisterProtocol(exe string) error {
root, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\Classes\talk`, registry.SET_VALUE)
if err != nil {
return fmt.Errorf("registering talk: protocol: %w", err)
}
defer root.Close()
if err := root.SetStringValue("", "URL:talk protocol"); err != nil {
return fmt.Errorf("registering talk: protocol: %w", err)
}
if err := root.SetStringValue("URL Protocol", ""); err != nil {
return fmt.Errorf("registering talk: protocol: %w", err)
}
cmdKey, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\Classes\talk\shell\open\command`, registry.SET_VALUE)
if err != nil {
return fmt.Errorf("registering talk: protocol: %w", err)
}
defer cmdKey.Close()
if err := cmdKey.SetStringValue("", fmt.Sprintf(`"%s" uri "%%1"`, exe)); err != nil {
return fmt.Errorf("registering talk: protocol: %w", err)
}
return nil
}