#!/usr/bin/env bash
# Kon dev launcher. Starts Vite first, waits for it to bind port 1420,
# then runs Tauri without triggering a second Vite instance.
# For performance testing use: npm run tauri build
set -euo pipefail
cd "$(dirname "$0")"

export LIBCLANG_PATH=/usr/lib64/llvm21/lib64

printf 'Starting Vite dev server...\n' >&2
npm run dev:frontend &
VITE_PID=$!

until curl -sf http://localhost:1420 > /dev/null 2>&1; do sleep 0.5; done
printf 'Vite ready. Launching Tauri...\n' >&2

cleanup() {
    kill "$VITE_PID" 2>/dev/null || true
}
trap cleanup EXIT INT TERM

npx tauri dev --config '{"build":{"beforeDevCommand":""}}'
