#!/bin/bash
set -euo pipefail
MACOS="$(cd "$(dirname "$0")" && pwd -P)"
ROOT="$(cd "$MACOS/../../../../.." && pwd)"
if ! (cd "$MACOS/../Resources" && /usr/bin/shasum -a 256 -c executable.sha256); then
    echo "Canonical preview checksum mismatch; refusing launch." >&2
    exit 1
fi
SHA="$(cat "$MACOS/../Resources/source-commit.txt")"
# Canonical macOS state lives under ~/Library/Application Support/com.bongkert.studio.
# Revision-specific portable roots split recents and preferences on every rebuild.
unset BONGKERT_PORTABLE_ROOT CONCAT_PORTABLE_ROOT
mkdir -p "$ROOT/evidence"
export RUST_BACKTRACE=1
cd "$ROOT"
if test "$#" -eq 0; then
    if test -f "$ROOT/fixtures/translation-preview/concat.json"; then
        set -- --translation-preview "$ROOT/fixtures/translation-preview"
    else
        echo "Translation preview fixture is absent; opening the native project chooser." >&2
    fi
fi
exec "$MACOS/bongkert-studio" "$@" >> "$ROOT/evidence/preview-$SHA.log" 2>&1
