Add systray

This commit is contained in:
2024-11-03 00:24:33 +01:00
parent 5a323c78f8
commit 180e8cb699
2 changed files with 9 additions and 4 deletions

BIN
duck2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

13
main.go
View File

@@ -7,6 +7,7 @@ import (
"os" "os"
"syscall" "syscall"
// _ "embed"
"fyne.io/systray" "fyne.io/systray"
hook "github.com/robotn/gohook" hook "github.com/robotn/gohook"
) )
@@ -17,6 +18,8 @@ var (
GetForegroundWindow = us32.MustFindProc("GetForegroundWindow") GetForegroundWindow = us32.MustFindProc("GetForegroundWindow")
) )
// //go:embed duck2.jpg
//var icon []byte
var Error *log.Logger var Error *log.Logger
var Warning *log.Logger var Warning *log.Logger
@@ -44,7 +47,7 @@ const (
) )
func main() { func main() {
systray.Run(onReady, onExit) systray.Run(onReady, nil)
keyEvents := make(chan *hook.Event, 4096) keyEvents := make(chan *hook.Event, 4096)
hook.Register(hook.KeyDown, []string{}, func(e hook.Event) { hook.Register(hook.KeyDown, []string{}, func(e hook.Event) {
keyEvents <- &e keyEvents <- &e
@@ -92,11 +95,13 @@ func main() {
} }
func onReady() { func onReady() {
systray.SetIcon(icon.Data) // Icons no workey... idk why...
// systray error: unable to set icon: The operation completed successfully.
//systray.SetIcon(icon)
systray.SetTitle("Awesome App") systray.SetTitle("Awesome App")
systray.SetTooltip("Pretty awesome超级棒") systray.SetTooltip("Pretty awesome超级棒")
mQuit := systray.AddMenuItem("Quit", "Quit the whole app") //mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
// Sets the icon of a menu item. Only available on Mac and Windows. // Sets the icon of a menu item. Only available on Mac and Windows.
mQuit.SetIcon(icon.Data) //mQuit.SetIcon(icon)
} }