start-digital-human-chrome.bat 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. @echo off
  2. REM Digital Human Chrome Kiosk Mode Startup Script (Silent Background Mode)
  3. REM Function: Auto start frontend and backend services silently, then open Chrome in kiosk mode with hidden taskbar
  4. REM Run silently using VBScript wrapper
  5. if not "%1"=="hidden" (
  6. REM Create a temporary VBScript to run this batch file silently
  7. echo Set WshShell = CreateObject("WScript.Shell"^) > "%TEMP%\run_silent.vbs"
  8. echo WshShell.Run """%~f0"" hidden", 0, False >> "%TEMP%\run_silent.vbs"
  9. cscript //nologo "%TEMP%\run_silent.vbs"
  10. del "%TEMP%\run_silent.vbs"
  11. exit /b
  12. )
  13. REM Keep window open (but hidden)
  14. setlocal enabledelayedexpansion
  15. REM Use GBK encoding for Chinese characters (Windows default)
  16. chcp 936 >nul 2>&1
  17. REM Configuration
  18. set FRONTEND_URL=http://localhost:3000/sentio
  19. set BACKEND_URL=http://localhost:8000
  20. set WAIT_TIME=10
  21. set CHECK_INTERVAL=2
  22. REM Get script directory and project root (parent directory)
  23. set "SCRIPT_DIR=%~dp0"
  24. set "PROJECT_ROOT=%SCRIPT_DIR%.."
  25. REM Remove trailing backslash if present
  26. if "%PROJECT_ROOT:~-1%"=="\" set "PROJECT_ROOT=%PROJECT_ROOT:~0,-1%"
  27. set "WEB_DIR=%PROJECT_ROOT%\web"
  28. REM Find Chrome browser path
  29. set "CHROME_PATH="
  30. REM Check Qoom Chrome (user specified path) - try different possible exe names
  31. if exist "C:\Program Files\Qoom Chrome\chrome.exe" (
  32. set "CHROME_PATH=C:\Program Files\Qoom Chrome\chrome.exe"
  33. goto found_chrome
  34. )
  35. if exist "C:\Program Files\Qoom Chrome\QoomChrome.exe" (
  36. set "CHROME_PATH=C:\Program Files\Qoom Chrome\QoomChrome.exe"
  37. goto found_chrome
  38. )
  39. if exist "C:\Program Files\Qoom Chrome\Qoom Chrome.exe" (
  40. set "CHROME_PATH=C:\Program Files\Qoom Chrome\Qoom Chrome.exe"
  41. goto found_chrome
  42. )
  43. if exist "C:\Program Files\Qoom Chrome\Application\chrome.exe" (
  44. set "CHROME_PATH=C:\Program Files\Qoom Chrome\Application\chrome.exe"
  45. goto found_chrome
  46. )
  47. REM Check common Google Chrome installation paths
  48. if exist "%ProgramFiles%\Google\Chrome\Application\chrome.exe" (
  49. set "CHROME_PATH=%ProgramFiles%\Google\Chrome\Application\chrome.exe"
  50. goto found_chrome
  51. )
  52. if exist "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" (
  53. set "CHROME_PATH=%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe"
  54. goto found_chrome
  55. )
  56. if exist "%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe" (
  57. set "CHROME_PATH=%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe"
  58. goto found_chrome
  59. )
  60. REM Try to find from registry
  61. for /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" /ve 2^>nul ^| findstr /i "REG_SZ"') do (
  62. set "CHROME_PATH=%%b"
  63. if exist "!CHROME_PATH!" (
  64. goto found_chrome
  65. )
  66. )
  67. REM Try to find from user registry
  68. for /f "tokens=2*" %%a in ('reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" /ve 2^>nul ^| findstr /i "REG_SZ"') do (
  69. set "CHROME_PATH=%%b"
  70. if exist "!CHROME_PATH!" (
  71. goto found_chrome
  72. )
  73. )
  74. REM If still not found, exit silently (log to file for debugging)
  75. echo Chrome not found at %date% %time% >> "%TEMP%\digital_human_error.log"
  76. exit /b 1
  77. :found_chrome
  78. REM Check web directory
  79. if not exist "%WEB_DIR%" (
  80. echo Web directory not found at %date% %time% >> "%TEMP%\digital_human_error.log"
  81. exit /b 1
  82. )
  83. REM Check Node.js
  84. where node >nul 2>&1
  85. if errorlevel 1 (
  86. echo Node.js not found at %date% %time% >> "%TEMP%\digital_human_error.log"
  87. exit /b 1
  88. )
  89. REM Check Python
  90. where python >nul 2>&1
  91. if errorlevel 1 (
  92. echo Python not found at %date% %time% >> "%TEMP%\digital_human_error.log"
  93. exit /b 1
  94. )
  95. REM Prevent system sleep/hibernate
  96. REM Disable sleep/hibernate timeouts
  97. powercfg /change standby-timeout-ac 0 >nul 2>&1
  98. powercfg /change standby-timeout-dc 0 >nul 2>&1
  99. powercfg /change hibernate-timeout-ac 0 >nul 2>&1
  100. powercfg /change hibernate-timeout-dc 0 >nul 2>&1
  101. REM Keep display on (set to 0 = never turn off)
  102. powercfg /change monitor-timeout-ac 0 >nul 2>&1
  103. powercfg /change monitor-timeout-dc 0 >nul 2>&1
  104. REM Use SetThreadExecutionState API to prevent sleep (more reliable)
  105. if exist "%~dp0prevent-sleep.ps1" (
  106. powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File "%~dp0prevent-sleep.ps1" 2>nul
  107. ) else (
  108. REM Fallback: inline PowerShell command
  109. powershell -WindowStyle Hidden -Command "$code = '[DllImport(\"kernel32.dll\")] public static extern uint SetThreadExecutionState(uint esFlags); public const uint ES_CONTINUOUS = 0x80000000; public const uint ES_SYSTEM_REQUIRED = 0x00000001; public const uint ES_DISPLAY_REQUIRED = 0x00000002; public static void PreventSleep() { SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); }'; Add-Type -MemberDefinition $code -Name Win32 -Namespace System; [System.Win32]::PreventSleep()" 2>nul
  110. )
  111. REM Hide taskbar using PowerShell script (if script exists)
  112. if exist "%~dp0hide-taskbar.ps1" (
  113. powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File "%~dp0hide-taskbar.ps1" 2>nul
  114. )
  115. REM Start frontend service silently (completely hidden)
  116. powershell -WindowStyle Hidden -Command "Start-Process -FilePath 'cmd.exe' -ArgumentList '/c', 'cd /d %WEB_DIR% && npm run dev' -WindowStyle Hidden" 2>nul
  117. if errorlevel 1 (
  118. REM Fallback: use start /min if PowerShell fails
  119. start /min "" cmd /c "cd /d %WEB_DIR% && npm run dev >nul 2>&1"
  120. )
  121. REM Start backend service silently (completely hidden)
  122. powershell -WindowStyle Hidden -Command "Start-Process -FilePath 'cmd.exe' -ArgumentList '/c', 'cd /d %PROJECT_ROOT% && python main.py' -WindowStyle Hidden" 2>nul
  123. if errorlevel 1 (
  124. REM Fallback: use start /min if PowerShell fails
  125. start /min "" cmd /c "cd /d %PROJECT_ROOT% && python main.py >nul 2>&1"
  126. )
  127. REM Wait for services to start
  128. timeout /t %WAIT_TIME% /nobreak >nul
  129. REM Open Chrome in kiosk mode with fullscreen and hidden taskbar
  130. REM --kiosk: Fullscreen kiosk mode (hides taskbar automatically)
  131. REM --start-fullscreen: Start in fullscreen mode
  132. REM --disable-infobars: Hide info bars
  133. REM --autoplay-policy: Allow autoplay
  134. REM Create Chrome user data directory for persistent permissions
  135. set "CHROME_USER_DATA=%TEMP%\chrome-digital-human"
  136. if not exist "%CHROME_USER_DATA%" mkdir "%CHROME_USER_DATA%"
  137. REM Setup Chrome permissions for microphone access (if script exists)
  138. if exist "%~dp0setup-chrome-permissions.ps1" (
  139. powershell -ExecutionPolicy Bypass -WindowStyle Hidden -Command "& '%~dp0setup-chrome-permissions.ps1' -ChromeUserData '%CHROME_USER_DATA%' -Origin '%FRONTEND_URL%'" 2>nul
  140. )
  141. REM Open Chrome in kiosk mode with microphone auto-permission
  142. REM Note: Removed --use-fake-ui-for-media-stream and --use-fake-device-for-media-stream to allow real microphone access
  143. REM --unsafely-treat-insecure-origin-as-secure: Allow localhost to access media devices
  144. REM --user-data-dir: Use separate user data directory to persist permissions
  145. start "" "%CHROME_PATH%" --kiosk --start-fullscreen --kiosk-printing --disable-infobars --disable-session-crashed-bubble --disable-restore-session-state --no-first-run --disable-features=TranslateUI --autoplay-policy=no-user-gesture-required --force-device-scale-factor=1 --disable-features=AutoHideScrollbars --force-color-profile=srgb --disable-pinch --overscroll-history-navigation=0 --disable-background-networking --disable-background-timer-throttling --disable-breakpad --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-domain-reliability --disable-features=AudioServiceOutOfProcess --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --disable-translate --metrics-recording-only --no-first-run --safebrowsing-disable-auto-update --disable-blink-features=AutomationControlled --exclude-switches=enable-automation --password-store=basic --use-mock-keychain --user-data-dir="%CHROME_USER_DATA%" --enable-features=UseModernMediaControls --unsafely-treat-insecure-origin-as-secure=%FRONTEND_URL% --allow-running-insecure-content "%FRONTEND_URL%"
  146. REM Keep script running silently and prevent sleep continuously
  147. :loop
  148. REM Refresh sleep prevention every 30 seconds to ensure it stays active
  149. if exist "%~dp0prevent-sleep.ps1" (
  150. powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File "%~dp0prevent-sleep.ps1" 2>nul
  151. ) else (
  152. powershell -WindowStyle Hidden -Command "$code = '[DllImport(\"kernel32.dll\")] public static extern uint SetThreadExecutionState(uint esFlags); public const uint ES_CONTINUOUS = 0x80000000; public const uint ES_SYSTEM_REQUIRED = 0x00000001; public const uint ES_DISPLAY_REQUIRED = 0x00000002; public static void PreventSleep() { SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); }'; Add-Type -MemberDefinition $code -Name Win32 -Namespace System; [System.Win32]::PreventSleep()" 2>nul
  153. )
  154. timeout /t 30 /nobreak >nul
  155. goto loop