@echo off
setlocal enabledelayedexpansion
title Codice Labs + KK Music Virtual CDJ — Windows Desktop Launcher

:: ============================================================================
:: Codice Labs + KK Music Virtual CDJ — Standalone Desktop Launcher & Setup
:: Launches Virtual CDJ in hardware-accelerated App Mode (Edge / Chrome)
:: and optionally creates a Desktop shortcut.
:: ============================================================================

set "APP_NAME=Codice Labs Virtual CDJ"
set "APP_URL=https://studio.jukkamusic.com.br"
if not "%~1"=="" set "APP_URL=%~1"

echo.
echo ====================================================================
echo   CODICE LABS + KK MUSIC — VIRTUAL CDJ DESKTOP LAUNCHER (WINDOWS)
echo ====================================================================
echo   Target URL: %APP_URL%
echo.

:: Locate Microsoft Edge or Google Chrome for standalone --app window mode
set "BROWSER_EXE="
if exist "%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe" (
    set "BROWSER_EXE=%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"
) else if exist "%ProgramFiles%\Microsoft\Edge\Application\msedge.exe" (
    set "BROWSER_EXE=%ProgramFiles%\Microsoft\Edge\Application\msedge.exe"
) else if exist "%ProgramFiles%\Google\Chrome\Application\chrome.exe" (
    set "BROWSER_EXE=%ProgramFiles%\Google\Chrome\Application\chrome.exe"
) else if exist "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" (
    set "BROWSER_EXE=%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe"
) else if exist "%LocalAppData%\Google\Chrome\Application\chrome.exe" (
    set "BROWSER_EXE=%LocalAppData%\Google\Chrome\Application\chrome.exe"
)

echo   [1] Launch Virtual CDJ Desktop App now
echo   [2] Create Desktop Shortcut + Launch
echo   [3] Exit
echo.
set /p "CHOICE=Select an option (1-3) [default 1]: "
if "%CHOICE%"=="" set "CHOICE=1"
if "%CHOICE%"=="3" goto :eof

if "%CHOICE%"=="2" (
    call :create_shortcut
)

echo.
echo Launching %APP_NAME%...
if defined BROWSER_EXE (
    start "" "%BROWSER_EXE%" --app="%APP_URL%" --window-size=1440,900
) else (
    echo Edge/Chrome not found in standard paths. Opening in default browser...
    start "" "%APP_URL%"
)

echo Done! You can close this window.
timeout /t 2 >nul
goto :eof

:create_shortcut
set "SHORTCUT_PATH=%USERPROFILE%\Desktop\%APP_NAME%.lnk"
if defined BROWSER_EXE (
    powershell -NoProfile -ExecutionPolicy Bypass -Command ^
      "$ws = New-Object -ComObject WScript.Shell; ^
       $s = $ws.CreateShortcut('%SHORTCUT_PATH%'); ^
       $s.TargetPath = '%BROWSER_EXE%'; ^
       $s.Arguments = '--app=%APP_URL% --window-size=1440,900'; ^
       $s.Description = 'Codice Labs + KK Music Virtual CDJ'; ^
       $s.Save()" >nul 2>&1
    if exist "%SHORTCUT_PATH%" (
        echo [OK] Desktop shortcut created: %SHORTCUT_PATH%
    ) else (
        echo [WARN] Could not create Desktop shortcut automatically.
    )
) else (
    echo [INFO] Creating URL shortcut on Desktop...
    (
        echo [InternetShortcut]
        echo URL=%APP_URL%
    ) > "%USERPROFILE%\Desktop\%APP_NAME%.url"
)
goto :eof
