feat: 优化滑动重置回退延迟,从2秒减少到0.1秒;完善预约系统二次回退机制

This commit is contained in:
Your Name committed 2026-01-16 21:54:09 +08:00
1 parent 54f9b39d2e
commit db75248b98
4 files changed
+56 -18

No files matched your search

+13 -1
View File
@@ -16,7 +16,7 @@
本小节记录最近完成的若干修复与功能开关,便于开发与运维快速验证和回滚。
- 概要:修复GUI中滑动重置回退方式与返回键回退的配置逻辑分离问题;完善预约系统中回退校验失败后的二次回退机制,确保能根据映射表重新定位目标直播间。
- 概要:修复GUI中滑动重置回退方式与返回键回退的配置逻辑分离问题;完善预约系统中回退校验失败后的二次回退机制,确保能根据映射表重新定位目标直播间;优化滑动重置回退过程中的延迟,从2秒减少到0.1秒以加快回退速度。
- GUI回退配置逻辑分离:
- `gui/gui_app.py`:修复保存配置逻辑,独立处理`reset_after_swipes_action`和`enable_back_on_misses`配置;重新组织UI布局,按功能分组显示相关配置。
@@ -27,11 +27,15 @@
- `douyin/reservation/douyin_reservation_logic.py`:修复回退校验失败后的二次回退逻辑,添加位置重新查找机制;确保二次回退成功时正确设置锁定期和待处理标志。
- `douyin/reservation/douyin_reservation_handler.py`:`seek_reservation_room`函数优化,确保位置差为0时仍能正确处理。
- 滑动回退延迟优化:
- `douyin/handlers/douyin_swipe_handler.py`:优化滑动重置回退过程中的延迟,从每次回退间的2秒延迟减少到0.1秒;显著加快回退到第一个直播间的速度。
- 验证要点(运行时观察):
- GUI中滑动重置回退方式与返回键回退配置完全独立,不再相互影响。
- 预约回退校验失败时,会先重新查找目标直播间位置,然后执行二次回退。
- 二次回退成功时会正确设置锁定期,避免重复处理同一预约。
- 日志中显示"重新查找目标直播间位置成功"和"第二次回退成功"的相关信息。
- 滑动重置回退过程显著加快,每次回退间的延迟从2秒减少到0.1秒。
- 快速验证命令(仓库根目录,PowerShell):
@@ -61,6 +65,14 @@ python -c "
from douyin.handlers import douyin_swipe_handler
handler = douyin_swipe_handler.SwipeHandler()
print('滑动处理器初始化正常')
# 检查回退延迟是否已优化
import inspect
source = inspect.getsource(handler.maybe_reset_after_swipes)
if 'analyser.operation.delay(0.1)' in source and 'analyser.operation.delay(2)' not in source.split('#')[0]:
print('回退延迟优化验证通过:延迟已从2秒减少到0.1秒')
else:
print('回退延迟优化验证失败:延迟未正确修改')
"
```
+1 -1
View File
@@ -371,7 +371,7 @@ class SwipeHandler:
)
except Exception:
pass
analyser.operation.delay(2)
analyser.operation.delay(0.1) # 减少回退延迟,从2秒改为0.1秒
except Exception:
pass
# 回到第一个后,计数归零,但不重置位置以保持映射表连续性
+36 -14
View File
@@ -1868,14 +1868,20 @@ def process_reservation_attend_window(
pass
# 校验失败意味着位置信息可能不准确,先尝试重新查找目标直播间的当前位置
updated_target = dict(target) # 复制一份,避免修改原预约项
updated_target = dict(
target
) # 复制一份,避免修改原预约项
try:
from douyin.reservation import douyin_reservation_handler
from douyin.reservation import (
douyin_reservation_handler,
)
current_pos = ReservationHandler.find_room_pos_by_title(
analyser,
target_room_title,
target_room_title_raw
current_pos = (
ReservationHandler.find_room_pos_by_title(
analyser,
target_room_title,
target_room_title_raw,
)
)
if current_pos is not None and current_pos > 0:
updated_target["pos_seen"] = current_pos
@@ -1898,7 +1904,9 @@ def process_reservation_attend_window(
analyser._log_kv(
"预约",
"[预约] 重新查找目标直播间位置失败,使用原有位置",
target_pos=int(target.get("pos_seen", 0)),
target_pos=int(
target.get("pos_seen", 0)
),
target_room_title=(
target_room_title[:50]
if target_room_title
@@ -1923,7 +1931,9 @@ def process_reservation_attend_window(
try:
if seek_reservation_room_callback:
ok2 = bool(
seek_reservation_room_callback(updated_target)
seek_reservation_room_callback(
updated_target
)
)
except Exception:
ok2 = False
@@ -1932,20 +1942,28 @@ def process_reservation_attend_window(
# 第二次回退成功,设置锁定期并标记待处理
focus_until_new = ft + max(0.0, poll_before)
if reservation_focus_until_ts_ref:
reservation_focus_until_ts_ref[0] = focus_until_new
reservation_focus_until_ts_ref[0] = (
focus_until_new
)
else:
reservation_focus_until_ts_ref.append(focus_until_new)
reservation_focus_until_ts_ref.append(
focus_until_new
)
if reservation_after_action_pending_ref:
reservation_after_action_pending_ref[0] = True
else:
reservation_after_action_pending_ref.append(True)
reservation_after_action_pending_ref.append(
True
)
try:
analyser._log_kv(
"预约",
"[预约] 第二次回退成功:已根据映射表回退到目标直播间",
target_pos=int(updated_target.get("pos_seen", 0)),
target_pos=int(
updated_target.get("pos_seen", 0)
),
target_room_title=(
target_room_title[:50]
if target_room_title
@@ -1972,7 +1990,9 @@ def process_reservation_attend_window(
pass
try:
if reservation_after_action_pending_ref:
reservation_after_action_pending_ref[0] = False
reservation_after_action_pending_ref[0] = (
False
)
except Exception:
pass
@@ -1980,7 +2000,9 @@ def process_reservation_attend_window(
analyser._log_kv(
"预约",
"[预约] 第二次回退失败:无法根据映射表定位到目标直播间",
target_pos=int(updated_target.get("pos_seen", 0)),
target_pos=int(
updated_target.get("pos_seen", 0)
),
target_room_title=(
target_room_title[:50]
if target_room_title
+6 -2
View File
@@ -2008,7 +2008,9 @@ def main():
except Exception:
enable_back_on_misses_var.set(True)
try:
reset_after_swipes_action_var.set(str(cfg.get("reset_after_swipes_action", "swipe")))
reset_after_swipes_action_var.set(
str(cfg.get("reset_after_swipes_action", "swipe"))
)
except Exception:
reset_after_swipes_action_var.set("swipe")
switch_room_wait_after_stage_diag_seconds_var.set(
@@ -2301,7 +2303,9 @@ def main():
)
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["reset_after_swipes_action"] = str(reset_after_swipes_action_var.get() or "swipe")
cfg2["reset_after_swipes_action"] = str(
reset_after_swipes_action_var.get() or "swipe"
)
cfg2["fudai_disable_content_recognition"] = bool(
fudai_disable_content_recognition_var.get()
)