feat: 接入统一桌面端产品图标
使用根目录 icon 资源替换托盘占位图标,并为 macOS App、Windows 安装器和 Linux 安装脚本接入对应图标格式。
This commit is contained in:
1 parent
07fea7d1e6
commit
137a08489d
14 files changed
+78
-39
No files matched your search
@@ -54,6 +54,7 @@ jobs:
|
||||
mkdir -p "$package_dir"
|
||||
go build -trimpath -ldflags='-s -w' -o "$package_dir/xianyu-server" ./cmd/server
|
||||
go build -trimpath -ldflags='-s -w' -o "$package_dir/browser-install" ./cmd/browser-install
|
||||
cp icon/linux/icon.png "$package_dir/icon.png"
|
||||
cp packaging/linux/install.sh packaging/linux/uninstall.sh packaging/linux/ydisks-xianyu-helper.service "$package_dir/"
|
||||
chmod +x "$package_dir/install.sh" "$package_dir/uninstall.sh"
|
||||
tar -C dist -czf "dist/ydisks-xianyu-helper-linux-${GOARCH}-${APP_VERSION}.tar.gz" "$(basename "$package_dir")"
|
||||
|
||||
+16
-34
@@ -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
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 171 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 171 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 171 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 171 KiB |
@@ -20,6 +20,7 @@ fi
|
||||
|
||||
SERVER_SOURCE="${XIANYU_SERVER_SOURCE:-$SCRIPT_DIR/xianyu-server}"
|
||||
BROWSER_SOURCE="${XIANYU_BROWSER_INSTALL_SOURCE:-$SCRIPT_DIR/browser-install}"
|
||||
ICON_SOURCE="${XIANYU_ICON_SOURCE:-$SCRIPT_DIR/icon.png}"
|
||||
if [[ ! -x "$SERVER_SOURCE" ]]; then
|
||||
echo "找不到 xianyu-server:$SERVER_SOURCE" >&2
|
||||
exit 1
|
||||
@@ -28,6 +29,10 @@ if [[ ! -x "$BROWSER_SOURCE" ]]; then
|
||||
echo "找不到 browser-install:$BROWSER_SOURCE" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "$ICON_SOURCE" ]]; then
|
||||
echo "找不到应用图标:$ICON_SOURCE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! getent group "$APP_NAME" >/dev/null; then
|
||||
groupadd --system "$APP_NAME"
|
||||
@@ -43,6 +48,7 @@ install -d -o "$APP_NAME" -g "$APP_NAME" -m 0750 "$DATA_DIR/playwright-driver" "
|
||||
install -d -m 0750 "$CONFIG_DIR"
|
||||
install -m 0755 "$SERVER_SOURCE" "$INSTALL_DIR/xianyu-server"
|
||||
install -m 0755 "$BROWSER_SOURCE" "$INSTALL_DIR/browser-install"
|
||||
install -D -m 0644 "$ICON_SOURCE" "/usr/share/icons/hicolor/512x512/apps/$APP_NAME.png"
|
||||
install -m 0644 "$SCRIPT_DIR/ydisks-xianyu-helper.service" "/etc/systemd/system/$SERVICE_NAME"
|
||||
|
||||
if [[ ! -f "$CONFIG_DIR/config.env" ]]; then
|
||||
|
||||
@@ -13,4 +13,5 @@ systemctl disable --now "$SERVICE_NAME" >/dev/null 2>&1 || true
|
||||
rm -f "/etc/systemd/system/$SERVICE_NAME"
|
||||
systemctl daemon-reload
|
||||
rm -rf "/opt/$APP_NAME"
|
||||
rm -f "/usr/share/icons/hicolor/512x512/apps/$APP_NAME.png"
|
||||
echo "程序和服务已移除;数据仍保留在 /var/lib/$APP_NAME。"
|
||||
@@ -18,5 +18,7 @@
|
||||
<true/>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>xianyu-tray</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>icon.icns</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -3,6 +3,8 @@ set -eu
|
||||
|
||||
VERSION="${1:?version is required}"
|
||||
DIST_DIR="${2:?dist directory is required}"
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
PROJECT_ROOT="$(CDPATH= cd -- "$SCRIPT_DIR/../.." && pwd)"
|
||||
ROOT_DIR="$DIST_DIR/pkgroot"
|
||||
APP="$ROOT_DIR/Applications/Ydisks Xianyu Helper.app"
|
||||
PACKAGE_PATH="$DIST_DIR/Ydisks-Xianyu-Helper-$VERSION.pkg"
|
||||
@@ -13,9 +15,10 @@ mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Helpers" "$APP/Contents/Resources"
|
||||
cp "$DIST_DIR/xianyu-server" "$APP/Contents/Helpers/xianyu-server"
|
||||
cp "$DIST_DIR/browser-install" "$APP/Contents/Helpers/browser-install"
|
||||
cp "$DIST_DIR/xianyu-tray" "$APP/Contents/MacOS/xianyu-tray"
|
||||
cp "$(dirname "$0")/com.ydisks.xianyu-helper.server.plist.template" "$APP/Contents/Resources/"
|
||||
cp "$(dirname "$0")/com.ydisks.xianyu-helper.tray.plist.template" "$APP/Contents/Resources/"
|
||||
sed "s/__VERSION__/$VERSION/g" "$(dirname "$0")/Info.plist" > "$APP/Contents/Info.plist"
|
||||
cp "$SCRIPT_DIR/com.ydisks.xianyu-helper.server.plist.template" "$APP/Contents/Resources/"
|
||||
cp "$SCRIPT_DIR/com.ydisks.xianyu-helper.tray.plist.template" "$APP/Contents/Resources/"
|
||||
cp "$PROJECT_ROOT/icon/macos/icon.icns" "$APP/Contents/Resources/icon.icns"
|
||||
sed "s/__VERSION__/$VERSION/g" "$SCRIPT_DIR/Info.plist" > "$APP/Contents/Info.plist"
|
||||
chmod 0755 "$APP/Contents/MacOS/xianyu-tray" "$APP/Contents/Helpers/xianyu-server" "$APP/Contents/Helpers/browser-install"
|
||||
|
||||
if [ -n "${MACOS_SIGNING_IDENTITY:-}" ]; then
|
||||
@@ -47,7 +50,7 @@ rm -f "$PACKAGE_PATH" "$UNSIGNED_PACKAGE_PATH"
|
||||
|
||||
pkgbuild \
|
||||
--root "$ROOT_DIR" \
|
||||
--scripts "$(dirname "$0")/scripts" \
|
||||
--scripts "$SCRIPT_DIR/scripts" \
|
||||
--identifier com.ydisks.xianyu-helper \
|
||||
--version "$VERSION" \
|
||||
--install-location / \
|
||||
|
||||
@@ -15,7 +15,8 @@ OutputBaseFilename=Ydisks-Xianyu-Helper-Setup
|
||||
PrivilegesRequired=admin
|
||||
ArchitecturesInstallIn64BitMode=x64compatible
|
||||
DisableProgramGroupPage=yes
|
||||
UninstallDisplayIcon={app}\{#AppExeName}
|
||||
UninstallDisplayIcon={app}\icon.ico
|
||||
SetupIconFile=..\..\icon\windows\icon.ico
|
||||
Compression=lzma2
|
||||
SolidCompression=yes
|
||||
|
||||
@@ -23,6 +24,7 @@ SolidCompression=yes
|
||||
Source: "..\..\dist\windows\xianyu-server.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "..\..\dist\windows\browser-install.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "..\..\dist\windows\xianyu-tray.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "..\..\icon\windows\icon.ico"; DestDir: "{app}"; Flags: ignoreversion
|
||||
|
||||
[Dirs]
|
||||
Name: "{#AppDataDir}\data"
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// Command iconconv wraps a PNG image in the Windows ICO container format.
|
||||
// It is used to generate the checked-in installer icon from the product asset.
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 3 {
|
||||
fmt.Fprintln(os.Stderr, "usage: iconconv input.png output.ico")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(os.Args[1])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// A PNG-compressed 256x256 image is valid in an ICO file and keeps the
|
||||
// alpha channel of the original product icon.
|
||||
const headerSize = 6
|
||||
const entrySize = 16
|
||||
result := make([]byte, headerSize+entrySize+len(data))
|
||||
binary.LittleEndian.PutUint16(result[0:2], 0)
|
||||
binary.LittleEndian.PutUint16(result[2:4], 1)
|
||||
binary.LittleEndian.PutUint16(result[4:6], 1)
|
||||
entry := result[headerSize : headerSize+entrySize]
|
||||
entry[0] = 0 // 0 means 256 in the ICO format.
|
||||
entry[1] = 0
|
||||
binary.LittleEndian.PutUint16(entry[4:6], 1)
|
||||
binary.LittleEndian.PutUint16(entry[6:8], 32)
|
||||
binary.LittleEndian.PutUint32(entry[8:12], uint32(len(data)))
|
||||
binary.LittleEndian.PutUint32(entry[12:16], headerSize+entrySize)
|
||||
copy(result[headerSize+entrySize:], data)
|
||||
|
||||
if err := os.WriteFile(os.Args[2], result, 0644); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user