Complete missing Web GUI controls

This commit is contained in:
Your Name committed 2026-05-20 17:54:40 +08:00
1 parent 8368f1f3b7
commit 89128deb0f
3 files changed
+762 -100

No files matched your search

+225 -4
View File
@@ -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()