From 7eb72bd00e55296b9dcca8172e3b524b2030d7f4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 20 May 2026 08:12:06 +0800 Subject: [PATCH] Update config, web GUI, and add debug features --- config/config.json | 2 +- gui/web_gui.py | 5 +++ scripts/一键启动WebGUI.bat | 19 ++++++++--- test_webgui.py | 41 +++++++++++++++++++++++ webui/app.js | 14 ++++++-- webui/debug.html | 68 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 test_webgui.py create mode 100644 webui/debug.html diff --git a/config/config.json b/config/config.json index 7a19778..34f2fc9 100644 --- a/config/config.json +++ b/config/config.json @@ -70,7 +70,7 @@ "fudai_quiet_hours_enabled": true, "fudai_quiet_start_hour": 2, "fudai_quiet_end_hour": 9, - "yanghao_enabled": true, + "yanghao_enabled": false, "yanghao_enable_actions": true, "yanghao_like_icon_x": 988, "yanghao_like_icon_y": 1218, diff --git a/gui/web_gui.py b/gui/web_gui.py index 4001795..e89350b 100644 --- a/gui/web_gui.py +++ b/gui/web_gui.py @@ -11,6 +11,11 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from typing import Optional from urllib.parse import parse_qs, urlparse +# Add project root to Python path +project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if project_root not in sys.path: + sys.path.insert(0, project_root) + import path_config BASE_DIR = path_config.PROJECT_ROOT diff --git a/scripts/一键启动WebGUI.bat b/scripts/一键启动WebGUI.bat index 5d5c0b6..89baae7 100644 --- a/scripts/一键启动WebGUI.bat +++ b/scripts/一键启动WebGUI.bat @@ -17,8 +17,16 @@ if errorlevel 1 ( goto :cleanup ) +REM Change to project root directory (parent of scripts) +cd /d "%~dp0.." +if errorlevel 1 ( + echo [ERROR] Cannot change to project root directory + pause + goto :cleanup +) + REM Save current directory to variable (for delayed expansion) -set "WORK_DIR=%~dp0" +set "WORK_DIR=%~dp0.." set "WORK_DIR=!WORK_DIR:~0,-1!" REM Create log file @@ -50,9 +58,10 @@ echo. REM [2/6] Check required files echo [2/6] Checking required files... -if not exist "web_gui.py" ( +if not exist "gui\web_gui.py" ( echo [ERROR] web_gui.py not found echo Current directory: !WORK_DIR! + echo Expected path: !WORK_DIR!\gui\web_gui.py echo [ERROR] web_gui.py does not exist >> "%LOG_FILE%" pause goto :cleanup @@ -105,13 +114,13 @@ if exist ".venv\Scripts\python.exe" ( REM Start service (in new window, keep window open) if !USE_VENV! equ 1 ( REM Use virtual environment python.exe directly (use full path) - set "PYTHON_CMD=!WORK_DIR!\.venv\Scripts\python.exe web_gui.py" + set "PYTHON_CMD=!WORK_DIR!\.venv\Scripts\python.exe gui\web_gui.py" ) else if !USE_VENV! equ 2 ( REM Use activate.bat - set "PYTHON_CMD=call !WORK_DIR!\.venv\Scripts\activate.bat && python web_gui.py" + set "PYTHON_CMD=call !WORK_DIR!\.venv\Scripts\activate.bat && python gui\web_gui.py" ) else ( REM Use system Python - set "PYTHON_CMD=python web_gui.py" + set "PYTHON_CMD=python gui\web_gui.py" ) REM Start command with proper quoting diff --git a/test_webgui.py b/test_webgui.py new file mode 100644 index 0000000..d8b4544 --- /dev/null +++ b/test_webgui.py @@ -0,0 +1,41 @@ +import sys +import os +import time +import subprocess +import threading + +# Add project root to path +project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if project_root not in sys.path: + sys.path.insert(0, project_root) + +import gui.web_gui as wg + +def test_server(): + # Start server in background thread + def run_server(): + try: + wg.main() + except SystemExit: + pass + + server_thread = threading.Thread(target=run_server, daemon=True) + server_thread.start() + + # Wait for server to start + time.sleep(2) + + # Test API + try: + import requests + response = requests.get('http://localhost:8001/api/config', timeout=5) + print(f"Status: {response.status_code}") + print(f"Response length: {len(response.text)}") + data = response.json() + print(f"Config keys: {len(data)}") + print(f"Sample keys: {list(data.keys())[:5]}") + except Exception as e: + print(f"Error: {e}") + +if __name__ == "__main__": + test_server() \ No newline at end of file diff --git a/webui/app.js b/webui/app.js index 2f11ec6..8d66fd4 100644 --- a/webui/app.js +++ b/webui/app.js @@ -623,9 +623,17 @@ function collectConfigFromUI() { } async function loadConfig() { - const cfg = await apiGet("/api/config"); - applyConfigToUI(cfg); - appendLog(["[WEB] 配置已加载"]); + console.log('[DEBUG] loadConfig called'); + try { + const cfg = await apiGet("/api/config"); + console.log('[DEBUG] Config loaded:', Object.keys(cfg).length, 'keys'); + applyConfigToUI(cfg); + console.log('[DEBUG] Config applied to UI'); + appendLog(["[WEB] 配置已加载"]); + } catch (e) { + console.error('[DEBUG] loadConfig error:', e); + appendLog(["[WEB] 配置加载失败: " + e.message]); + } } async function saveConfig() { diff --git a/webui/debug.html b/webui/debug.html new file mode 100644 index 0000000..88fcd98 --- /dev/null +++ b/webui/debug.html @@ -0,0 +1,68 @@ + + + + Debug WebGUI + + +

Debug WebGUI Config Loading

+
+ + + + \ No newline at end of file