Files
opsxdb/scripts/gui-dev-app.sh
logan 2c0bfafd8d 同步完整源码至远程:扁平化重构现状 + 未入库源文件
- 补入库:server/internal/db/dump.go、redis 分页/扫描预算测试、opsxdb-mcp main_test、
  packages/opsxdb-mcp package-lock、docs 审计与对比文档等 37 个新文件
- 含结构扁平化进行中的 80 处修改与 155 处旧结构删除(server/ src/ src-tauri/ 为当前有效源)
- 构建产物(bin/target/dist)与签名私钥仍按规则排除
2026-10-16 03:47:33 +08:00

105 lines
3.9 KiB
Bash

# sourced by run.sh — temp OpsxDB.app for Dock icon (icons/icon.icns)
# shellcheck shell=bash
# .noindex:避免 Spotlight 把临时 Dock 壳当成可打开的历史 App
TAURI_DIR="$SCRIPT_DIR/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"
DBG_BIN="$TAURI_DIR/target/debug/opsxdb"
GUI_DEV_NEEDS_VITE=0
_gui_write_plist() {
cat >"$GUI_APP/Contents/Info.plist" <<'PLIST'
<?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">
<dict>
<key>CFBundleDisplayName</key><string>OpsxDB</string>
<key>CFBundleExecutable</key><string>OpsxDB</string>
<key>CFBundleIconFile</key><string>icon.icns</string>
<key>CFBundleIdentifier</key><string>com.opsx.db.dev</string>
<key>CFBundleName</key><string>OpsxDB</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>0.1.0-dev</string>
<key>CFBundleVersion</key><string>0</string>
<key>LSHighResolutionCapable</key><true/>
</dict>
</plist>
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/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 [ -x "$DBG_BIN" ]; then
rm -rf "$GUI_APP"
_gui_wrap_bin "$DBG_BIN"
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"
/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/src-tauri/target/debug/opsxdb" 2>/dev/null || true
pkill -f "$SCRIPT_DIR/src-tauri/target/debug/opsxdb-desktop" 2>/dev/null || true
pkill -f "$SCRIPT_DIR/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
}