Files
navop/script/bundle-macos.sh
T
胡飞 a701121637 feat(branding): Shell 与 Data 换成各自的图标,三个产品不再共用一套
之前三个产品共用 resources/windows/navop.ico、macOS 的 Navop.icns 与 Linux 的
三张 navop png(Shell/Data 的 png 只是复制品),装在一起几乎分不出来。

- 新增 script/generate-product-icons.py:同一套视觉语言(深蓝圆角底 + 青蓝渐变
  前景),Shell 用终端提示符、Data 用数据库柱体,输出 Linux PNG(128/256/512)、
  macOS ICNS、Windows ICO(16~256)。
- macOS:bundle-macos.sh 按产品选 Navop / NavopShell / NavopData 的 icns,
  Info.plist 的 CFBundleIconFile 仍是 Navop,拷贝时统一重命名。
- Windows:apps/navop-shell|navop-data/build.rs 嵌入各自的 ico;独立产品的
  MSI/卸载项通过 build-product-installer.ps1 的 -IconPath 传入产品图标。
- Linux:package-linux-product.sh 本来就读 <product>-<size>.png,把复制的
  png 换成新绘制的一套。
- 打包测试补「每个产品都有自己的图标」:build.rs 的 ico 路径、macOS icns 映射、
  Linux 三尺寸 png、独立产品安装包 -IconPath。
2026-11-03 13:50:22 +08:00

118 lines
4.3 KiB
Bash
Executable File
Raw 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/bash
set -euo pipefail
PRODUCT="${NAVOP_PRODUCT:-${ONETCLI_PRODUCT:-${2:-navop}}}"
case "$PRODUCT" in
navop)
APP_NAME="Navop"
BINARY_NAME="navop"
BUNDLE_ID="com.onetcli.app"
PACKAGE_NAME="navop"
ICNS_NAME="Navop"
INCLUDE_DOCUMENT_TYPES=1
;;
navop-shell)
APP_NAME="Navop Shell"
BINARY_NAME="navop-shell"
BUNDLE_ID="com.navop.shell"
PACKAGE_NAME="navop-shell"
ICNS_NAME="NavopShell"
INCLUDE_DOCUMENT_TYPES=0
;;
navop-data)
APP_NAME="Navop Data"
BINARY_NAME="navop-data"
BUNDLE_ID="com.navop.data"
PACKAGE_NAME="navop-data"
ICNS_NAME="NavopData"
INCLUDE_DOCUMENT_TYPES=0
;;
*)
echo "Error: unknown product '${PRODUCT}' (expected navop, navop-shell, navop-data)"
exit 1
;;
esac
TARGET="${1:-aarch64-apple-darwin}"
VERSION="${ONETCLI_VERSION:-0.1.0}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SOURCE_PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PROJECT_DIR="${ONETCLI_PROJECT_DIR:-$SOURCE_PROJECT_DIR}"
RESOURCE_DIR="${ONETCLI_MACOS_RESOURCE_DIR:-${PROJECT_DIR}/resources/macos}"
APP_DIR="${PROJECT_DIR}/target/${APP_NAME}.app"
echo "Bundling ${APP_NAME}.app for ${TARGET} (version: ${VERSION})..."
# Clean previous bundle
rm -rf "$APP_DIR"
# Create .app directory structure
mkdir -p "$APP_DIR/Contents/MacOS"
mkdir -p "$APP_DIR/Contents/Resources"
# Copy binary
BINARY_PATH="${ONETCLI_BINARY_PATH:-${PROJECT_DIR}/target/${TARGET}/release/${BINARY_NAME}}"
if [ ! -f "$BINARY_PATH" ]; then
echo "Error: Binary not found at ${BINARY_PATH}"
echo "Run: cargo build --release -p ${PACKAGE_NAME} --target ${TARGET}"
exit 1
fi
cp "$BINARY_PATH" "$APP_DIR/Contents/MacOS/${BINARY_NAME}"
# Copy Info.plist and substitute product identity. The full product keeps the
# historical bundle id so upgrades, keychain items and file associations are
# preserved; standalone products get their own identity.
if [ "$INCLUDE_DOCUMENT_TYPES" = "1" ]; then
sed -e "s/\${ONETCLI_VERSION}/${VERSION}/g" \
-e "s|com.onetcli.app|${BUNDLE_ID}|g" \
-e "/<key>CFBundleName<\/key>/{n;s|<string>Navop</string>|<string>${APP_NAME}</string>|;}" \
-e "/<key>CFBundleDisplayName<\/key>/{n;s|<string>Navop</string>|<string>${APP_NAME}</string>|;}" \
-e "/<key>CFBundleExecutable<\/key>/{n;s|<string>navop</string>|<string>${BINARY_NAME}</string>|;}" \
"${RESOURCE_DIR}/Info.plist" \
> "$APP_DIR/Contents/Info.plist"
else
sed -e "s/\${ONETCLI_VERSION}/${VERSION}/g" \
-e "s|com.onetcli.app|${BUNDLE_ID}|g" \
-e "/<key>CFBundleName<\/key>/{n;s|<string>Navop</string>|<string>${APP_NAME}</string>|;}" \
-e "/<key>CFBundleDisplayName<\/key>/{n;s|<string>Navop</string>|<string>${APP_NAME}</string>|;}" \
-e "/<key>CFBundleExecutable<\/key>/{n;s|<string>navop</string>|<string>${BINARY_NAME}</string>|;}" \
-e "/<!-- NAVOP_DOCUMENT_TYPES_START -->/,/<!-- NAVOP_DOCUMENT_TYPES_END -->/d" \
"${RESOURCE_DIR}/Info.plist" \
> "$APP_DIR/Contents/Info.plist"
fi
# Copy icon(三个产品各有自己的 icns,Info.plist 的 CFBundleIconFile 都是 Navop,
# 所以统一拷成 Navop.icns)
ICNS_PATH="${RESOURCE_DIR}/${ICNS_NAME}.icns"
if [ ! -f "$ICNS_PATH" ]; then
echo "Error: Icon file not found at ${ICNS_PATH}"
exit 1
fi
cp "$ICNS_PATH" "$APP_DIR/Contents/Resources/Navop.icns"
# Write PkgInfo
echo -n "APPL????" > "$APP_DIR/Contents/PkgInfo"
# Sign the app bundle before packaging it. A real Developer ID identity is
# preferred; ad-hoc signing still binds Info.plist and the bundle identifier.
APP_SIGN_IDENTITY="${MACOS_APP_SIGN_IDENTITY:-${MACOS_SIGN_IDENTITY:--}}"
if [ "$APP_SIGN_IDENTITY" = "-" ]; then
echo "Ad-hoc signing ${APP_NAME}.app..."
codesign --force --deep --sign - "$APP_DIR"
else
echo "Signing ${APP_NAME}.app with identity: ${APP_SIGN_IDENTITY}"
codesign \
--force \
--deep \
--options runtime \
--timestamp \
--sign "$APP_SIGN_IDENTITY" \
"$APP_DIR"
fi
codesign --verify --deep --strict --verbose=2 "$APP_DIR"
echo "Successfully built: ${APP_DIR}"
echo "Contents:"
ls -la "$APP_DIR/Contents/"
ls -la "$APP_DIR/Contents/MacOS/"
ls -la "$APP_DIR/Contents/Resources/"