From 5e949902756b13a477f0b608a825b01f81cadc2c Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 5 Jan 2026 22:57:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=94=AE=E5=9B=9E=E9=80=80=E7=9A=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=80=89=E9=A1=B9=EF=BC=8C=E4=BC=98=E5=8C=96=E6=97=A0?= =?UTF-8?q?=E7=A6=8F=E8=A2=8B=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/core/douyin_flow_control.py | 45 ++++++++++++++++++++++++------ gui/gui_app.py | 32 +++++++++++++++++---- gui/gui_core.py | 7 +++++ run_cli.py | 20 +++++++++++++ 4 files changed, 90 insertions(+), 14 deletions(-) diff --git a/douyin/core/douyin_flow_control.py b/douyin/core/douyin_flow_control.py index 25b6b5d..a0f423d 100644 --- a/douyin/core/douyin_flow_control.py +++ b/douyin/core/douyin_flow_control.py @@ -182,16 +182,43 @@ def find_and_open_fudai_detail( ) except Exception: pass - try: - analyser.operation.click_back(analyser.device_id) - except Exception: + # 检查是否启用了返回键回退(优先 analyser 属性,回退到配置文件) + enabled = getattr(analyser, "enable_back_on_misses", None) + if enabled is None: try: - # 兜底:使用通用 click 返回坐标 - rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080) - ry = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400) - back_x = int(50 * rx / 1080) - back_y = int(50 * ry / 2400) - analyser.operation.click(analyser.device_id, back_x, back_y) + import json + + cfg_path = path_config.get_config_path() + if cfg_path and os.path.exists(cfg_path): + with open(cfg_path, "r", encoding="utf-8") as f: + cfg = json.load(f) + enabled = bool(cfg.get("enable_back_on_misses", True)) + else: + enabled = True + except Exception: + enabled = True + + if enabled: + try: + analyser.operation.click_back(analyser.device_id) + except Exception: + try: + # 兜底:使用通用 click 返回坐标 + rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080) + ry = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400) + back_x = int(50 * rx / 1080) + back_y = int(50 * ry / 2400) + analyser.operation.click(analyser.device_id, back_x, back_y) + except Exception: + pass + else: + try: + analyser._log_kv( + "流程", + "返回键回退已禁用,跳过按返回键", + consecutive_no_fudai=cur, + threshold=threshold, + ) except Exception: pass # 重置计数,避免重复触发 diff --git a/gui/gui_app.py b/gui/gui_app.py index 0d4cfdd..0e2b2a6 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -320,11 +320,14 @@ def main(): fudai_exit_after_misses_var = tk.IntVar( value=int(cfg.get("fudai_exit_after_misses", 30) or 30) ) - # 连续无福袋退出阈值(在直播间连续未找到福袋达到该次数时按返回键退出) - ttk.Label(top, text="连续无福袋退出阈值:").pack(side=LEFT) - ttk.Spinbox( - top, from_=1, to=99999, textvariable=fudai_exit_after_misses_var, width=6 - ).pack(side=LEFT, padx=(0, 12)) + # 连续无福袋退出阈值变量(提前声明,避免后续使用前未绑定) + fudai_exit_after_misses_var = tk.IntVar( + value=int(cfg.get("fudai_exit_after_misses", 30) or 30) + ) + # 启用返回键回退开关变量(提前声明) + enable_back_on_misses_var = tk.BooleanVar( + value=bool(cfg.get("enable_back_on_misses", True)) + ) # 中部:左侧配置(使用Notebook标签页)+ 右侧日志/预览(支持拖拽调整宽度) mid = ttk.PanedWindow(root, orient="horizontal") @@ -708,6 +711,19 @@ def main(): ).pack(side=LEFT) ttk.Label(r2, text="(触发后会向上回退)").pack(side=LEFT, padx=(6, 0)) + # r3: 连续无福袋退出阈值 + 启用返回键回退 + r3 = ttk.Frame(run_box) + r3.pack(fill=X, padx=10, pady=(0, 10)) + ttk.Label(r3, text="连续无福袋退出阈值:").pack(side=LEFT) + ttk.Spinbox( + r3, from_=1, to=99999, textvariable=fudai_exit_after_misses_var, width=6 + ).pack(side=LEFT, padx=(6, 12)) + ttk.Checkbutton( + r3, + text="启用返回键回退", + variable=enable_back_on_misses_var, + ).pack(side=LEFT) + # 标签页2:筛选设置 filter_tab = ttk.Frame(left_notebook) left_notebook.add(filter_tab, text="筛选设置") @@ -1624,6 +1640,10 @@ def main(): ) except Exception: fudai_exit_after_misses_var.set(30) + try: + enable_back_on_misses_var.set(bool(cfg.get("enable_back_on_misses", True))) + except Exception: + enable_back_on_misses_var.set(True) switch_room_wait_after_stage_diag_seconds_var.set( float(cfg.get("switch_room_wait_after_stage_diag_seconds", 7.0) or 7.0) ) @@ -1841,6 +1861,7 @@ def main(): fudai_click_wait_seconds_var.get() or 2.0 ) cfg2["fudai_exit_after_misses"] = int(fudai_exit_after_misses_var.get() or 30) + cfg2["enable_back_on_misses"] = bool(enable_back_on_misses_var.get()) cfg2["fudai_disable_content_recognition"] = bool( fudai_disable_content_recognition_var.get() ) @@ -2997,6 +3018,7 @@ def main(): # 只养号模式与养号时长 yanghao_only=bool(yg_only_var.get()), yanghao_seconds=int(yg_recommend_duration_var.get() or 0), + enable_back_on_misses=bool(enable_back_on_misses_var.get()), ) def start_run(): diff --git a/gui/gui_core.py b/gui/gui_core.py index f84ef8f..9dbb5e0 100644 --- a/gui/gui_core.py +++ b/gui/gui_core.py @@ -95,6 +95,7 @@ class RunParams: skip_if_countdown_gt_seconds: int reset_after_swipes_enabled: bool reset_after_swipes: int + enable_back_on_misses: bool min_prize_value_yuan: float min_participants: int max_participants: int @@ -979,6 +980,12 @@ class Runner: ["--fudai-template-threshold", str(params.fudai_template_match_threshold)] ) + # 启用/禁用 达到连续未找到福袋阈值时按返回键回退 + if getattr(params, "enable_back_on_misses", True): + cmd.append("--enable-back-on-misses") + else: + cmd.append("--disable-back-on-misses") + # 只养号模式:如果启用则传递到 run_cli.py try: if getattr(params, "yanghao_only", False): diff --git a/run_cli.py b/run_cli.py index a5db8e1..d77b292 100644 --- a/run_cli.py +++ b/run_cli.py @@ -289,6 +289,17 @@ def parse_args(argv: list[str]) -> argparse.Namespace: help="禁用福袋模板匹配(默认已禁用)", ) + p.add_argument( + "--enable-back-on-misses", + action="store_true", + help="启用:达到连续未找到福袋阈值时按返回键回退(GUI 优先配置)", + ) + p.add_argument( + "--disable-back-on-misses", + action="store_true", + help="禁用:达到连续未找到福袋阈值时按返回键回退", + ) + p.add_argument( "--yanghao-only", action="store_true", @@ -410,6 +421,15 @@ def main(argv: list[str]) -> int: setattr(analyser, "yanghao_use_recommend_flow", True) # 加载配置(包括养号相关配置) analyser.load_config() + + # CLI 覆盖:启用/禁用 达到连续未找到福袋阈值时按返回键回退 + try: + if getattr(args, "enable_back_on_misses", False): + setattr(analyser, "enable_back_on_misses", True) + elif getattr(args, "disable_back_on_misses", False): + setattr(analyser, "enable_back_on_misses", False) + except Exception: + pass print( "[TEST] device_id={} res={}x{}".format( device_id, analyser.resolution_ratio_x, analyser.resolution_ratio_y