From 89128deb0fe067218375aee78d2efc12024cb0cf Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 20 May 2026 17:54:40 +0800 Subject: [PATCH] Complete missing Web GUI controls --- gui/web_gui.py | 229 +++++++++++++++++++++++- webui/app.js | 178 +++++++++++++++++- webui/index.html | 455 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 762 insertions(+), 100 deletions(-) diff --git a/gui/web_gui.py b/gui/web_gui.py index e89350b..8bac9ef 100644 --- a/gui/web_gui.py +++ b/gui/web_gui.py @@ -78,6 +78,19 @@ def read_config() -> dict: return json.load(f) +def get_nested_value(obj: dict, key: str, default=None): + """读取支持点号路径的配置值,如 logging.keep_days。""" + try: + cur = obj + for part in str(key).split("."): + if not isinstance(cur, dict) or part not in cur: + return default + cur = cur[part] + return cur + except Exception: + return default + + def write_config(cfg: dict) -> None: # Web 表单通常只生成“已知字段”的子集;直接覆盖写会丢失其它键(例如 ROI rect/poly 等扩展配置)。 # 这里做一次 merge:保留原配置中的未知键,再用新 cfg 覆盖同名键。 @@ -974,6 +987,60 @@ class ProcRunner: } return {"updated_ts": 0.0, "reason": "no_state_file", "total": 0, "rooms": []} + def send_back_key(self, device_id: str) -> bool: + try: + adb = find_adb_executable() + if not adb: + self._append_log("[错误] 未找到 adb.exe") + return False + if not device_id: + devices = list_adb_devices(adb) + if not devices: + self._append_log("[错误] 未找到可用设备") + return False + device_id = devices[0] + proc = subprocess.run( + [adb, "-s", device_id, "shell", "input", "keyevent", "4"], + capture_output=True, + text=True, + encoding="utf-8", + errors="replace", + timeout=5, + check=False, + ) + if proc.returncode == 0: + self._append_log(f"[手动操作] 已发送返回键到设备: {device_id}") + return True + self._append_log(f"[错误] 发送返回键失败: {(proc.stderr or proc.stdout or '').strip()}") + return False + except Exception as e: + self._append_log(f"[错误] 发送返回键异常: {e}") + return False + + def force_stop(self) -> None: + with self._lock: + pid = self._pid + p = self._proc + self._append_log(f"[停止] 强制停止请求 pid={pid or '-'}") + try: + if p is not None and p.poll() is None: + p.kill() + except Exception: + pass + if pid: + try: + if os.name == "nt": + subprocess.run(["taskkill", "/PID", str(pid), "/T", "/F"], capture_output=True, text=True, check=False, timeout=10) + else: + subprocess.run(["kill", "-9", str(pid)], capture_output=True, text=True, check=False, timeout=10) + except Exception as e: + self._append_log(f"[停止] 系统强制结束失败: {e}") + with self._lock: + self._proc = None + self._pid = None + self._exit_code = self._exit_code if self._exit_code is not None else -9 + self._append_log("[停止] 强制停止完成") + def stop(self) -> None: with self._lock: p = self._proc @@ -1247,15 +1314,22 @@ class ProcRunner: and params.get(key) is not None ): return params.get(key) - if isinstance(cfg, dict) and key in cfg and cfg.get(key) is not None: - return cfg.get(key) + if isinstance(cfg, dict): + val = get_nested_value(cfg, key, None) if "." in key else cfg.get(key) + if val is not None: + return val return default device_id = str(_pick("device_id", "") or "").strip() y_pianyi = int(_pick("y_pianyi", 0) or 0) needswitch = bool(_pick("needswitch", False)) reset_after_swipes_enabled = bool(_pick("reset_after_swipes_enabled", False)) - wait_minutes = int(_pick("wait_minutes", 5) or 5) + try: + wait_minutes = int(_pick("wait_minutes", 5)) + except Exception: + wait_minutes = 5 + if wait_minutes < 0: + wait_minutes = 0 # 启动时自动截图 if device_id: @@ -1279,6 +1353,9 @@ class ProcRunner: skip_if_countdown_lt_seconds = int( _pick("skip_if_countdown_lt_seconds", 15) or 15 ) + skip_if_countdown_gt_seconds = int( + _pick("skip_if_countdown_gt_seconds", 900) or 900 + ) try: reset_after_swipes = int(_pick("reset_after_swipes", 10) or 10) except Exception: @@ -1308,6 +1385,8 @@ class ProcRunner: str(min_prize_value_yuan), "--skip-if-countdown-lt-seconds", str(skip_if_countdown_lt_seconds), + "--skip-if-countdown-gt-seconds", + str(skip_if_countdown_gt_seconds), ] if device_id: cmd += ["--device-id", device_id] @@ -1318,6 +1397,20 @@ class ProcRunner: cmd += ["--reset-after-swipes", str(reset_after_swipes)] else: cmd.append("--reset-after-swipes-disabled") + reset_action = str(_pick("reset_after_swipes_action", "swipe") or "swipe").strip().lower() + if reset_action in ("swipe", "back"): + cmd += ["--reset-after-swipes-action", reset_action] + try: + swipe_down_back_count = int(_pick("swipe_down_back_count", 0) or 0) + except Exception: + swipe_down_back_count = 0 + swipe_down_back_enabled = bool(_pick("swipe_down_back_enabled", False)) + if swipe_down_back_enabled: + cmd.append("--swipe-down-back-enabled") + if swipe_down_back_count > 0: + cmd += ["--swipe-down-back-count", str(swipe_down_back_count)] + else: + cmd.append("--swipe-down-back-disabled") if min_participants > 0: cmd += ["--min-participants", str(min_participants)] if max_participants > 0: @@ -1340,6 +1433,13 @@ class ProcRunner: cmd.append("--high-value-room-revisit-disabled") if high_value_room_revisit_only_current_run: cmd.append("--high-value-room-revisit-only-current-run") + try: + cmd += ["--high-value-room-revisit-min-interval-seconds", str(int(_pick("high_value_room_revisit_min_interval_seconds", 300) or 300))] + cmd += ["--high-value-room-revisit-max-per-run", str(int(_pick("high_value_room_revisit_max_per_run", 5) or 5))] + cmd += ["--high-value-room-revisit-min-prize-value", str(float(_pick("high_value_room_revisit_min_prize_value", 0.0) or 0.0))] + cmd += ["--high-value-room-revisit-max-age-days", str(int(_pick("high_value_room_revisit_max_age_days", 30) or 30))] + except Exception: + pass # 预约回退校验开关(由 Run 面板控制) reservation_back_verify_enabled = bool( @@ -1393,6 +1493,19 @@ class ProcRunner: except Exception: pass + if bool(_pick("enable_back_on_misses", True)): + cmd.append("--enable-back-on-misses") + else: + cmd.append("--disable-back-on-misses") + if bool(_pick("yanghao_only", False)): + cmd.append("--yanghao-only") + try: + seconds = int(_pick("yanghao_seconds", _pick("yanghao_recommend_duration_seconds", 60)) or 60) + if seconds > 0: + cmd += ["--yanghao-seconds", str(seconds)] + except Exception: + pass + self._start_process(cmd) def _start_process(self, cmd: list[str]) -> None: @@ -1821,6 +1934,17 @@ class Handler(BaseHTTPRequestHandler): "yanghao_after_dwell_swipe_distance_px", "yanghao_recommend_duration_seconds", "yanghao_recommend_interval_seconds", + "wait_minutes", + "y_pianyi", + "fudai_exit_after_misses", + "swipe_duration_ms", + "swipe_up_start_y", + "swipe_up_end_y", + "high_value_room_revisit_min_interval_seconds", + "high_value_room_revisit_max_per_run", + "high_value_room_revisit_max_age_days", + "logging.keep_days", + "logging.compress_after_days", } float_keys = { "min_prize_value_yuan", @@ -1837,6 +1961,22 @@ class Handler(BaseHTTPRequestHandler): "fudai_icon_max_wait_seconds", "reservation_back_swipe_delay", "high_value_fudai_threshold_yuan", + "fansclub_click_delay", + "fansclub_auto_join_wait_seconds", + "fansclub_manual_wait_seconds", + "fudai_click_wait_seconds", + "fudai_detail_template_threshold", + "coupon_template_match_threshold", + "attend_button_red_ratio_threshold", + "fansclub_join_red_ratio_threshold", + "shopping_redpacket_red_ratio_threshold", + "high_value_fudai_poll_before_seconds", + "high_value_room_revisit_min_prize_value", + "reservation_back_verify_wait_seconds", + "switch_room_wait_after_stage_diag_seconds", + "logging.max_total_size_gb", + "logging.monitor_warning_mb", + "logging.monitor_critical_mb", } bool_keys = { "auto_join_fansclub", @@ -1852,6 +1992,22 @@ class Handler(BaseHTTPRequestHandler): "high_value_room_revisit_enabled", "high_value_room_revisit_only_current_run", "reservation_back_verify_enabled", + "needswitch", + "infinite_loop_enabled", + "enable_back_on_misses", + "enable_streaming_screenshot", + "fudai_disable_task_recognition", + "yanghao_only", + "debug_captures.async_save", + "debug_captures.log_on_complete", + "logging.beautify_output", + "logging.color_output", + "logging.show_timestamps", + "logging.enable_monitor", + "logging.compress_logs", + "logging.stage_diag_verbose", + "logging.performance_tracking.enabled", + "logging.performance_tracking.track_function_calls", } list_str_keys = { "contains_want", @@ -1933,7 +2089,72 @@ class Handler(BaseHTTPRequestHandler): return self._send_json({"ok": False, "error": str(e)}, status=500) return self._send_json({"ok": True}) - # (已移除) /api/test-yanghao 与 /api/test-comment 接口已删除 + # Web 端补齐的手动动作与桌面 GUI 常用操作。 + + if u.path == "/api/force-stop": + RUNNER.force_stop() + return self._send_json({"ok": True, "message": "已执行强制停止"}) + + if u.path == "/api/back-key": + body = self._read_json() + device_id = str(body.get("device_id") or "").strip() + ok = RUNNER.send_back_key(device_id) + return self._send_json({"ok": bool(ok), "message": "返回键已发送" if ok else "发送返回键失败"}, status=200 if ok else 500) + + if u.path == "/api/wifi/enable": + body = self._read_json() + adb = find_adb_executable() + device_id = str(body.get("device_id") or "").strip() + if not device_id: + return self._send_json({"ok": False, "error": "missing device_id"}, status=400) + try: + from gui.gui_core import enable_wifi_adb + ok, msg = enable_wifi_adb(adb, device_id) + except Exception as e: + ok, msg = False, str(e) + return self._send_json({"ok": bool(ok), "message": msg}, status=200 if ok else 500) + + if u.path == "/api/wifi/connect": + body = self._read_json() + adb = find_adb_executable() + ip = str(body.get("ip") or "").strip() + port = str(body.get("port") or "5555").strip() or "5555" + if not ip: + return self._send_json({"ok": False, "error": "missing ip"}, status=400) + try: + from gui.gui_core import connect_wifi_adb + ok, msg = connect_wifi_adb(adb, ip, port) + except Exception as e: + ok, msg = False, str(e) + devices = list_adb_devices(adb) if adb else [] + return self._send_json({"ok": bool(ok), "message": msg, "devices": devices}, status=200 if ok else 500) + + if u.path == "/api/wifi/disconnect": + body = self._read_json() + adb = find_adb_executable() + ip = str(body.get("ip") or "").strip() + port = str(body.get("port") or "5555").strip() or "5555" + if not ip: + return self._send_json({"ok": False, "error": "missing ip"}, status=400) + try: + from gui.gui_core import disconnect_wifi_adb + ok, msg = disconnect_wifi_adb(adb, ip, port) + except Exception as e: + ok, msg = False, str(e) + devices = list_adb_devices(adb) if adb else [] + return self._send_json({"ok": bool(ok), "message": msg, "devices": devices}, status=200 if ok else 500) + + if u.path == "/api/test-yanghao": + if RUNNER.is_running(): + return self._send_json({"ok": False, "error": "running"}, status=409) + body = self._read_json() + cfg = read_config() + seconds = int(body.get("seconds") or cfg.get("yanghao_recommend_duration_seconds") or 60) + RUNNER.start_main_run({"device_id": str(body.get("device_id") or ""), "yanghao_only": True, "yanghao_seconds": seconds, "wait_minutes": 0}) + return self._send_json({"ok": True}) + + if u.path == "/api/test-comment": + return self._send_json({"ok": False, "error": "独立测试评论接口已移除,请用养号参数中的评论概率/文案后启动养号流程"}, status=410) if u.path == "/api/stop": RUNNER.stop() diff --git a/webui/app.js b/webui/app.js index 8cb2338..9eca3bc 100644 --- a/webui/app.js +++ b/webui/app.js @@ -74,6 +74,56 @@ const DEFAULTS = { fudai_quiet_hours_enabled: true, fudai_quiet_start_hour: 2, fudai_quiet_end_hour: 7, + + // 桌面 GUI 对齐补充 + infinite_loop_enabled: false, + skip_if_countdown_gt_seconds: 900, + reset_after_swipes_action: "swipe", + enable_back_on_misses: true, + enable_streaming_screenshot: true, + swipe_duration_ms: 600, + swipe_up_start_y: 1200, + swipe_up_end_y: 600, + switch_room_wait_after_stage_diag_seconds: 7.0, + fansclub_click_delay: 0.6, + fansclub_auto_join_wait_seconds: 5.0, + fansclub_manual_wait_seconds: 3.0, + high_value_fudai_poll_before_seconds: 10.0, + high_value_room_revisit_min_interval_seconds: 300, + high_value_room_revisit_max_per_run: 5, + high_value_room_revisit_min_prize_value: 0, + high_value_room_revisit_max_age_days: 30, + reservation_back_verify_wait_seconds: 5.0, + fudai_disable_task_recognition: false, + fudai_exit_after_misses: 30, + fudai_click_wait_seconds: 2.0, + fudai_detail_template_threshold: 0.7, + coupon_template_match_threshold: 0.75, + attend_button_red_ratio_threshold: 0.25, + fansclub_join_red_ratio_threshold: 0.25, + shopping_redpacket_red_ratio_threshold: 0.15, + yanghao_only: false, + yanghao_icon_match_threshold: 0.72, + "debug_captures.async_save": true, + "debug_captures.log_on_complete": false, + "logging.beautify_output": true, + "logging.color_output": true, + "logging.show_timestamps": true, + "logging.enable_monitor": true, + "logging.compress_logs": true, + "logging.keep_days": 30, + "logging.max_total_size_gb": 10.0, + "logging.compress_after_days": 7, + "logging.debug_detail_level": "normal", + "logging.error_detail_level": "full", + "logging.action_log_format": "concise", + "logging.log_format_mode": "simple", + "logging.monitor_warning_mb": 500, + "logging.monitor_critical_mb": 2000, + "logging.stage_diag_verbose": true, + "logging.performance_tracking.enabled": true, + "logging.performance_tracking.track_function_calls": true, + "gui.theme": "litera", }; function $(id) { return document.getElementById(id); } @@ -565,6 +615,40 @@ function getConfigBoundElements() { return Array.from(document.querySelectorAll("[data-key]")); } +function syncMirrorFields() { + const mirrors = Array.from(document.querySelectorAll("[data-mirror-key]")); + for (const mirror of mirrors) { + const key = mirror.dataset.mirrorKey; + const source = document.querySelector(`[data-key="${CSS.escape(key)}"]`); + if (!source) continue; + const copy = () => { + if (mirror.type === "checkbox") mirror.checked = !!source.checked; + else mirror.value = source.value; + }; + copy(); + source.addEventListener("input", copy); + source.addEventListener("change", copy); + mirror.addEventListener("input", () => { + if (source.type === "checkbox") source.checked = !!mirror.checked; + else source.value = mirror.value; + source.dispatchEvent(new Event("input", { bubbles: true })); + source.dispatchEvent(new Event("change", { bubbles: true })); + }); + } +} + +function getConfigValue(cfg, key) { + if (!cfg || !key) return undefined; + if (Object.prototype.hasOwnProperty.call(cfg, key)) return cfg[key]; + if (!String(key).includes(".")) return undefined; + let cur = cfg; + for (const part of String(key).split(".")) { + if (!cur || typeof cur !== "object" || !Object.prototype.hasOwnProperty.call(cur, part)) return undefined; + cur = cur[part]; + } + return cur; +} + function coerceValue(type, raw, isCheckbox) { if (type === "bool") return !!raw; if (type === "int") { @@ -587,7 +671,7 @@ function applyConfigToUI(cfg) { for (const el of getConfigBoundElements()) { const key = el.dataset.key; const type = el.dataset.type || "str"; - const val = cfg ? cfg[key] : undefined; + const val = getConfigValue(cfg, key); // undefined/null 都视为“未配置”:保留页面默认值 const hasVal = !(typeof val === "undefined" || val === null); @@ -638,13 +722,72 @@ async function saveConfig() { appendLog(["[WEB] 配置已保存到 config.json"]); } +function selectedDeviceId() { + const el = $("device"); + return el ? (el.value || "") : ""; +} + +async function postDeviceAction(path, body, successPrefix) { + try { + const result = await apiPost(path, body || {}); + const msg = result.message || result.output || result.error || "完成"; + appendLog([`${successPrefix}: ${msg}`]); + if (result.devices) await refreshDevices(); + return result; + } catch (e) { + appendLog([`${successPrefix}失败: ${e?.message || e}`]); + throw e; + } +} + +async function forceStopRun() { + await postDeviceAction("/api/force-stop", {}, "[WEB] 强制停止"); +} + +async function sendBackKey() { + const deviceId = selectedDeviceId(); + await postDeviceAction("/api/back-key", { device_id: deviceId }, "[WEB] 返回键"); +} + +async function wifiEnable() { + const deviceId = selectedDeviceId(); + if (!deviceId) { + appendLog(["[WiFi ADB] 请先选择 USB 设备"]); + return; + } + const result = await postDeviceAction("/api/wifi/enable", { device_id: deviceId }, "[WiFi ADB] 启用"); + setTextIfExists("wifiStatus", result.message || "已发送启用命令"); +} + +async function wifiConnect() { + const ip = ($("wifi_ip")?.value || "").trim(); + const port = ($("wifi_port")?.value || "5555").trim() || "5555"; + if (!ip) { + appendLog(["[WiFi ADB] 请填写设备 IP"]); + return; + } + const result = await postDeviceAction("/api/wifi/connect", { ip, port }, "[WiFi ADB] 连接"); + setTextIfExists("wifiStatus", result.message || "连接命令已执行"); +} + +async function wifiDisconnect() { + const ip = ($("wifi_ip")?.value || selectedDeviceId() || "").trim(); + const port = ($("wifi_port")?.value || "5555").trim() || "5555"; + if (!ip) { + appendLog(["[WiFi ADB] 请填写 IP 或选择 WiFi 设备"]); + return; + } + const result = await postDeviceAction("/api/wifi/disconnect", { ip, port }, "[WiFi ADB] 断开"); + setTextIfExists("wifiStatus", result.message || "断开命令已执行"); +} + async function startRun() { try { const deviceId = $("device").value || ""; const yPianyi = parseInt($("y_pianyi").value || "0", 10); - const waitMinutes = parseInt($("wait_minutes").value || "5", 10); - const needswitch = $("needswitch").checked; const cfgPart = collectConfigFromUI(); + const waitMinutes = cfgPart.infinite_loop_enabled ? 0 : parseInt($("wait_minutes").value || "5", 10); + const needswitch = $("needswitch").checked; appendLog([`[WEB] 正在启动...`]); @@ -661,11 +804,26 @@ async function startRun() { reset_after_swipes: cfgPart.reset_after_swipes, auto_join_fansclub: cfgPart.auto_join_fansclub, fansclub_fail_action: cfgPart.fansclub_fail_action, + skip_if_countdown_gt_seconds: cfgPart.skip_if_countdown_gt_seconds, + reset_after_swipes_action: cfgPart.reset_after_swipes_action, + enable_back_on_misses: cfgPart.enable_back_on_misses, + swipe_down_back_enabled: cfgPart.swipe_down_back_enabled, + swipe_down_back_count: cfgPart.swipe_down_back_count, high_value_room_revisit_enabled: cfgPart.high_value_room_revisit_enabled, high_value_room_revisit_only_current_run: cfgPart.high_value_room_revisit_only_current_run, + high_value_room_revisit_min_interval_seconds: cfgPart.high_value_room_revisit_min_interval_seconds, + high_value_room_revisit_max_per_run: cfgPart.high_value_room_revisit_max_per_run, + high_value_room_revisit_min_prize_value: cfgPart.high_value_room_revisit_min_prize_value, + high_value_room_revisit_max_age_days: cfgPart.high_value_room_revisit_max_age_days, reservation_back_verify_enabled: cfgPart.reservation_back_verify_enabled, reservation_back_swipe_delay: cfgPart.reservation_back_swipe_delay, + reservation_back_verify_wait_seconds: cfgPart.reservation_back_verify_wait_seconds, fudai_find_max_attempts: cfgPart.fudai_find_max_attempts, + enable_ocr_mode1: cfgPart.enable_ocr_mode1, + fudai_template_match_enabled: cfgPart.fudai_template_match_enabled, + fudai_template_match_threshold: cfgPart.fudai_template_match_threshold, + yanghao_only: cfgPart.yanghao_only, + yanghao_seconds: cfgPart.yanghao_recommend_duration_seconds, }); // 检查返回结果 @@ -1168,6 +1326,16 @@ window.addEventListener("DOMContentLoaded", async () => { $("btnSave").addEventListener("click", async () => { await saveConfig(); }); $("btnStart").addEventListener("click", async () => { await startRun(); }); $("btnStop").addEventListener("click", async () => { await stopRun(); }); + const btnForceStop = $("btnForceStop"); + if (btnForceStop) btnForceStop.addEventListener("click", async () => { await forceStopRun(); }); + const btnBackKey = $("btnBackKey"); + if (btnBackKey) btnBackKey.addEventListener("click", async () => { await sendBackKey(); }); + const btnWifiEnable = $("btnWifiEnable"); + if (btnWifiEnable) btnWifiEnable.addEventListener("click", async () => { await wifiEnable(); }); + const btnWifiConnect = $("btnWifiConnect"); + if (btnWifiConnect) btnWifiConnect.addEventListener("click", async () => { await wifiConnect(); }); + const btnWifiDisconnect = $("btnWifiDisconnect"); + if (btnWifiDisconnect) btnWifiDisconnect.addEventListener("click", async () => { await wifiDisconnect(); }); // 截图按钮 $("btnScreenshot").addEventListener("click", async () => { @@ -1231,6 +1399,8 @@ window.addEventListener("DOMContentLoaded", async () => { if (runSearchBtn) runSearchBtn.addEventListener('click', async () => { await doRunLogSearch(); }); if (runClear) runClear.addEventListener('click', () => { runLogBuffer = []; runSearchResultsBuffer = []; runSearchActive = false; runLogFilter = ''; if (runSearchEl) runSearchEl.value=''; renderRunLog(); }); + syncMirrorFields(); + const actionsSearchEl = $("actionsLogSearch"); if (actionsSearchEl) { actionsSearchEl.addEventListener('input', (e) => { actionsLogFilter = String(e.target.value || ''); renderActionsLog(); }); @@ -1252,4 +1422,4 @@ window.addEventListener("DOMContentLoaded", async () => { pollShot(); pollReservations(); pollHighValueRooms(); -}); \ No newline at end of file +}); diff --git a/webui/index.html b/webui/index.html index 4c7f667..aabbc0b 100644 --- a/webui/index.html +++ b/webui/index.html @@ -10,7 +10,7 @@
-
抖音挂机控制�?/div> +
抖音挂机控制台
配置与运行(纯坐标点击)
@@ -18,7 +18,8 @@ - 开始运�? + 开始运行 + + +
@@ -73,7 +86,7 @@
+
WiFi ADB
+
+
+ + +
+
+ + +
+
+
+ + + +
+
先用 USB 设备启用 TCP/IP,再按 IP 连接。
-
- +
- + -
识别到福袋一�?4�? 秒,可按设备/网络情况微调
+
识别到福袋一般 4-8 秒,可按设备/网络情况微调
-
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +