Update config, web GUI, and add debug features

This commit is contained in:
Your Name committed 2026-05-20 08:12:06 +08:00
1 parent 4492b77d67
commit 7eb72bd00e
6 files changed
+140 -9

No files matched your search

+1 -1
View File
@@ -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,
+5
View File
@@ -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
+14 -5
View File
@@ -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
+41
View File
@@ -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()
+11 -3
View File
@@ -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() {
+68
View File
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<title>Debug WebGUI</title>
</head>
<body>
<h1>Debug WebGUI Config Loading</h1>
<div id="output"></div>
<script>
const output = document.getElementById('output');
async function apiGet(path) {
const res = await fetch(path, { cache: "no-store" });
if (!res.ok) throw new Error(await res.text());
return await res.json();
}
function getConfigBoundElements() {
return Array.from(document.querySelectorAll("[data-key]"));
}
async function testConfig() {
try {
output.innerHTML += '<p>Testing API...</p>';
const cfg = await apiGet("/api/config");
output.innerHTML += `<p>Config loaded: ${Object.keys(cfg).length} keys</p>`;
// Test getConfigBoundElements
const elements = getConfigBoundElements();
output.innerHTML += `<p>Found ${elements.length} config-bound elements</p>`;
if (elements.length > 0) {
output.innerHTML += '<p>Sample elements:</p><ul>';
for (let i = 0; i < Math.min(5, elements.length); i++) {
const el = elements[i];
output.innerHTML += `<li>${el.id || el.name || 'unnamed'}: data-key="${el.dataset.key}"</li>`;
}
output.innerHTML += '</ul>';
}
// Test DEFAULTS
const DEFAULTS = {
min_prize_value_yuan: 0,
min_participants: 0,
skip_if_countdown_lt_seconds: 15,
};
output.innerHTML += '<p>Testing applyConfigToUI logic...</p>';
for (const key of Object.keys(DEFAULTS)) {
const val = cfg ? cfg[key] : undefined;
const hasVal = !(typeof val === "undefined" || val === null);
const useVal = hasVal ? val : (Object.prototype.hasOwnProperty.call(DEFAULTS, key) ? DEFAULTS[key] : undefined);
output.innerHTML += `<p>${key}: config=${val}, hasVal=${hasVal}, useVal=${useVal}</p>`;
}
} catch (e) {
output.innerHTML += `<p>Error: ${e.message}</p>`;
console.error(e);
}
}
testConfig();
</script>
</body>
</html>