#!/usr/bin/env bash # A local SubCast.app for trying changes, signed with the Developer ID like a release. # # Why sign: an ad-hoc build is known to the Keychain only by its hash, which changes on every build, so each # new build asks for the login password again to read the saved API keys. Signed with the same identity and # bundle id as the release, the Keychain recognises it as the same app: "Always Allow" once and it stays. # # scripts/dev-app.sh debug build, sign, open # scripts/dev-app.sh --fast-release fast optimized build (no LTO, incremental), sign, open # scripts/dev-app.sh --install also replace /Applications/SubCast.app before opening # scripts/dev-app.sh --with-cli force rebuilding subcast-cli (reused from cache when omitted) # scripts/dev-app.sh --no-open build, sign (and install if requested) without opening set -euo pipefail cd "$(dirname "$0")/.." export PATH="$HOME/.cargo/bin:$PATH" FAST_RELEASE=0 INSTALL=0 WITH_CLI=0 OPEN=1 while [ $# -gt 0 ]; do case "$1" in --fast-release) FAST_RELEASE=1 ;; --install) INSTALL=1 ;; --with-cli) WITH_CLI=1 ;; --no-open) OPEN=0 ;; *) echo "unknown option: $1" >&2; exit 2 ;; esac shift done START_TS=$(date +%s) IDENTITY="${APPLE_SIGNING_IDENTITY:-Developer ID Application: xiangyang qiao (BRCU3DPFH4)}" if ! security find-identity -v -p codesigning | grep -qF "$IDENTITY"; then echo "Signing identity not found: $IDENTITY (set APPLE_SIGNING_IDENTITY)" >&2 exit 1 fi TAURI_CFG='{"bundle":{"createUpdaterArtifacts":false}}' if [ "$FAST_RELEASE" = 1 ]; then PROFILE_DIR="fast-release" TAURI_FLAGS=(--bundles app --no-sign --config "$TAURI_CFG" -- --profile fast-release) CLI_CARGO_FLAGS=(--profile fast-release) else PROFILE_DIR="debug" TAURI_FLAGS=(--debug --bundles app --no-sign --config "$TAURI_CFG") CLI_CARGO_FLAGS=() fi APP="src-tauri/target/$PROFILE_DIR/bundle/macos/SubCast.app" # The running copy holds the bundle open; quit it first. osascript -e 'quit app id "ai.qiaomu.subcast"' >/dev/null 2>&1 || true APPLE_SIGNING_IDENTITY="$IDENTITY" npx tauri build "${TAURI_FLAGS[@]}" CLI_BIN="" if [ "$WITH_CLI" = 0 ]; then for cand in \ "src-tauri/target/$PROFILE_DIR/subcast-cli" \ "src-tauri/target/release/subcast-cli" \ "src-tauri/target/debug/subcast-cli" \ "/Applications/SubCast.app/Contents/MacOS/subcast-cli"; do if [ -x "$cand" ]; then CLI_BIN="$cand" break fi done fi if [ -z "$CLI_BIN" ]; then cargo build "${CLI_CARGO_FLAGS[@]}" -p subcast-cli CLI_BIN="src-tauri/target/$PROFILE_DIR/subcast-cli" fi cp "$CLI_BIN" "$APP/Contents/MacOS/subcast-cli" # Tauri signs when APPLE_SIGNING_IDENTITY is set; sign again explicitly so the result never depends on that. codesign --force --deep --options runtime --entitlements src-tauri/Entitlements.plist --sign "$IDENTITY" "$APP" codesign --verify --deep --strict "$APP" codesign -d -r- "$APP" 2>&1 | grep designated TARGET_APP="$APP" if [ "$INSTALL" = 1 ]; then rm -rf /Applications/SubCast.app ditto "$APP" /Applications/SubCast.app codesign --verify --deep --strict /Applications/SubCast.app TARGET_APP="/Applications/SubCast.app" fi echo "==> Done in $(( $(date +%s) - START_TS ))s ($TARGET_APP)" [[ "$OPEN" = 1 ]] && open "$TARGET_APP" || true