File: notify_windows.go

package info (click to toggle)
golang-github-tillitis-tkeyutil 0.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 128 kB
  • sloc: sh: 70; makefile: 10
file content (45 lines) | stat: -rw-r--r-- 994 bytes parent folder | download
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)
	}
}