set shell := ["C:/Program Files/Git/usr/bin/bash.exe", "-c"]
set unstable := true

android_sdk := replace(env('LOCALAPPDATA'), '\', '/') / "Android/Sdk"
adb := android_sdk / "platform-tools/adb.exe"
avd := android_sdk / "cmdline-tools/latest/bin/avdmanager.bat"
emulator := android_sdk / "emulator/emulator.exe"
camera_virtual := "-camera-back virtualscene -virtualscene-poster wall=\"" + (justfile_directory() / "TestImages/reference_alpha/serra_angel.jpg") + "\""
camera_webcam := "-camera-back webcam0 -camera-front webcam0"

default camera="virtual":
    {{ emulator }} -avd Pixel_6 {{ if camera == "virtual" { camera_virtual } else { camera_webcam } }} -no-snapshot-load -gpu host

install:
    {{ avd }} delete avd -n Pixel_6
    {{ avd }} create avd -n Pixel_6 -k "system-images;android-36;google_apis_playstore;x86_64" -d pixel_6

# Wait for emulator to fully boot (timeout after 2 minutes)
[script]
emu-wait:
    # Wait for Android emulator to boot with timeout
    TIMEOUT=120

    echo "Waiting for emulator to boot..."

    for ((i=TIMEOUT; i>0; i--)); do
        if [ "$({{ adb }} shell getprop sys.boot_completed 2>/dev/null)" = "1" ]; then
            echo "Emulator ready"
            exit 0
        fi
        sleep 1
    done

    echo "Emulator failed to boot within 2 minutes"
    exit 1
