@echo off
title PC Management System
cls

echo ---------------------------------------------------
echo  Starting PC Management System Live...
echo ---------------------------------------------------

if exist "system\python_embed\python.exe" (
    set "PY_CMD=system\python_embed\python.exe"
) else (
    set "PY_CMD=python"
)

rem Check if Flask is installed
"%PY_CMD%" -c "import flask_socketio" 2>nul
if %errorlevel% neq 0 (
    echo.
    echo [Setup] First time setup is running...
    echo [Setup] Installing required packages...
    "%PY_CMD%" -m pip install flask flask-socketio --quiet
    echo [Setup] Done.
    echo.
)

:restart
echo Starting server...
"%PY_CMD%" -W ignore::DeprecationWarning "system/server.py"

if %errorlevel% neq 0 (
    echo Server stopped unexpectedly. Restarting in 5 seconds...
    echo (Press Ctrl+C to stop)
    timeout /t 5 /nobreak > nul
    goto restart
)