From bffca95af01cccb1236dea1c02824bb160177ed0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 3 Jan 2026 19:54:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E5=80=92?= =?UTF-8?q?=E8=AE=A1=E6=97=B6=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=E6=97=B6=E9=97=B4=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=EF=BC=8C=E8=B0=83=E6=95=B4=E7=9B=B8=E5=85=B3=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.json | 2 +- douyin/core/douyin_fudai.py | 22 +++-- douyin/core/state/reservations.json | 29 ++---- douyin/fudai/core/fudai_attend.py | 7 +- douyin/fudai/douyin_fudai_core.py | 7 +- .../reservation/douyin_reservation_handler.py | 2 +- gui/gui_app.py | 93 +++++++++++++++++-- 7 files changed, 115 insertions(+), 47 deletions(-) diff --git a/config/config.json b/config/config.json index aa39320..8034e14 100644 --- a/config/config.json +++ b/config/config.json @@ -1,5 +1,5 @@ { - "needswitch": true, + "needswitch": false, "infinite_loop_enabled": true, "wait_minutes": 5, "min_prize_value_yuan": 200.0, diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 8e10693..80bb561 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -733,7 +733,11 @@ class fudai_analyse: # 检测到结果,清等待并处理 self._waiting_for_lottery_result = False try: - self._log_kv("参与", "等待期间检测到开奖结果,开始处理", attempt=attempt) + self._log_kv( + "参与", + "等待期间检测到开奖结果,开始处理", + attempt=attempt, + ) except Exception: pass self._handle_lottery_result_by_ocr(result) @@ -2079,10 +2083,17 @@ class fudai_analyse: try: # 从保存的 tuple 中安全读取倒计时信息,使用 cast 明确类型以帮助静态分析 detail = getattr(self, "_last_fudai_detail_tuple", None) - if detail is not None and isinstance(detail, tuple) and len(detail) >= 6: + if ( + detail is not None + and isinstance(detail, tuple) + and len(detail) >= 6 + ): # 使用解包避免索引告警 _, _, _, _, _, countdown_tuple = detail - if isinstance(countdown_tuple, (tuple, list)) and len(countdown_tuple) >= 2: + if ( + isinstance(countdown_tuple, (tuple, list)) + and len(countdown_tuple) >= 2 + ): future_ts = float(countdown_tuple[1] or 0.0) if future_ts > 0: # 设置当前福袋的 future_ts,供 attend_choujiang 使用 @@ -2746,11 +2757,8 @@ class fudai_analyse: if remain_seconds > 0: # 设置等待开奖标志和预期开奖时间 # 直接保存开奖时间戳,等待时直接用 future_timestamp - time.time() 计算剩余秒数 - # 提前13秒,修正倒计时误差 self._waiting_for_lottery_result = True - self._lottery_result_expected_ts = ( - future_timestamp - 13.0 - ) # 提前13秒,修正倒计时误差 + self._lottery_result_expected_ts = future_timestamp self._log_kv( "参与", diff --git a/douyin/core/state/reservations.json b/douyin/core/state/reservations.json index ded9bb5..a163ed9 100644 --- a/douyin/core/state/reservations.json +++ b/douyin/core/state/reservations.json @@ -1,23 +1,8 @@ { - "updated_ts": 1767438731.9581015, - "reason": "record_reservation", - "room_pos": 6, - "current_room_title": "作业帮数", - "current_room_title_raw": "作业帮数", - "reservations": [ - { - "prize_value_yuan": 1999.0, - "content": "", - "future_ts": 1767439294.678569, - "future_str": "2026-01-03 19:21:34", - "pos_seen": 6, - "room_title": "作业帮数", - "room_title_raw": "作业帮数", - "created_ts": 1767438731.950231, - "task_count": 2, - "time_text": "09:28", - "participants": 0, - "copies": 0 - } - ] -} \ No newline at end of file + "updated_ts": 1767440958.0048747, + "reason": "startup_clear", + "room_pos": 0, + "current_room_title": "", + "current_room_title_raw": "", + "reservations": [] +} diff --git a/douyin/fudai/core/fudai_attend.py b/douyin/fudai/core/fudai_attend.py index 99570c5..42d15fa 100644 --- a/douyin/fudai/core/fudai_attend.py +++ b/douyin/fudai/core/fudai_attend.py @@ -133,9 +133,9 @@ def attend_choujiang(analyser) -> bool: current_time = time.time() remain_seconds = max(0, future_ts - current_time) if remain_seconds > 0: - # 设置等待开奖标志和预期开奖时间(提前13秒,修正倒计时误差) + # 设置等待开奖标志和预期开奖时间 analyser._waiting_for_lottery_result = True - analyser._lottery_result_expected_ts = future_ts - 13.0 + analyser._lottery_result_expected_ts = future_ts analyser._log_kv( "参与", "参与成功,设置等待开奖标志", @@ -278,9 +278,8 @@ def attend_choujiang(analyser) -> bool: remain_seconds = int(future_ts - current_time) if remain_seconds > 0: # 设置等待开奖标志和预期开奖时间 - # 提前13秒,修正倒计时误差 analyser._waiting_for_lottery_result = True - analyser._lottery_result_expected_ts = future_ts - 13.0 + analyser._lottery_result_expected_ts = future_ts # #region agent log - countdown set with open(get_debug_log_path(), "a", encoding="utf-8") as f: diff --git a/douyin/fudai/douyin_fudai_core.py b/douyin/fudai/douyin_fudai_core.py index b16283f..ef1ad90 100644 --- a/douyin/fudai/douyin_fudai_core.py +++ b/douyin/fudai/douyin_fudai_core.py @@ -2215,9 +2215,9 @@ def attend_choujiang(analyser) -> bool: current_time = time.time() remain_seconds = max(0, future_ts - current_time) if remain_seconds > 0: - # 设置等待开奖标志和预期开奖时间(提前13秒,修正倒计时误差) + # 设置等待开奖标志和预期开奖时间 analyser._waiting_for_lottery_result = True - analyser._lottery_result_expected_ts = future_ts - 13.0 + analyser._lottery_result_expected_ts = future_ts analyser._log_kv( "参与", "参与成功,设置等待开奖标志", @@ -2331,9 +2331,8 @@ def attend_choujiang(analyser) -> bool: remain_seconds = int(future_ts - current_time) if remain_seconds > 0: # 设置等待开奖标志和预期开奖时间 - # 提前13秒,修正倒计时误差 analyser._waiting_for_lottery_result = True - analyser._lottery_result_expected_ts = future_ts - 13.0 + analyser._lottery_result_expected_ts = future_ts analyser._log_kv( "参与", "点击参与抽奖后,设置等待开奖标志", diff --git a/douyin/reservation/douyin_reservation_handler.py b/douyin/reservation/douyin_reservation_handler.py index 577d6f4..3ea4064 100644 --- a/douyin/reservation/douyin_reservation_handler.py +++ b/douyin/reservation/douyin_reservation_handler.py @@ -725,7 +725,7 @@ class ReservationHandler: remain_seconds = max(0, future_ts - current_time) if remain_seconds > 0: analyser._waiting_for_lottery_result = True - analyser._lottery_result_expected_ts = future_ts - 13.0 + analyser._lottery_result_expected_ts = future_ts analyser._log_kv( # type: ignore[attr-defined] "预约", "[预约] 预约回退后参与成功,设置开奖等待状态", diff --git a/gui/gui_app.py b/gui/gui_app.py index b0d831f..657f240 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -2206,6 +2206,23 @@ def main(): # 右侧:Notebook(日志 / 截图预览 / 统计信息 / 预约队列 / 高价值房间) notebook = ttk.Notebook(right) + # 实时状态工具栏(固定在 Notebook 上方,始终可见) + show_actions_var = tk.BooleanVar(value=True) + show_screenshot_var = tk.BooleanVar(value=False) + auto_scroll_var = tk.BooleanVar(value=True) + + realtime_tools = ttk.Frame(right) + realtime_tools.pack(fill=X, padx=8, pady=(4, 0)) + ttk.Checkbutton( + realtime_tools, text="显示动作流", variable=show_actions_var + ).pack(side=LEFT, padx=(0, 8)) + ttk.Checkbutton( + realtime_tools, text="显示截图", variable=show_screenshot_var + ).pack(side=LEFT, padx=(0, 8)) + ttk.Checkbutton( + realtime_tools, text="自动滚动", variable=auto_scroll_var + ).pack(side=LEFT, padx=(0, 8)) + log_tab = ttk.Frame(notebook) preview_tab = ttk.Frame(notebook) stats_tab = ttk.Frame(notebook) @@ -2234,7 +2251,13 @@ def main(): realtime_frame = ttk.Frame(realtime_tab) realtime_frame.pack(fill=BOTH, expand=True, padx=8, pady=8) - realtime_text = ScrolledText(realtime_frame, height=20) + + + # 截图预览区域(根据选项显示/隐藏) + image_label = ttk.Label(realtime_frame) + image_label.pack(fill=X) + + realtime_text = ScrolledText(realtime_frame, height=14) realtime_text.pack(fill=BOTH, expand=True) realtime_text.configure(state="disabled") @@ -2309,14 +2332,68 @@ def main(): parsed = list(reversed(parsed)) - realtime_text.configure(state="normal") - realtime_text.delete("1.0", "end") - if not parsed: - realtime_text.insert("1.0", "暂无动作日志(仅显示包含“耗时”的行)") + # 更新截图(若选中) + if show_screenshot_var.get(): + try: + try: + from path_config import get_screenshot_path + + screenshot_path = get_screenshot_path() + except Exception: + import path_config + + screenshot_path = path_config.get_screenshot_path() + + if os.path.exists(screenshot_path): + img = Image.open(screenshot_path) + # 缩放以适应宽度(保持纵横比),最大宽度 420 + max_w = 420 + w, h = img.size + if w > max_w: + nw = max_w + nh = int(h * (nw / w)) + img = img.resize((nw, nh), Image.LANCZOS) + tk_img = ImageTk.PhotoImage(img) + image_label.configure(image=tk_img) + image_label.image = tk_img + image_label.pack(fill=X) + else: + image_label.configure(image="") + image_label.image = None + image_label.pack_forget() + except Exception: + image_label.configure(image="") + image_label.image = None + image_label.pack_forget() else: - for action, dur in parsed: - realtime_text.insert("end", f"{action} {dur}\n") - realtime_text.configure(state="disabled") + image_label.configure(image="") + image_label.image = None + image_label.pack_forget() + + # 更新动作流文本(若选中) + if show_actions_var.get(): + realtime_text.configure(state="normal") + realtime_text.delete("1.0", "end") + if not parsed: + realtime_text.insert("1.0", "暂无动作日志(仅显示包含“耗时”的行)") + else: + for action, dur in parsed: + realtime_text.insert("end", f"{action} {dur}\n") + # 自动滚动 + if auto_scroll_var.get(): + try: + realtime_text.see("end") + except Exception: + try: + realtime_text.yview_moveto(1.0) + except Exception: + pass + realtime_text.configure(state="disabled") + else: + # 隐藏文本内容但保留控件 + realtime_text.configure(state="normal") + realtime_text.delete("1.0", "end") + realtime_text.configure(state="disabled") # 安排下一次刷新 try: