feat: 优化实时查看功能的实现,确保函数调用安全性

This commit is contained in:
Your Name committed 2026-01-04 10:12:28 +08:00
1 parent 161e2e9491
commit b215e79a26
2 files changed
+42 -34

No files matched your search

+32 -26
View File
@@ -1354,10 +1354,17 @@ class fudai_analyse:
import json
if os.path.exists(state_path):
with open(state_path, "r", encoding="utf-8") as f:
with open(
state_path, "r", encoding="utf-8"
) as f:
data = json.load(f)
if isinstance(data, dict) and "reservations" in data:
loaded = data.get("reservations", [])
if (
isinstance(data, dict)
and "reservations" in data
):
loaded = data.get(
"reservations", []
)
elif isinstance(data, list):
loaded = data
else:
@@ -1837,22 +1844,23 @@ class fudai_analyse:
len(self.reservations) if self.reservations else 0
),
)
except Exception:
pass
# use module-level `douyin_reservation_logic`
douyin_reservation_logic.cleanup_expired_reservations(
self, self.reservations, _write_state
)
except Exception as exc:
try:
self._log_kv(
"预约",
"[预约] 单间模式下清理过期预约时出错",
error=str(exc),
douyin_reservation_logic.cleanup_expired_reservations(
self, self.reservations, _write_state
)
except Exception:
pass
except Exception as exc:
try:
self._log_kv(
"预约",
"[预约] 单间模式下清理过期预约时出错",
error=str(exc),
)
except Exception:
pass
except Exception:
pass
except Exception:
pass
@@ -2488,10 +2496,13 @@ class fudai_analyse:
and isinstance(detail, tuple)
and len(detail) >= 6
):
# 使用索引读取并使用 try/except 以避免静态分析对解包/下标的误报
try:
countdown_tuple = detail[5]
except Exception:
# 确认 detail 为序列后再索引,避免静态分析误报
if isinstance(detail, (list, tuple)):
try:
countdown_tuple = detail[5]
except Exception:
countdown_tuple = ()
else:
countdown_tuple = ()
if (
isinstance(countdown_tuple, (tuple, list))
@@ -3183,10 +3194,7 @@ class fudai_analyse:
# 从预约队列中移除已完成的预约(匹配 future_ts,允许5秒误差)
if hasattr(self, "reservations") and self.reservations:
from douyin.reservation import (
douyin_reservation_logic,
) # pylint: disable=redefined-outer-name
# use module-level `douyin_reservation_logic`
reservations_to_remove = []
for idx, r in enumerate(self.reservations):
try:
@@ -3310,9 +3318,7 @@ class fudai_analyse:
# 检查是否在锁定期内,且时间窗口未到,避免重复打开福袋详情
try:
import time as time_module
now_ts = time_module.time()
now_ts = time.time()
focus_until = float(getattr(self, "reservation_focus_until_ts", 0.0) or 0.0)
queue_full_waiting = bool(
getattr(self, "queue_full_waiting_at_earliest", False) or False
+10 -8
View File
@@ -2231,13 +2231,13 @@ def main():
side=LEFT, padx=(0, 8)
)
# forward-declare handler to satisfy linters; real function defined later
open_realtime_viewer_func = lambda: None
_open_realtime_viewer_impl = None
ttk.Button(
realtime_tools,
text="实时查看",
width=10,
command=lambda: open_realtime_viewer_func(),
command=lambda: _open_realtime_viewer_impl() if callable(_open_realtime_viewer_impl) else None,
).pack(side=LEFT, padx=(8, 0))
log_tab = ttk.Frame(notebook)
@@ -2425,12 +2425,12 @@ def main():
pass
# --------- 实时查看弹窗(紧凑视图) ---------
def open_realtime_viewer_func():
def _open_realtime_viewer_impl():
try:
# 如果已打开则直接聚焦
if hasattr(open_realtime_viewer_func, "_win") and open_realtime_viewer_func._win:
if hasattr(_open_realtime_viewer_impl, "_win") and _open_realtime_viewer_impl._win:
try:
open_realtime_viewer_func._win.lift()
_open_realtime_viewer_impl._win.lift()
except Exception:
pass
return
@@ -2438,7 +2438,7 @@ def main():
win = tk.Toplevel(root)
win.title("实时查看 - 截图与最简动作流")
win.geometry("520x520")
open_realtime_viewer_func._win = win
_open_realtime_viewer_impl._win = win
# 图片与列表
img_lbl = ttk.Label(win)
@@ -2462,7 +2462,7 @@ def main():
win.destroy()
except Exception:
pass
open_realtime_viewer_func._win = None
_open_realtime_viewer_impl._win = None
win.protocol("WM_DELETE_WINDOW", close_win)
@@ -4661,7 +4661,9 @@ def main():
ttk.Button(win_record_top, text="打开目录", command=open_win_folder).pack(side=LEFT)
ttk.Button(
win_record_top, text="实时查看", command=lambda: open_realtime_viewer_func()
win_record_top,
text="实时查看",
command=(lambda: _open_realtime_viewer_impl() if callable(_open_realtime_viewer_impl) else None),
).pack(side=LEFT, padx=(8, 0))
# 误识别记录管理