@echo off
title Wivexx — Claude Voice Assistant
color 0A
cd /d "%~dp0"

echo ════════════════════════════════════════════════
echo   Wivexx  ^|  Claude Voice Assistant
echo ════════════════════════════════════════════════
echo.

:: Check Python is installed
python --version >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Python is not installed or not in PATH.
    echo         Download it from https://www.python.org/downloads/
    echo         Make sure to check "Add Python to PATH" during install.
    pause
    exit /b 1
)

:: Warn (non-blocking) if Python is outside the tested 3.10-3.12 range
python -c "import sys; raise SystemExit(0 if (3,10)<=sys.version_info[:2]<=(3,12) else 1)" >nul 2>&1
if %errorlevel% neq 0 (
    for /f "tokens=2" %%v in ('python --version 2^>^&1') do set PYVER=%%v
    echo.
    echo [NOTE] Your Python ^(%PYVER%^) is outside the tested range 3.10-3.12.
    echo        Wivexx works best on Python 3.12. If a REQUIRED package fails to
    echo        install below, install Python 3.12 ^(64-bit^) from
    echo        https://www.python.org/downloads/ and run this again.
    echo.
)

:: Install / update packages (skipped once the pre-flight cache exists;
:: delete .wivexx_preflight.json or run "python wivexx_api.py --preflight"
:: to force a full re-check)
if exist ".wivexx_preflight.json" (
    echo Packages already verified — skipping pip install.
) else (
    echo Installing packages (only needed on first run^)...
    echo This can take a few minutes the first time.
    :: --prefer-binary picks versions that ship a prebuilt wheel, avoiding source
    :: builds that fail on a brand-new Python with no C compiler. This step is
    :: NON-FATAL: Wivexx's own pre-flight re-checks and installs anything still
    :: missing, skipping optional extras it cannot install.
    pip install -r requirements.txt --prefer-binary --disable-pip-version-check
    if %errorlevel% neq 0 (
        echo.
        echo [NOTE] Some packages did not install up front — that's OK. Wivexx will
        echo        re-check on startup and skip any OPTIONAL ones it can't install.
        echo        If it then says a REQUIRED package failed, your Python is likely
        echo        too new: install Python 3.10, 3.11 or 3.12 and run this again.
        echo.
    )
)

:: One-time convenience: drop a "Wivexx" shortcut on the Desktop so you never have
:: to open this folder again — from now on just double-click the Desktop icon. It's
:: silent and only created if one isn't already there. (If you MOVE the Wivexx
:: folder later, double-click "Create Desktop Shortcut.vbs" to point it at the new spot.)
set "WVX_DIR=%~dp0"
set "WVX_TGT=%~dp0Wivexx.vbs"
set "WVX_ICO=%~dp0wivexx.ico"
powershell -NoProfile -Command "try{$d=[Environment]::GetFolderPath('Desktop');$lnk=Join-Path $d 'Wivexx.lnk';if(-not(Test-Path $lnk)){$w=New-Object -ComObject WScript.Shell;$s=$w.CreateShortcut($lnk);$s.TargetPath=$env:WVX_TGT;$s.WorkingDirectory=$env:WVX_DIR;if(Test-Path $env:WVX_ICO){$s.IconLocation=$env:WVX_ICO+',0'};$s.Description='Wivexx - voice AI assistant';$s.Save()}}catch{}" >nul 2>&1

echo.
echo Starting Wivexx...
echo Wivexx will appear as a small circle in your system tray (bottom-right).
echo (A "Wivexx" shortcut is now on your Desktop — use it to start Wivexx next time.)
echo Right-click the tray icon to quit.
echo.

python wivexx_api.py

echo.
echo Wivexx has stopped.
pause
