@echo off
REM ============================================================
REM  Open Paychek Safeguard — double-click this file
REM  Starts the local server in the background (no terminal)
REM  and opens the UI. Server keeps running if you close the UI;
REM  use _technique\STOP.bat to stop.
REM  Note: avoid PowerShell here — paths with "(N)" break cmd quoting.
REM ============================================================
setlocal EnableExtensions
cd /d "%~dp0"

set "TECH=%~dp0_technique"
set "STARTBAT=%TECH%\START.bat"
set "PYW=%TECH%\runtime\pythonw.exe"
set "LAUNCHER=%TECH%\src\desktop_launcher.py"

if not exist "%LAUNCHER%" (
  echo desktop_launcher.py not found. Extract the full ZIP first.
  pause
  exit /b 1
)

REM Prefer pythonw directly (no black window). Quoted paths OK with parentheses.
if exist "%PYW%" (
  start "" /D "%TECH%" "%PYW%" "%LAUNCHER%"
  exit /b 0
)

if exist "%STARTBAT%" (
  start "" /D "%TECH%" "%STARTBAT%"
  exit /b 0
)

echo START.bat / pythonw not found. Re-download the ZIP from paychek.pro.
pause
exit /b 1
