feat: 重构 macOS 安装目录与卸载流程
将 macOS 应用固定安装到 /Applications/Ydisks闲鱼助手/,应用包和托盘可执行文件统一使用 Ydisks闲鱼助手 名称。 托盘菜单栏不再显示文字标题,根据后台服务健康状态切换彩色和黑白图标。 新增完整卸载程序,停止新旧 LaunchAgent 及遗留进程,删除应用、服务配置、用户数据、Chromium 缓存和日志,并清理安装包收据。 修正 postinstall 和 preinstall 的应用路径处理,避免 macOS localized 路径导致服务 plist 生成失败。
This commit is contained in:
1 parent
9cb50a229c
commit
bfa72fd9b7
9 files changed
+136
-27
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 117 KiB |
+13
-6
@@ -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 {
|
||||
|
||||
+13
-9
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.ydisks.xianyu-helper</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Ydisks Xianyu Helper</string>
|
||||
<string>Ydisks闲鱼助手</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>闲鱼管家</string>
|
||||
<string>Ydisks闲鱼助手</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleVersion</key>
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>LSUIElement</key>
|
||||
<true/>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>xianyu-tray</string>
|
||||
<string>Ydisks闲鱼助手</string>
|
||||
<key>CFBundleIconName</key>
|
||||
<string>AppIcon</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
|
||||
@@ -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" \
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<array>
|
||||
<dict>
|
||||
<key>RootRelativeBundlePath</key>
|
||||
<string>Applications/Ydisks闲鱼助手/Ydisks闲鱼助手.app</string>
|
||||
<key>BundleIsRelocatable</key>
|
||||
<false/>
|
||||
<key>BundleIsVersionChecked</key>
|
||||
<false/>
|
||||
<key>BundleHasStrictIdentifier</key>
|
||||
<true/>
|
||||
<key>BundleOverwriteAction</key>
|
||||
<string>upgrade</string>
|
||||
</dict>
|
||||
</array>
|
||||
</plist>
|
||||
@@ -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)"
|
||||
|
||||
|
||||
@@ -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
|
||||
Executable
+66
@@ -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 已卸载完成。"
|
||||
Reference in new issue
Block a user