@echo off
rem ============================================================
rem  Live queue display panel - 300x800 dark overlay
rem  Double-click to open a borderless 300x800 window.
rem  In Douyin Live Partner: Add source - Window - pick it.
rem
rem  To change server later: edit the SERVER line below.
rem  (This file is ASCII-only on purpose: zero encoding issues.)
rem ============================================================

set "SERVER=https://www.yuyiyuanshen.online"
if not "%GQ_SERVER%"=="" set "SERVER=%GQ_SERVER%"
set "URL=%SERVER%/overlay"
set "W=300"
set "H=800"

echo.
echo   Genshin Queue - Live Display Panel
echo   --------------------------------------
echo   URL  : %URL%
echo   Size : %W% x %H%
echo.

set "BROWSER="
for %%P in (
  "%ProgramFiles%\Google\Chrome\Application\chrome.exe"
  "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe"
  "%LocalAppData%\Google\Chrome\Application\chrome.exe"
  "%ProgramFiles%\Microsoft\Edge\Application\msedge.exe"
  "%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"
  "%ProgramFiles%\BraveSoftware\Brave-Browser\Application\brave.exe"
) do (
  if exist %%P if not defined BROWSER set "BROWSER=%%~P"
)

if not defined BROWSER (
  echo   [X] Chrome / Edge / Brave not found.
  echo       Install Google Chrome or Edge, then run this again.
  echo       Or open this URL in any browser:
  echo       %URL%
  echo.
  pause
  exit /b 1
)

echo   Browser: %BROWSER%
echo   Closing leftover display windows (if any)...

rem ---- Kill any old display browser instance ----------------
rem  Chrome only applies command-line flags to the FIRST process
rem  using a user-data-dir. If an old display window survived
rem  (e.g. from yesterday), re-running this script would open a
rem  window WITHOUT the anti-freeze flags and the capture would
rem  freeze when covered. So: kill every process started with
rem  our dedicated profile dir, then start fresh.
powershell -NoProfile -Command "Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -like '*.genshin-queue-display*' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }" >nul 2>&1
timeout /t 1 >nul

echo   Opening window...

start "" "%BROWSER%" ^
  --app="%URL%" ^
  --window-size=%W%,%H% ^
  --window-position=40,80 ^
  --no-first-run ^
  --no-default-browser-check ^
  --disable-backgrounding-occluded-windows ^
  --disable-renderer-backgrounding ^
  --disable-background-timer-throttling ^
  --disable-features=Translate,CalculateNativeWinOcclusion ^
  --user-data-dir="%USERPROFILE%\.genshin-queue-display"

timeout /t 3 >nul

echo   [OK] Display window should be open now.
echo.
echo   --------------------------------------
echo   In Douyin Live Partner:
echo     Add source  -  Window  -  pick this window
echo     Drag it where you want. NO chroma key needed.
echo.
echo   The panel updates by itself - even when fully
echo   covered by other windows or games. Switching
echo   apps will NOT freeze the capture anymore.
echo   Do NOT minimize the window - covering is fine,
echo   minimizing is not.
echo.
pause
