diff --git a/FyneApp.toml b/FyneApp.toml index f211201..59684c1 100644 --- a/FyneApp.toml +++ b/FyneApp.toml @@ -5,4 +5,4 @@ Icon = "assert/favicon.ico" Name = "goodlink-windows-amd64-ui" ID = "goodlink.kony.vip" Version = "2.5.18" -Build = 4 +Build = 6 diff --git a/assert/tray_danger.ico b/assert/tray_danger.ico new file mode 100644 index 0000000..3444854 Binary files /dev/null and b/assert/tray_danger.ico differ diff --git a/assert/tray_idle.ico b/assert/tray_idle.ico new file mode 100644 index 0000000..533b1b3 Binary files /dev/null and b/assert/tray_idle.ico differ diff --git a/assert/tray_success.ico b/assert/tray_success.ico new file mode 100644 index 0000000..506e5ea Binary files /dev/null and b/assert/tray_success.ico differ diff --git a/assert/tray_warning.ico b/assert/tray_warning.ico new file mode 100644 index 0000000..5da8c99 Binary files /dev/null and b/assert/tray_warning.ico differ diff --git a/cmd/gen_tray_icons/main.go b/cmd/gen_tray_icons/main.go index 4a57906..cc0d31c 100644 --- a/cmd/gen_tray_icons/main.go +++ b/cmd/gen_tray_icons/main.go @@ -1,5 +1,5 @@ -// gen_tray_icons reads assert/favicon.png and generates 4 tray state PNGs -// into ui2/ using the same dot-drawing logic as ui2/tray.go. +// gen_tray_icons reads assert/favicon.png and generates 4 tray state .ico files +// into assert/ using the same dot-drawing logic as ui2/tray.go. // Run from project root: go run ./cmd/gen_tray_icons package main @@ -7,10 +7,12 @@ import ( "image" "image/color" "image/draw" - "image/png" "math" "os" "path/filepath" + + "github.com/antoinefink/golang-ico" + "github.com/nfnt/resize" ) var ( @@ -25,7 +27,7 @@ func main() { if len(os.Args) > 1 { basePath = os.Args[1] } - outDir := "ui2" + outDir := "assert" if len(os.Args) > 2 { outDir = os.Args[2] } @@ -39,15 +41,18 @@ func main() { if err != nil { panic("decode base image: " + err.Error()) } + // Resize to 32x32 for tray icon (ICO max 256x256; small size suits system tray) + const traySize = 32 + baseImage = resize.Resize(traySize, traySize, baseImage, resize.Lanczos3) states := []struct { name string c color.NRGBA }{ - {"tray_idle.png", dotColorIdle}, - {"tray_warning.png", dotColorWarning}, - {"tray_danger.png", dotColorDanger}, - {"tray_success.png", dotColorSuccess}, + {"tray_idle.ico", dotColorIdle}, + {"tray_warning.ico", dotColorWarning}, + {"tray_danger.ico", dotColorDanger}, + {"tray_success.ico", dotColorSuccess}, } for _, s := range states { @@ -57,7 +62,7 @@ func main() { if err != nil { panic("create " + outPath + ": " + err.Error()) } - if err := png.Encode(out, dst); err != nil { + if err := ico.Encode(out, dst); err != nil { _ = out.Close() panic("encode " + outPath + ": " + err.Error()) } diff --git a/go.mod b/go.mod index 1503210..b3b7b46 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( require ( fyne.io/systray v1.12.0 // indirect + github.com/antoinefink/golang-ico v0.0.0-20251207114801-fa953cf78f26 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fredbi/uri v1.1.1 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect diff --git a/go.sum b/go.sum index 30c0c89..e5c69f0 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I= github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= +github.com/antoinefink/golang-ico v0.0.0-20251207114801-fa953cf78f26 h1:aRJlisWHMprWOjJ/ow5ykKz5x8D6uPEU16x35S7rdRc= +github.com/antoinefink/golang-ico v0.0.0-20251207114801-fa953cf78f26/go.mod h1:kupAIPIZtaUZRWnkktmLPEJoaQSwZpkCqXQz2dorV6Y= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= diff --git a/main_ui.go b/main_ui.go index 3019709..3a1592f 100644 --- a/main_ui.go +++ b/main_ui.go @@ -3,6 +3,7 @@ package main import ( + "embed" "goodlink/config" "goodlink/pro" _ "goodlink/pro" @@ -17,6 +18,9 @@ import ( "fyne.io/fyne/v2/driver/desktop" ) +//go:embed assert/tray_idle.ico assert/tray_warning.ico assert/tray_danger.ico assert/tray_success.ico +var trayIcons embed.FS + const ( M_APP_TITLE = "Goodlink" ) @@ -52,7 +56,11 @@ func main() { } }() - ui2.InitTrayIcons() + idle, _ := trayIcons.ReadFile("assert/tray_idle.ico") + warning, _ := trayIcons.ReadFile("assert/tray_warning.ico") + danger, _ := trayIcons.ReadFile("assert/tray_danger.ico") + success, _ := trayIcons.ReadFile("assert/tray_success.ico") + ui2.InitTrayIcons(idle, warning, danger, success) if desk, ok := myApp.(desktop.App); ok { ui2.SetTrayApp(desk) diff --git a/ui2/tray.go b/ui2/tray.go index 6f8836e..0c62f75 100644 --- a/ui2/tray.go +++ b/ui2/tray.go @@ -3,46 +3,47 @@ package ui2 import ( - "embed" "fyne.io/fyne/v2" "fyne.io/fyne/v2/driver/desktop" "image/color" ) -//go:embed tray_idle.png tray_warning.png tray_danger.png tray_success.png -var trayIconFS embed.FS - var ( trayApp desktop.App currentDotColor color.NRGBA + // Pre-generated tray icon data (ICO bytes), set by InitTrayIcons. + trayIconIdle []byte + trayIconWarning []byte + trayIconDanger []byte + trayIconSuccess []byte ) -func InitTrayIcons() { - // No-op: icons are embedded and selected by UpdateTrayIcon. +// InitTrayIcons sets the 4 pre-generated tray icon bytes (ICO format). +// Icons should be from assert/tray_idle.ico, tray_warning.ico, tray_danger.ico, tray_success.ico. +func InitTrayIcons(idle, warning, danger, success []byte) { + trayIconIdle = idle + trayIconWarning = warning + trayIconDanger = danger + trayIconSuccess = success } func iconForDotColor(c color.NRGBA) fyne.Resource { - data, _ := trayIconFS.ReadFile(iconNameForDotColor(c)) + var data []byte + if c.R == DotColorIdle.R && c.G == DotColorIdle.G && c.B == DotColorIdle.B { + data = trayIconIdle + } else if c.R == DotColorWarning.R && c.G == DotColorWarning.G && c.B == DotColorWarning.B { + data = trayIconWarning + } else if c.R == DotColorDanger.R && c.G == DotColorDanger.G && c.B == DotColorDanger.B { + data = trayIconDanger + } else if c.R == DotColorSuccess.R && c.G == DotColorSuccess.G && c.B == DotColorSuccess.B { + data = trayIconSuccess + } else { + data = trayIconIdle + } if len(data) == 0 { return nil } - return fyne.NewStaticResource("tray_icon.png", data) -} - -func iconNameForDotColor(c color.NRGBA) string { - if c.R == DotColorIdle.R && c.G == DotColorIdle.G && c.B == DotColorIdle.B { - return "tray_idle.png" - } - if c.R == DotColorWarning.R && c.G == DotColorWarning.G && c.B == DotColorWarning.B { - return "tray_warning.png" - } - if c.R == DotColorDanger.R && c.G == DotColorDanger.G && c.B == DotColorDanger.B { - return "tray_danger.png" - } - if c.R == DotColorSuccess.R && c.G == DotColorSuccess.G && c.B == DotColorSuccess.B { - return "tray_success.png" - } - return "tray_idle.png" + return fyne.NewStaticResource("tray_icon.ico", data) } func SetTrayApp(desk desktop.App) { diff --git a/ui2/tray_danger.png b/ui2/tray_danger.png deleted file mode 100644 index e966a9f..0000000 Binary files a/ui2/tray_danger.png and /dev/null differ diff --git a/ui2/tray_idle.png b/ui2/tray_idle.png deleted file mode 100644 index 9bc0c4c..0000000 Binary files a/ui2/tray_idle.png and /dev/null differ diff --git a/ui2/tray_success.png b/ui2/tray_success.png deleted file mode 100644 index dedbbfa..0000000 Binary files a/ui2/tray_success.png and /dev/null differ diff --git a/ui2/tray_warning.png b/ui2/tray_warning.png deleted file mode 100644 index 400cafb..0000000 Binary files a/ui2/tray_warning.png and /dev/null differ