#!/usr/bin/env bash
# SwiftCanvas launcher for Linux / macOS.
# 不传参数时由 app.py 自动检测显卡:无 NVIDIA 显卡自动走 CPU 模式。
# 强制 CPU 请用 ./start_cpu.sh 或 ./start.sh --cpu
set -e
cd "$(dirname "$0")"

PY="${PYTHON:-}"
if [ -z "$PY" ]; then
    if [ -x ".venv/bin/python" ]; then PY=".venv/bin/python"
    elif [ -x "venv/bin/python" ]; then PY="venv/bin/python"
    elif command -v python3 >/dev/null 2>&1; then PY="python3"
    elif command -v python >/dev/null 2>&1; then PY="python"
    else
        echo "[ERROR] Python not found. Install Python 3.10+ first." >&2
        exit 1
    fi
fi

echo "Using Python: $PY"
echo "Starting SwiftCanvas... Open browser: http://127.0.0.1:7871"
exec "$PY" app.py "$@"