Update tray icon management by replacing PNG assets with ICO format, enhancing compatibility and resource efficiency. Modify FyneApp.toml build version to 6 and add new dependency for ICO handling.

This commit is contained in:
kony
2026-03-17 21:18:55 +08:00
parent fa9f4bd415
commit 180516203a
14 changed files with 52 additions and 35 deletions
+1 -1
View File
@@ -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
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

+14 -9
View File
@@ -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())
}
+1
View File
@@ -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
+2
View File
@@ -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=
+9 -1
View File
@@ -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)
+25 -24
View File
@@ -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) {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB