feat: 接入统一桌面端产品图标

使用根目录 icon 资源替换托盘占位图标,并为 macOS App、Windows 安装器和 Linux 安装脚本接入对应图标格式。
This commit is contained in:
Christ committed 2026-08-11 23:07:13 +08:00
1 parent 07fea7d1e6
commit 137a08489d
14 files changed
+78 -39

No files matched your search

+16 -34
View File
@@ -1,39 +1,23 @@
package main
import (
"bytes"
_ "embed"
"encoding/binary"
"image"
"image/color"
"image/png"
"runtime"
)
// trayIconBytes 返回一个不依赖外部文件的图标,避免安装器还要额外管理图标路径。
// icon.png 是从根目录 icon/windows/icon.png 同步的产品图标,并直接嵌入托盘二进制。
//
//go:embed icon.png
var productIconPNG []byte
// trayIconBytes 返回嵌入的产品图标,避免运行时依赖外部图标文件。
// Windows 的 Shell_NotifyIcon 需要 ICO;macOS/Linux 可以直接使用 PNG。
func trayIconBytes() []byte {
const size = 32
img := image.NewRGBA(image.Rect(0, 0, size, size))
for y := 0; y < size; y++ {
for x := 0; x < size; x++ {
dx, dy := x-size/2, y-size/2
if dx*dx+dy*dy <= 14*14 {
img.SetRGBA(x, y, color.RGBA{R: 37, G: 99, B: 235, A: 255})
}
if abs(x-y) <= 2 || abs(x+y-(size-1)) <= 2 {
if dx*dx+dy*dy <= 10*10 {
img.SetRGBA(x, y, color.RGBA{R: 255, G: 255, B: 255, A: 255})
}
}
}
}
var pngData bytes.Buffer
_ = png.Encode(&pngData, img)
if runtime.GOOS != "windows" {
return pngData.Bytes()
return productIconPNG
}
return pngToICO(pngData.Bytes(), size)
return pngToICO(productIconPNG, 256)
}
func pngToICO(data []byte, size int) []byte {
@@ -45,8 +29,13 @@ func pngToICO(data []byte, size int) []byte {
binary.LittleEndian.PutUint16(result[2:4], 1)
binary.LittleEndian.PutUint16(result[4:6], 1)
entry := result[headerSize : headerSize+entrySize]
entry[0] = byte(size)
entry[1] = byte(size)
if size >= 256 {
entry[0] = 0
entry[1] = 0
} else {
entry[0] = byte(size)
entry[1] = byte(size)
}
entry[2] = 0
entry[3] = 0
binary.LittleEndian.PutUint16(entry[4:6], 1)
@@ -56,10 +45,3 @@ func pngToICO(data []byte, size int) []byte {
copy(result[headerSize+entrySize:], data)
return result
}
func abs(value int) int {
if value < 0 {
return -value
}
return value
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB