@echo off
REM ============================================================
REM  KIOSK LAN + ONLINE - OTOMATIS
REM  Windows 7 / 10 / 11 - Edge dulu, kalau tidak ada pakai Chrome
REM  Coba dulu LAN lab: http://192.168.100.14
REM  Kalau LAN tidak bisa dijangkau, langsung pakai online:
REM  https://i3wp8yi6hh09.sman2kandangan.sch.id
REM  Buka fullscreen mode kiosk, keluar: Alt+F4
REM ============================================================
setlocal
set "URL=http://192.168.100.14"
set "URL_ONLINE=https://i3wp8yi6hh09.sman2kandangan.sch.id"

REM --- Cek LAN dulu (2x ping, maks ~2 detik) ---
ping -n 2 -w 1000 192.168.100.14 | find "TTL=" >nul
if errorlevel 1 (
  set "URL=%URL_ONLINE%"
)

REM --- Matikan browser lama supaya kiosk bersih ---
taskkill /F /IM msedge.exe >nul 2>&1
taskkill /F /IM chrome.exe >nul 2>&1
taskkill /F /IM iexplore.exe >nul 2>&1
timeout /t 2 /nobreak >nul

REM --- 1. Edge Chromium (bawaan Win 10/11, paling disarankan) ---
if exist "%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe" (
  start "" "%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe" --kiosk %URL% --edge-kiosk-type=fullscreen --inprivate --disable-save-password-bubble --no-first-run --noerrdialogs
  exit /b
)
if exist "%ProgramFiles%\Microsoft\Edge\Application\msedge.exe" (
  start "" "%ProgramFiles%\Microsoft\Edge\Application\msedge.exe" --kiosk %URL% --edge-kiosk-type=fullscreen --inprivate --disable-save-password-bubble --no-first-run --noerrdialogs
  exit /b
)

REM --- 2. Chrome (Program Files) ---
if exist "%ProgramFiles%\Google\Chrome\Application\chrome.exe" (
  start "" "%ProgramFiles%\Google\Chrome\Application\chrome.exe" --kiosk %URL% --incognito --disable-save-password-bubble --no-first-run --disable-translate --noerrdialogs
  exit /b
)
if exist "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" (
  start "" "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" --kiosk %URL% --incognito --disable-save-password-bubble --no-first-run --disable-translate --noerrdialogs
  exit /b
)

REM --- 3. Chrome instalasi per-user (sering di Win 7) ---
if exist "%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe" (
  start "" "%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe" --kiosk %URL% --incognito --disable-save-password-bubble --no-first-run --disable-translate --noerrdialogs
  exit /b
)

REM --- 4. Internet Explorer fallback (Win 7, terakhir) ---
if exist "%ProgramFiles%\Internet Explorer\iexplore.exe" (
  start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" -k %URL%
  exit /b
)
if exist "%ProgramFiles(x86)%\Internet Explorer\iexplore.exe" (
  start "" "%ProgramFiles(x86)%\Internet Explorer\iexplore.exe" -k %URL%
  exit /b
)

echo Browser Edge / Chrome / IE tidak ditemukan di PC ini.
echo Install Edge atau Chrome dulu, lalu jalankan lagi file ini.
pause
exit /b 1
