diff --git a/cmd/tray/icon-gray.png b/cmd/tray/icon-gray.png
new file mode 100644
index 0000000..eaaaf35
Binary files /dev/null and b/cmd/tray/icon-gray.png differ
diff --git a/cmd/tray/icon.go b/cmd/tray/icon.go
index 005372a..c3c4913 100644
--- a/cmd/tray/icon.go
+++ b/cmd/tray/icon.go
@@ -6,18 +6,25 @@ import (
"runtime"
)
-// icon.png 是从根目录 icon/windows/icon.png 同步的产品图标,并直接嵌入托盘二进制。
+// icon.png 是从根目录 icon/windows/icon.png 同步的彩色产品图标,并直接嵌入托盘二进制。
//
//go:embed icon.png
var productIconPNG []byte
-// trayIconBytes 返回嵌入的产品图标,避免运行时依赖外部图标文件。
+//go:embed icon-gray.png
+var productIconGrayPNG []byte
+
+// trayIconBytes 返回当前服务状态对应的图标,避免运行时依赖外部图标文件。
// Windows 的 Shell_NotifyIcon 需要 ICO;macOS/Linux 可以直接使用 PNG。
-func trayIconBytes() []byte {
- if runtime.GOOS != "windows" {
- return productIconPNG
+func trayIconBytes(running bool) []byte {
+ data := productIconGrayPNG
+ if running {
+ data = productIconPNG
}
- return pngToICO(productIconPNG, 256)
+ if runtime.GOOS != "windows" {
+ return data
+ }
+ return pngToICO(data, 256)
}
func pngToICO(data []byte, size int) []byte {
diff --git a/cmd/tray/main.go b/cmd/tray/main.go
index 9cba69c..0a598a6 100644
--- a/cmd/tray/main.go
+++ b/cmd/tray/main.go
@@ -27,9 +27,9 @@ func main() {
}
func onReady() {
- systray.SetTitle("闲鱼管家")
- systray.SetIcon(trayIconBytes())
- systray.SetTooltip("闲鱼管家服务")
+ systray.SetTitle("")
+ systray.SetIcon(trayIconBytes(false))
+ systray.SetTooltip("Ydisks闲鱼助手服务")
statusItem := systray.AddMenuItem("服务状态:检查中", "读取后台服务状态")
openItem := systray.AddMenuItem("打开管理页面", "在默认浏览器打开管理页面")
@@ -71,7 +71,7 @@ func onReady() {
for range quitItem.ClickedCh {
if err := quitTray(); err != nil {
statusItem.SetTitle("托盘状态:退出失败")
- systray.SetTooltip(fmt.Sprintf("闲鱼管家:托盘退出失败:%v", err))
+ systray.SetTooltip(fmt.Sprintf("Ydisks闲鱼助手:托盘退出失败:%v", err))
continue
}
systray.Quit()
@@ -88,7 +88,7 @@ func installBrowser() error {
}
path = executable
if runtime.GOOS == "darwin" {
- path = strings.Replace(path, "/Contents/MacOS/xianyu-tray", "/Contents/Helpers/browser-install", 1)
+ path = strings.Replace(path, "/Contents/MacOS/Ydisks闲鱼助手", "/Contents/Helpers/browser-install", 1)
} else {
path = strings.Replace(path, "xianyu-tray.exe", "browser-install.exe", 1)
}
@@ -107,22 +107,26 @@ func refreshStatus(item *systray.MenuItem) {
func refreshStatusOnce(item *systray.MenuItem, client *http.Client) {
status, err := readHealth(client)
if err != nil {
+ systray.SetIcon(trayIconBytes(false))
item.SetTitle("服务状态:未运行")
- systray.SetTooltip("闲鱼管家:后台服务未运行")
+ systray.SetTooltip("Ydisks闲鱼助手:后台服务未运行")
} else if status.Status == "ok" && status.Database == "ok" {
+ systray.SetIcon(trayIconBytes(true))
item.SetTitle("服务状态:运行正常")
- systray.SetTooltip("闲鱼管家:运行正常")
+ systray.SetTooltip("Ydisks闲鱼助手:运行正常")
} else {
+ systray.SetIcon(trayIconBytes(false))
item.SetTitle("服务状态:异常")
- systray.SetTooltip("闲鱼管家:数据库或服务异常")
+ systray.SetTooltip("Ydisks闲鱼助手:数据库或服务异常")
}
}
func runServiceAction(statusItem *systray.MenuItem, actionName, action string) {
+ systray.SetIcon(trayIconBytes(false))
statusItem.SetTitle("服务状态:" + actionName + "中")
if err := serviceAction(action); err != nil {
statusItem.SetTitle("服务状态:操作失败")
- systray.SetTooltip(fmt.Sprintf("闲鱼管家:%s失败:%v", actionName, err))
+ systray.SetTooltip(fmt.Sprintf("Ydisks闲鱼助手:%s失败:%v", actionName, err))
return
}
diff --git a/packaging/macos/Info.plist b/packaging/macos/Info.plist
index 76d2c02..f349a08 100644
--- a/packaging/macos/Info.plist
+++ b/packaging/macos/Info.plist
@@ -5,9 +5,9 @@
CFBundleIdentifier
com.ydisks.xianyu-helper
CFBundleName
- Ydisks Xianyu Helper
+ Ydisks闲鱼助手
CFBundleDisplayName
- 闲鱼管家
+ Ydisks闲鱼助手
CFBundlePackageType
APPL
CFBundleVersion
@@ -17,7 +17,7 @@
LSUIElement
CFBundleExecutable
- xianyu-tray
+ Ydisks闲鱼助手
CFBundleIconName
AppIcon
CFBundleIconFile
diff --git a/packaging/macos/build-pkg.sh b/packaging/macos/build-pkg.sh
index 266ec67..b0e04e4 100755
--- a/packaging/macos/build-pkg.sh
+++ b/packaging/macos/build-pkg.sh
@@ -6,7 +6,8 @@ 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"
+APP_DIR="$ROOT_DIR/Applications/Ydisks闲鱼助手"
+APP="$APP_DIR/Ydisks闲鱼助手.app"
PACKAGE_PATH="$DIST_DIR/Ydisks-Xianyu-Helper-$VERSION.pkg"
UNSIGNED_PACKAGE_PATH="$DIST_DIR/.Ydisks-Xianyu-Helper-$VERSION.unsigned.pkg"
@@ -14,13 +15,14 @@ rm -rf "$ROOT_DIR"
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 "$DIST_DIR/xianyu-tray" "$APP/Contents/MacOS/Ydisks闲鱼助手"
+cp "$SCRIPT_DIR/uninstall.command" "$APP_DIR/卸载 Ydisks闲鱼助手.command"
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/Assets.car" "$APP/Contents/Resources/Assets.car"
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"
+chmod 0755 "$APP/Contents/MacOS/Ydisks闲鱼助手" "$APP/Contents/Helpers/xianyu-server" "$APP/Contents/Helpers/browser-install" "$APP_DIR/卸载 Ydisks闲鱼助手.command"
if [ -n "${MACOS_SIGNING_IDENTITY:-}" ]; then
sign_code() {
@@ -37,7 +39,7 @@ if [ -n "${MACOS_SIGNING_IDENTITY:-}" ]; then
# macOS 代码签名必须从内部组件开始,最后再签名 App 包本身。
sign_code "$APP/Contents/Helpers/xianyu-server"
sign_code "$APP/Contents/Helpers/browser-install"
- sign_code "$APP/Contents/MacOS/xianyu-tray"
+ sign_code "$APP/Contents/MacOS/Ydisks闲鱼助手"
sign_code "$APP"
codesign --verify --deep --strict --verbose=2 "$APP"
fi
@@ -51,6 +53,7 @@ rm -f "$PACKAGE_PATH" "$UNSIGNED_PACKAGE_PATH"
pkgbuild \
--root "$ROOT_DIR" \
+ --component-plist "$SCRIPT_DIR/component.plist" \
--scripts "$SCRIPT_DIR/scripts" \
--identifier com.ydisks.xianyu-helper \
--version "$VERSION" \
diff --git a/packaging/macos/component.plist b/packaging/macos/component.plist
new file mode 100644
index 0000000..202b386
--- /dev/null
+++ b/packaging/macos/component.plist
@@ -0,0 +1,18 @@
+
+
+
+
+
+ RootRelativeBundlePath
+ Applications/Ydisks闲鱼助手/Ydisks闲鱼助手.app
+ BundleIsRelocatable
+
+ BundleIsVersionChecked
+
+ BundleHasStrictIdentifier
+
+ BundleOverwriteAction
+ upgrade
+
+
+
diff --git a/packaging/macos/scripts/postinstall b/packaging/macos/scripts/postinstall
index 50125df..e88addd 100755
--- a/packaging/macos/scripts/postinstall
+++ b/packaging/macos/scripts/postinstall
@@ -12,6 +12,7 @@ set -x
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
APP=""
for app_path in \
+ "/Applications/Ydisks闲鱼助手/Ydisks闲鱼助手.app" \
"/Applications/Ydisks Xianyu Helper.app" \
"/Applications/Ydisks Xianyu Helper.localized/Ydisks Xianyu Helper.app"
do
@@ -21,12 +22,12 @@ do
fi
done
if [ -z "$APP" ]; then
- echo "找不到已安装的 Ydisks Xianyu Helper.app,无法继续注册服务。"
+ echo "找不到已安装的 Ydisks闲鱼助手.app,无法继续注册服务。"
exit 1
fi
SERVER="$APP/Contents/Helpers/xianyu-server"
-TRAY="$APP/Contents/MacOS/xianyu-tray"
+TRAY="$APP/Contents/MacOS/Ydisks闲鱼助手"
BROWSER_INSTALL="$APP/Contents/Helpers/browser-install"
CONSOLE_USER="$(stat -f '%Su' /dev/console)"
diff --git a/packaging/macos/scripts/preinstall b/packaging/macos/scripts/preinstall
index 2357b43..6d3cc35 100755
--- a/packaging/macos/scripts/preinstall
+++ b/packaging/macos/scripts/preinstall
@@ -10,6 +10,11 @@ printf '\n[%s] preinstall start; uid=%s; user=%s; args=%s\n' \
set -x
EXPECTED_BUNDLE_ID="com.ydisks.xianyu-helper"
+CANONICAL_APP_DIR="/Applications/Ydisks闲鱼助手"
+CANONICAL_APP_PATH="$CANONICAL_APP_DIR/Ydisks闲鱼助手.app"
+LEGACY_APP_PATH="/Applications/Ydisks Xianyu Helper.app"
+LEGACY_LOCALIZED_APP_DIR="/Applications/Ydisks Xianyu Helper.localized"
+LEGACY_LOCALIZED_APP_PATH="$LEGACY_LOCALIZED_APP_DIR/Ydisks Xianyu Helper.app"
CONSOLE_USER="$(stat -f '%Su' /dev/console)"
if [ "$CONSOLE_USER" != "root" ] && [ -n "$CONSOLE_USER" ]; then
@@ -25,8 +30,9 @@ if [ "$CONSOLE_USER" != "root" ] && [ -n "$CONSOLE_USER" ]; then
fi
for app_path in \
- "/Applications/Ydisks Xianyu Helper.app" \
- "/Applications/Ydisks Xianyu Helper.localized/Ydisks Xianyu Helper.app"
+ "$CANONICAL_APP_PATH" \
+ "$LEGACY_APP_PATH" \
+ "$LEGACY_LOCALIZED_APP_PATH"
do
if [ ! -d "$app_path" ]; then
continue
@@ -34,8 +40,12 @@ do
existing_bundle_id="$(/usr/bin/plutil -extract CFBundleIdentifier raw -o - \
"$app_path/Contents/Info.plist" 2>/dev/null || true)"
- if [ "$existing_bundle_id" != "$EXPECTED_BUNDLE_ID" ]; then
+ if [ "$app_path" != "$CANONICAL_APP_PATH" ] || [ "$existing_bundle_id" != "$EXPECTED_BUNDLE_ID" ]; then
echo "清理旧 Bundle ID 的应用:${existing_bundle_id:-未知}($app_path)"
rm -rf "$app_path"
fi
done
+
+# 只删除空的旧目录,不影响用户可能放在 Applications 中的其他内容。
+rmdir "$LEGACY_LOCALIZED_APP_DIR/.localized" >/dev/null 2>&1 || true
+rmdir "$LEGACY_LOCALIZED_APP_DIR" >/dev/null 2>&1 || true
diff --git a/packaging/macos/uninstall.command b/packaging/macos/uninstall.command
new file mode 100755
index 0000000..fa30d53
--- /dev/null
+++ b/packaging/macos/uninstall.command
@@ -0,0 +1,66 @@
+#!/bin/sh
+set -eu
+
+PRODUCT_NAME="Ydisks闲鱼助手"
+EXPECTED_BUNDLE_ID="com.ydisks.xianyu-helper"
+CONSOLE_USER="$(/usr/bin/stat -f '%Su' /dev/console)"
+
+if [ "${1:-}" != "--confirmed" ]; then
+ if ! /usr/bin/osascript <<'APPLESCRIPT'
+tell application "System Events"
+ display dialog "卸载后将删除 Ydisks闲鱼助手、后台服务、配置、数据库、Chromium 和日志。此操作不可恢复。" buttons {"取消", "卸载"} default button "取消" cancel button "取消" with title "卸载 Ydisks闲鱼助手"
+end tell
+APPLESCRIPT
+ then
+ exit 0
+ fi
+fi
+
+if [ "$(id -u)" -ne 0 ]; then
+ exec /usr/bin/sudo "$0" --confirmed
+fi
+
+if [ "$CONSOLE_USER" != "root" ] && [ -n "$CONSOLE_USER" ]; then
+ UID_VALUE="$(/usr/bin/id -u "$CONSOLE_USER")"
+ HOME_DIR="$(/usr/bin/dscl . -read "/Users/$CONSOLE_USER" NFSHomeDirectory | /usr/bin/awk '{print $2}')"
+
+ for label in \
+ "com.ydisks.xianyu-helper.server" \
+ "com.ydisks.xianyu-helper.tray" \
+ "com.christ.ydisks-xianyu-helper.server" \
+ "com.christ.ydisks-xianyu-helper.tray"
+ do
+ /bin/launchctl bootout "gui/$UID_VALUE/$label" >/dev/null 2>&1 || true
+ done
+
+ # 处理用户手动启动、但没有被 LaunchAgent 管理的旧进程。
+ for process_path in \
+ "/Applications/Ydisks闲鱼助手/Ydisks闲鱼助手.app/Contents/Helpers/xianyu-server" \
+ "/Applications/Ydisks闲鱼助手/Ydisks闲鱼助手.app/Contents/MacOS/Ydisks闲鱼助手" \
+ "/Applications/Ydisks Xianyu Helper.app/Contents/Helpers/xianyu-server" \
+ "/Applications/Ydisks Xianyu Helper.app/Contents/MacOS/xianyu-tray" \
+ "/Applications/Ydisks Xianyu Helper.localized/Ydisks Xianyu Helper.app/Contents/Helpers/xianyu-server" \
+ "/Applications/Ydisks Xianyu Helper.localized/Ydisks Xianyu Helper.app/Contents/MacOS/xianyu-tray"
+ do
+ /usr/bin/pkill -TERM -f "$process_path" >/dev/null 2>&1 || true
+ done
+
+ /bin/rm -f \
+ "$HOME_DIR/Library/LaunchAgents/com.ydisks.xianyu-helper.server.plist" \
+ "$HOME_DIR/Library/LaunchAgents/com.ydisks.xianyu-helper.tray.plist" \
+ "$HOME_DIR/Library/LaunchAgents/com.christ.ydisks-xianyu-helper.server.plist" \
+ "$HOME_DIR/Library/LaunchAgents/com.christ.ydisks-xianyu-helper.tray.plist"
+
+ /bin/rm -rf \
+ "$HOME_DIR/Library/Application Support/YdisksXianyuHelper" \
+ "$HOME_DIR/Library/Logs/YdisksXianyuHelper"
+fi
+
+/bin/rm -rf \
+ "/Applications/Ydisks闲鱼助手" \
+ "/Applications/Ydisks Xianyu Helper.app" \
+ "/Applications/Ydisks Xianyu Helper.localized"
+/usr/bin/pkgutil --forget "$EXPECTED_BUNDLE_ID" >/dev/null 2>&1 || true
+/bin/rm -f /var/log/ydisks-xianyu-helper-install.log
+
+echo "$PRODUCT_NAME 已卸载完成。"