Fix GUI launch entries

This commit is contained in:
Your Name committed 2026-06-18 16:49:38 +08:00
1 parent 8dbaab9d27
commit c557ce0dfb
3 files changed
+33 -35

No files matched your search

+8 -1
View File
@@ -1,5 +1,13 @@
from __future__ import annotations from __future__ import annotations
import sys
from pathlib import Path
_BASE_DIR = Path(__file__).resolve().parent.parent
if str(_BASE_DIR) not in sys.path:
sys.path.insert(0, str(_BASE_DIR))
from douyin.updater.bootstrap import run_startup_update_check_early from douyin.updater.bootstrap import run_startup_update_check_early
@@ -10,4 +18,3 @@ from gui.dashboard_app.app import main # noqa: E402
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+23 -32
View File
@@ -17,9 +17,8 @@ if errorlevel 1 (
goto :cleanup goto :cleanup
) )
REM Save current directory to variable (for delayed expansion) REM Save current project root directory to variable (for delayed expansion)
set "WORK_DIR=%~dp0.." set "WORK_DIR=%CD%"
set "WORK_DIR=!WORK_DIR:~0,-1!"
REM Create log file REM Create log file
set "LOG_FILE=%~dp0webgui_startup.log" set "LOG_FILE=%~dp0webgui_startup.log"
@@ -50,11 +49,11 @@ echo.
REM [2/6] Check required files REM [2/6] Check required files
echo [2/6] Checking required files... echo [2/6] Checking required files...
if not exist "gui\web_gui.py" ( if not exist "gui\web_gui_entry.py" (
echo [ERROR] web_gui.py not found echo [ERROR] web_gui_entry.py not found
echo Current directory: !WORK_DIR! echo Current directory: !WORK_DIR!
echo Expected path: !WORK_DIR!\gui\web_gui.py echo Expected path: !WORK_DIR!\gui\web_gui_entry.py
echo [ERROR] web_gui.py does not exist >> "%LOG_FILE%" echo [ERROR] web_gui_entry.py does not exist >> "%LOG_FILE%"
pause pause
goto :cleanup goto :cleanup
) )
@@ -64,15 +63,15 @@ echo.
REM [3/6] Stop old processes REM [3/6] Stop old processes
echo [3/6] Stopping old processes... echo [3/6] Stopping old processes...
REM Silently stop old processes, redirect all output to nul to avoid garbled text REM Silently stop old processes, redirect all output to nul to avoid garbled text
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='SilentlyContinue'; Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {$_.CommandLine -like '*web_gui.py*' -and $_.Name -like 'python*'} | ForEach-Object {Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue}" >nul 2>&1 powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='SilentlyContinue'; $root=(Resolve-Path '.').Path; Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {($_.Name -like 'python*') -and ($_.CommandLine -like ('*' + $root + '*')) -and (($_.CommandLine -like '*web_gui.py*') -or ($_.CommandLine -like '*web_gui_entry.py*'))} | ForEach-Object {Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue}" >nul 2>&1
timeout /t 2 /nobreak >nul powershell -NoProfile -Command "Start-Sleep -Seconds 2" >nul 2>&1
echo [3/6] Stopping old processes... OK echo [3/6] Stopping old processes... OK
echo. echo.
REM [4/6] Port configuration REM [4/6] Port configuration
set "WEB_PORT=8000" set "WEB_PORT="
if defined PORT set "WEB_PORT=!PORT!" for /f "usebackq delims=" %%p in (`python -c "from douyin.core.path_config import get_web_gui_port; print(get_web_gui_port())" 2^>nul`) do set "WEB_PORT=%%p"
if defined WEB_GUI_PORT set "WEB_PORT=!WEB_GUI_PORT!" if not defined WEB_PORT set "WEB_PORT=8000"
echo [4/6] Port configuration: !WEB_PORT! echo [4/6] Port configuration: !WEB_PORT!
echo. echo.
@@ -104,30 +103,29 @@ if exist ".venv\Scripts\python.exe" (
) )
REM Start service (in new window, keep window open) REM Start service (in new window, keep window open)
set "SERVICE_LOG=%~dp0webgui_service.log"
if exist "!SERVICE_LOG!" del /f /q "!SERVICE_LOG!" >nul 2>&1
if !USE_VENV! equ 1 ( if !USE_VENV! equ 1 (
REM Use virtual environment python.exe directly (use full path) REM Use virtual environment python.exe directly (use full path)
set "PYTHON_CMD=!WORK_DIR!\.venv\Scripts\python.exe gui\web_gui.py" set "PYTHON_EXE=!WORK_DIR!\.venv\Scripts\python.exe"
) else if !USE_VENV! equ 2 (
REM Use activate.bat
set "PYTHON_CMD=call !WORK_DIR!\.venv\Scripts\activate.bat && python gui\web_gui.py"
) else ( ) else (
REM Use system Python REM Use system Python or activated Python through PATH
set "PYTHON_CMD=python gui\web_gui.py" set "PYTHON_EXE=python"
) )
REM Start command with proper quoting REM Start command with stable quoting and a service log
start "Douyin Web GUI" /D "!WORK_DIR!" cmd /k "cd /d !WORK_DIR! && echo Starting Web GUI service... && echo. && !PYTHON_CMD!" powershell -NoProfile -ExecutionPolicy Bypass -Command "$root = '%WORK_DIR%'; $py = '%PYTHON_EXE%'; $log = '%SERVICE_LOG%'; $cmd = 'cd /d \"' + $root + '\" && echo Starting Web GUI service... && echo. && \"' + $py + '\" gui\web_gui_entry.py >> \"' + $log + '\" 2>&1'; Start-Process -FilePath 'cmd.exe' -ArgumentList @('/k', $cmd) -WorkingDirectory $root -WindowStyle Normal"
REM Wait for service to start REM Wait for service to start
echo Starting service, please wait... echo Starting service, please wait...
set /a count=0 set /a count=0
:wait_loop :wait_loop
timeout /t 2 /nobreak >nul powershell -NoProfile -Command "Start-Sleep -Seconds 2" >nul 2>&1
set /a count+=1 set /a count+=1
REM Check if port is listening (use temporary variable to pass port number) REM Check if port is listening (use temporary variable to pass port number)
set "CHECK_PORT=!WEB_PORT!" set "CHECK_PORT=!WEB_PORT!"
powershell -NoProfile -Command "$listener = Get-NetTCPConnection -LocalPort %CHECK_PORT% -State Listen -ErrorAction SilentlyContinue; if ($listener) { exit 0 } else { exit 1 }" >nul 2>&1 powershell -NoProfile -Command "$listener = Get-NetTCPConnection -LocalPort !CHECK_PORT! -State Listen -ErrorAction SilentlyContinue; if ($listener) { exit 0 } else { exit 1 }" >nul 2>&1
if not errorlevel 1 ( if not errorlevel 1 (
echo [5/6] Web GUI service started echo [5/6] Web GUI service started
goto :open_browser goto :open_browser
@@ -147,7 +145,7 @@ goto :wait_loop
REM [6/6] Open browser REM [6/6] Open browser
echo. echo.
echo [6/6] Opening browser... echo [6/6] Opening browser...
timeout /t 1 /nobreak >nul powershell -NoProfile -Command "Start-Sleep -Seconds 1" >nul 2>&1
start "" "http://127.0.0.1:!WEB_PORT!" start "" "http://127.0.0.1:!WEB_PORT!"
echo. echo.
@@ -162,16 +160,9 @@ echo Notes:
echo - Web GUI service is running in a new window, do not close that window echo - Web GUI service is running in a new window, do not close that window
echo - Closing this window will not stop the Web GUI service echo - Closing this window will not stop the Web GUI service
echo - To stop the service, close the "Douyin Web GUI" window echo - To stop the service, close the "Douyin Web GUI" window
echo - Or run "StopWebGUIService.bat" echo - Or run "scripts\停止WebGUI服务.bat"
echo. echo.
echo Service log: !SERVICE_LOG!
REM Ask if view log
set /p view_log="View startup log? (Y/N): "
if /i "!view_log!"=="Y" (
if exist "%LOG_FILE%" (
notepad "%LOG_FILE%"
)
)
:cleanup :cleanup
endlocal endlocal
+2 -2
View File
@@ -11,8 +11,8 @@ echo.
echo 正在查找Web GUI进程... echo 正在查找Web GUI进程...
REM 查找并停止web_gui.py进程 REM 查找并停止 web_gui.py / web_gui_entry.py 进程
powershell -NoProfile -Command "$ps = Get-CimInstance Win32_Process | Where-Object { ($_.CommandLine -like '*web_gui.py*') -and ($_.Name -like 'python*') }; if ($ps) { $ps | ForEach-Object { try { $pid = $_.ProcessId; Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue; Write-Host \"[已停止] PID=$pid\" } catch { Write-Host \"[停止失败] PID=$($_.ProcessId): $_\" } } } else { Write-Host \"[未找到] 没有运行中的Web GUI进程\" }" powershell -NoProfile -Command "$root=(Resolve-Path (Join-Path '%~dp0' '..')).Path; $ps = Get-CimInstance Win32_Process | Where-Object { ($_.Name -like 'python*') -and ($_.CommandLine -like ('*' + $root + '*')) -and (($_.CommandLine -like '*web_gui.py*') -or ($_.CommandLine -like '*web_gui_entry.py*')) }; if ($ps) { $ps | ForEach-Object { try { $targetPid = $_.ProcessId; Stop-Process -Id $targetPid -Force -ErrorAction SilentlyContinue; Write-Host \"[已停止] PID=$targetPid\" } catch { Write-Host \"[停止失败] PID=$($_.ProcessId): $_\" } } } else { Write-Host \"[未找到] 没有运行中的Web GUI进程\" }"
echo. echo.
echo 操作完成! echo 操作完成!