-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify_windows.go
45 lines (37 loc) · 994 Bytes
/
notify_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-FileCopyrightText: 2023 Tillitis AB <tillitis.se>
// SPDX-License-Identifier: BSD-2-Clause
//go:build windows
package tkeyutil
import (
"fmt"
"os"
"github.com/gen2brain/beeep"
"github.com/go-toast/toast"
"golang.org/x/sys/windows"
)
var isWindows10 bool
func init() {
maj, _, _ := windows.RtlGetNtVersionNumbers()
isWindows10 = (maj >= 10)
}
func Notify(progname, msg string) {
// Doing this because beeep doesn't let us set appID
if isWindows10 {
// Skipping msg title in win10+ toast. AppID (progname) will
// be displayed at the top of the toast frame.
notification := toast.Notification{
AppID: progname,
Title: "",
Message: msg,
Icon: "",
}
if err := notification.Push(); err != nil {
fmt.Fprintf(os.Stderr, "toastNotify message %q failed: %s\n", msg, err)
}
return
}
// Using progname as title
if err := beeep.Notify(progname, msg, ""); err != nil {
fmt.Fprintf(os.Stderr, "Notify message %q failed: %s\n", msg, err)
}
}