Files
Christ bfa72fd9b7 feat: 重构 macOS 安装目录与卸载流程
将 macOS 应用固定安装到 /Applications/Ydisks闲鱼助手/,应用包和托盘可执行文件统一使用 Ydisks闲鱼助手 名称。

托盘菜单栏不再显示文字标题,根据后台服务健康状态切换彩色和黑白图标。

新增完整卸载程序,停止新旧 LaunchAgent 及遗留进程,删除应用、服务配置、用户数据、Chromium 缓存和日志,并清理安装包收据。

修正 postinstall 和 preinstall 的应用路径处理,避免 macOS localized 路径导致服务 plist 生成失败。
2026-08-11 23:53:24 +08:00

52 lines
1.8 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
set -eu
INSTALL_LOG="/var/log/ydisks-xianyu-helper-install.log"
exec >>"$INSTALL_LOG" 2>&1
trap 'exit_code=$?; printf "[%s] preinstall exit code: %s\\n" "$(date -u "+%Y-%m-%dT%H:%M:%SZ")" "$exit_code"' EXIT
printf '\n[%s] preinstall start; uid=%s; user=%s; args=%s\n' \
"$(date -u '+%Y-%m-%dT%H:%M:%SZ')" "$(id -u)" "$(id -un)" "$*"
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
UID_VALUE="$(id -u "$CONSOLE_USER")"
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
launchctl bootout "gui/$UID_VALUE/$label" >/dev/null 2>&1 || true
done
fi
for app_path in \
"$CANONICAL_APP_PATH" \
"$LEGACY_APP_PATH" \
"$LEGACY_LOCALIZED_APP_PATH"
do
if [ ! -d "$app_path" ]; then
continue
fi
existing_bundle_id="$(/usr/bin/plutil -extract CFBundleIdentifier raw -o - \
"$app_path/Contents/Info.plist" 2>/dev/null || true)"
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