# sourced by run.sh — temp OpsxDB.app for Dock icon (icons/icon.icns) # shellcheck shell=bash # .noindex:避免 Spotlight 把临时 Dock 壳当成可打开的历史 App TAURI_DIR="$SCRIPT_DIR/apps/desktop/src-tauri" GUI_APP_DIR="$TAURI_DIR/target/gui-app.noindex" GUI_APP="$GUI_APP_DIR/OpsxDB.app" ICONS_DIR="$TAURI_DIR/icons" REL_APP="$TAURI_DIR/target/release/bundle/macos/OpsxDB.app" DBG_APP="$TAURI_DIR/target/debug/bundle/macos/OpsxDB.app" REL_BIN="$TAURI_DIR/target/release/OpsxDB" [ -x "$REL_BIN" ] || REL_BIN="$SCRIPT_DIR/src-tauri/target/release/OpsxDB" DBG_BIN_A="$TAURI_DIR/target/debug/OpsxDB" [ -x "$DBG_BIN_A" ] || DBG_BIN_A="$SCRIPT_DIR/src-tauri/target/debug/OpsxDB" DBG_BIN_B="$TAURI_DIR/target/debug/opsxdb-desktop" [ -x "$DBG_BIN_B" ] || DBG_BIN_B="$SCRIPT_DIR/src-tauri/target/debug/opsxdb-desktop" GUI_DEV_NEEDS_VITE=0 _gui_write_plist() { cat >"$GUI_APP/Contents/Info.plist" <<'PLIST' CFBundleDisplayNameOpsxDB CFBundleExecutableOpsxDB CFBundleIconFileicon.icns CFBundleIdentifiercom.opsx.db.dev CFBundleNameOpsxDB CFBundlePackageTypeAPPL CFBundleShortVersionString0.1.0-dev CFBundleVersion0 LSHighResolutionCapable PLIST } _gui_wrap_bin() { local src="$1" mkdir -p "$GUI_APP/Contents/MacOS" "$GUI_APP/Contents/Resources" cp "$src" "$GUI_APP/Contents/MacOS/OpsxDB" chmod +x "$GUI_APP/Contents/MacOS/OpsxDB" local sidecar="" for sidecar in \ "$(dirname "$src")/opsxdb-server" \ "$SCRIPT_DIR/apps/server/bin/opsxdb-server" \ "$SCRIPT_DIR/src-tauri/target/debug/opsxdb-server" do if [ -x "$sidecar" ]; then cp "$sidecar" "$GUI_APP/Contents/MacOS/opsxdb-server" chmod +x "$GUI_APP/Contents/MacOS/opsxdb-server" break fi done _gui_write_plist } ensure_gui_dev_app() { local icon="$ICONS_DIR/icon.icns" GUI_DEV_NEEDS_VITE=0 if [ ! -f "$icon" ]; then error "缺少 ${icon}" return 1 fi mkdir -p "$GUI_APP_DIR" if [ -d "$DBG_APP" ]; then rm -rf "$GUI_APP" cp -R "$DBG_APP" "$GUI_APP" GUI_DEV_NEEDS_VITE=1 elif [ -x "$DBG_BIN_A" ]; then rm -rf "$GUI_APP" _gui_wrap_bin "$DBG_BIN_A" GUI_DEV_NEEDS_VITE=1 elif [ -x "$DBG_BIN_B" ]; then rm -rf "$GUI_APP" _gui_wrap_bin "$DBG_BIN_B" GUI_DEV_NEEDS_VITE=1 elif [ -d "$REL_APP" ]; then rm -rf "$GUI_APP" cp -R "$REL_APP" "$GUI_APP" elif [ -x "$REL_BIN" ]; then rm -rf "$GUI_APP" _gui_wrap_bin "$REL_BIN" else error "没有可包装的桌面二进制。请先 ./run.sh gui 走一次 tauri 编译,或 npm run tauri -- build --no-bundle。" return 1 fi mkdir -p "$GUI_APP/Contents/Resources" cp "$icon" "$GUI_APP/Contents/Resources/icon.icns" if [ -x "$GUI_APP/Contents/MacOS/opsxdb-desktop" ] && [ ! -x "$GUI_APP/Contents/MacOS/OpsxDB" ]; then mv "$GUI_APP/Contents/MacOS/opsxdb-desktop" "$GUI_APP/Contents/MacOS/OpsxDB" fi /usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName OpsxDB" "$GUI_APP/Contents/Info.plist" 2>/dev/null || true /usr/libexec/PlistBuddy -c "Set :CFBundleName OpsxDB" "$GUI_APP/Contents/Info.plist" 2>/dev/null || true /usr/libexec/PlistBuddy -c "Set :CFBundleExecutable OpsxDB" "$GUI_APP/Contents/Info.plist" 2>/dev/null || true /usr/libexec/PlistBuddy -c "Set :CFBundleIconFile icon.icns" "$GUI_APP/Contents/Info.plist" 2>/dev/null || true /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier com.opsx.db.dev" "$GUI_APP/Contents/Info.plist" 2>/dev/null || true local stamp stamp="$(date +%Y%m%d%H%M%S)" /usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${stamp}" "$GUI_APP/Contents/Info.plist" 2>/dev/null || true touch "$GUI_APP" success "临时 .app 已刷 icons/icon.icns → ${GUI_APP}" } kill_opsxdb_gui() { stop_detached "$DESKTOP_LABEL" pkill -f "$SCRIPT_DIR/apps/desktop/src-tauri/target/debug/OpsxDB" 2>/dev/null || true pkill -f "$SCRIPT_DIR/apps/desktop/src-tauri/target/debug/opsxdb-desktop" 2>/dev/null || true pkill -f "$SCRIPT_DIR/src-tauri/target/debug/opsxdb-desktop" 2>/dev/null || true pkill -f "$SCRIPT_DIR/src-tauri/target/debug/OpsxDB" 2>/dev/null || true pkill -f "$SCRIPT_DIR/apps/desktop/node_modules/.bin/tauri" 2>/dev/null || true pkill -f "$GUI_APP" 2>/dev/null || true pkill -f "$SCRIPT_DIR/src-tauri/target/gui-app.noindex/OpsxDB.app" 2>/dev/null || true pkill -x OpsxDB 2>/dev/null || true } gui_is_running() { pgrep -f "$GUI_APP/Contents/MacOS/" >/dev/null 2>&1 \ || pgrep -x OpsxDB >/dev/null 2>&1 }