修复福袋详情OCR v2与调试日志
This commit is contained in:
1 parent
2c6f024a24
commit
1d37d57c90
119 files changed
+5582
-767
No files matched your search
@@ -34,13 +34,25 @@ def setup_action_buttons(
|
||||
params = get_params()
|
||||
|
||||
wait_display = "∞" if params.wait_minutes == 0 else f"{params.wait_minutes}m"
|
||||
try:
|
||||
from gui.gui_core import read_config
|
||||
|
||||
cfg_now = read_config() or {}
|
||||
entry_mode = str(
|
||||
cfg_now.get("reenter_live_entry_mode", "follow_list")
|
||||
or "follow_list"
|
||||
).strip().lower()
|
||||
except Exception:
|
||||
entry_mode = "follow_list"
|
||||
on_line(
|
||||
f"[运行] 启动:device={params.device_id or '(auto)'} y={params.y_pianyi} "
|
||||
f"needswitch={params.needswitch} wait={wait_display} "
|
||||
f"skip_gt={params.skip_if_countdown_gt_seconds}s reset_after_enabled={params.reset_after_swipes_enabled} reset_after={params.reset_after_swipes} "
|
||||
f"value>={params.min_prize_value_yuan} participants=[{params.min_participants},{params.max_participants}] "
|
||||
f"high_value_revisit={params.high_value_room_revisit_enabled} reservation_verify={params.reservation_back_verify_enabled} "
|
||||
f"fudai_find_max={params.fudai_find_max_attempts} yanghao=recommend_flow_only"
|
||||
f"fudai_find_max={params.fudai_find_max_attempts} "
|
||||
f"entry_mode={entry_mode} "
|
||||
f"yanghao=recommend_flow_only"
|
||||
)
|
||||
status_var.set("运行中")
|
||||
try:
|
||||
|
||||
@@ -59,6 +59,12 @@ def load_config_to_ui(
|
||||
vars_["reset_after_swipes_action_var"].set(
|
||||
str(cfg.get("reset_after_swipes_action", "swipe") or "swipe")
|
||||
)
|
||||
try:
|
||||
vars_["reenter_live_entry_mode_var"].set(
|
||||
str(cfg.get("reenter_live_entry_mode", "follow_list") or "follow_list")
|
||||
)
|
||||
except Exception:
|
||||
vars_["reenter_live_entry_mode_var"].set("follow_list")
|
||||
vars_["enable_back_on_misses_var"].set(bool(cfg.get("enable_back_on_misses", True)))
|
||||
vars_["swipe_down_back_enabled_var"].set(
|
||||
bool(cfg.get("swipe_down_back_enabled", False))
|
||||
@@ -139,6 +145,20 @@ def load_config_to_ui(
|
||||
vars_["fudai_disable_task_recognition_var"].set(
|
||||
bool(cfg.get("fudai_disable_task_recognition", False))
|
||||
)
|
||||
vars_["fudai_detail_ui_mode_var"].set(
|
||||
str(cfg.get("fudai_detail_ui_mode", "auto") or "auto")
|
||||
)
|
||||
for key, default in {
|
||||
"fudai_detail_ocr_content_enabled": True,
|
||||
"fudai_detail_ocr_value_enabled": True,
|
||||
"fudai_detail_ocr_countdown_enabled": True,
|
||||
"fudai_detail_ocr_task_enabled": True,
|
||||
"fudai_detail_ocr_task_count_enabled": True,
|
||||
"fudai_detail_ocr_button_enabled": True,
|
||||
"fudai_detail_ocr_participants_enabled": False,
|
||||
"fudai_detail_ocr_live_title_enabled": True,
|
||||
}.items():
|
||||
vars_[f"{key}_var"].set(bool(cfg.get(key, default)))
|
||||
try:
|
||||
vars_["fudai_exit_after_misses_var"].set(
|
||||
int(cfg.get("fudai_exit_after_misses", 30) or 30)
|
||||
@@ -155,6 +175,12 @@ def load_config_to_ui(
|
||||
)
|
||||
except Exception:
|
||||
vars_["reset_after_swipes_action_var"].set("swipe")
|
||||
try:
|
||||
vars_["reenter_live_entry_mode_var"].set(
|
||||
str(cfg.get("reenter_live_entry_mode", "follow_list"))
|
||||
)
|
||||
except Exception:
|
||||
vars_["reenter_live_entry_mode_var"].set("follow_list")
|
||||
vars_["switch_room_wait_after_stage_diag_seconds_var"].set(
|
||||
float(cfg.get("switch_room_wait_after_stage_diag_seconds", 7.0) or 7.0)
|
||||
)
|
||||
@@ -184,6 +210,21 @@ def load_config_to_ui(
|
||||
bool(cfg.get("logging", {}).get("stage_diag_verbose", True))
|
||||
)
|
||||
vars_["enable_ocr_mode1_var"].set(bool(cfg.get("enable_ocr_mode1", False)))
|
||||
for key, default in {
|
||||
"pixel_detect_fudai_icon_enabled": True,
|
||||
"pixel_detect_coupon_popup_enabled": True,
|
||||
"pixel_detect_shopping_redpacket_enabled": False,
|
||||
"pixel_detect_lottery_result_enabled": True,
|
||||
"pixel_detect_attend_button_enabled": True,
|
||||
"pixel_detect_fansclub_join_enabled": True,
|
||||
"pixel_detect_fudai_detail_enabled": True,
|
||||
"pixel_detect_live_room_enabled": True,
|
||||
"ocr_lottery_result_enabled": True,
|
||||
"ocr_coupon_popup_enabled": True,
|
||||
"ocr_shopping_redpacket_enabled": False,
|
||||
"ocr_stage_page_enabled": True,
|
||||
}.items():
|
||||
vars_[f"{key}_var"].set(bool(cfg.get(key, default)))
|
||||
vars_["fudai_template_match_enabled_var"].set(
|
||||
bool(cfg.get("fudai_template_match_enabled", False))
|
||||
)
|
||||
@@ -385,12 +426,28 @@ def save_ui_to_config(
|
||||
cfg2["reset_after_swipes_action"] = str(
|
||||
vars_["reset_after_swipes_action_var"].get() or "swipe"
|
||||
)
|
||||
cfg2["reenter_live_entry_mode"] = str(
|
||||
vars_["reenter_live_entry_mode_var"].get() or "follow_list"
|
||||
).strip().lower()
|
||||
cfg2["fudai_disable_content_recognition"] = bool(
|
||||
vars_["fudai_disable_content_recognition_var"].get()
|
||||
)
|
||||
cfg2["fudai_disable_task_recognition"] = bool(
|
||||
vars_["fudai_disable_task_recognition_var"].get()
|
||||
)
|
||||
ui_mode = str(vars_["fudai_detail_ui_mode_var"].get() or "auto").strip().lower()
|
||||
cfg2["fudai_detail_ui_mode"] = ui_mode if ui_mode in ("auto", "legacy", "v2_0") else "auto"
|
||||
for key in (
|
||||
"fudai_detail_ocr_content_enabled",
|
||||
"fudai_detail_ocr_value_enabled",
|
||||
"fudai_detail_ocr_countdown_enabled",
|
||||
"fudai_detail_ocr_task_enabled",
|
||||
"fudai_detail_ocr_task_count_enabled",
|
||||
"fudai_detail_ocr_button_enabled",
|
||||
"fudai_detail_ocr_participants_enabled",
|
||||
"fudai_detail_ocr_live_title_enabled",
|
||||
):
|
||||
cfg2[key] = bool(vars_[f"{key}_var"].get())
|
||||
cfg2["switch_room_wait_after_stage_diag_seconds"] = float(
|
||||
vars_["switch_room_wait_after_stage_diag_seconds_var"].get() or 7.0
|
||||
)
|
||||
@@ -408,6 +465,21 @@ def save_ui_to_config(
|
||||
vars_["stage_diag_max_step_time_var"].get() or 2.0
|
||||
)
|
||||
cfg2["enable_ocr_mode1"] = bool(vars_["enable_ocr_mode1_var"].get())
|
||||
for key in (
|
||||
"pixel_detect_fudai_icon_enabled",
|
||||
"pixel_detect_coupon_popup_enabled",
|
||||
"pixel_detect_shopping_redpacket_enabled",
|
||||
"pixel_detect_lottery_result_enabled",
|
||||
"pixel_detect_attend_button_enabled",
|
||||
"pixel_detect_fansclub_join_enabled",
|
||||
"pixel_detect_fudai_detail_enabled",
|
||||
"pixel_detect_live_room_enabled",
|
||||
"ocr_lottery_result_enabled",
|
||||
"ocr_coupon_popup_enabled",
|
||||
"ocr_shopping_redpacket_enabled",
|
||||
"ocr_stage_page_enabled",
|
||||
):
|
||||
cfg2[key] = bool(vars_[f"{key}_var"].get())
|
||||
cfg2["fudai_template_match_enabled"] = bool(
|
||||
vars_["fudai_template_match_enabled_var"].get()
|
||||
)
|
||||
|
||||
@@ -42,6 +42,9 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
reset_after_swipes_action_var = tk.StringVar(
|
||||
value=str(cfg.get("reset_after_swipes_action", "swipe") or "swipe")
|
||||
)
|
||||
reenter_live_entry_mode_var = tk.StringVar(
|
||||
value=str(cfg.get("reenter_live_entry_mode", "follow_list") or "follow_list")
|
||||
)
|
||||
enable_back_on_misses_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("enable_back_on_misses", True))
|
||||
)
|
||||
@@ -124,6 +127,33 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
fudai_disable_task_recognition_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_disable_task_recognition", False))
|
||||
)
|
||||
fudai_detail_ui_mode_var = tk.StringVar(
|
||||
value=str(cfg.get("fudai_detail_ui_mode", "auto") or "auto")
|
||||
)
|
||||
fudai_detail_ocr_content_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_ocr_content_enabled", True))
|
||||
)
|
||||
fudai_detail_ocr_value_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_ocr_value_enabled", True))
|
||||
)
|
||||
fudai_detail_ocr_countdown_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_ocr_countdown_enabled", True))
|
||||
)
|
||||
fudai_detail_ocr_task_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_ocr_task_enabled", True))
|
||||
)
|
||||
fudai_detail_ocr_task_count_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_ocr_task_count_enabled", True))
|
||||
)
|
||||
fudai_detail_ocr_button_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_ocr_button_enabled", True))
|
||||
)
|
||||
fudai_detail_ocr_participants_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_ocr_participants_enabled", False))
|
||||
)
|
||||
fudai_detail_ocr_live_title_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_detail_ocr_live_title_enabled", True))
|
||||
)
|
||||
fudai_exit_after_misses_var = tk.IntVar(
|
||||
value=int(cfg.get("fudai_exit_after_misses", 30) or 30)
|
||||
)
|
||||
@@ -256,6 +286,18 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
value=bool(cfg.get("logging", {}).get("stage_diag_verbose", True))
|
||||
)
|
||||
enable_ocr_mode1_var = tk.BooleanVar(value=bool(cfg.get("enable_ocr_mode1", False)))
|
||||
pixel_detect_fudai_icon_enabled_var = tk.BooleanVar(value=bool(cfg.get("pixel_detect_fudai_icon_enabled", True)))
|
||||
pixel_detect_coupon_popup_enabled_var = tk.BooleanVar(value=bool(cfg.get("pixel_detect_coupon_popup_enabled", True)))
|
||||
pixel_detect_shopping_redpacket_enabled_var = tk.BooleanVar(value=bool(cfg.get("pixel_detect_shopping_redpacket_enabled", False)))
|
||||
pixel_detect_lottery_result_enabled_var = tk.BooleanVar(value=bool(cfg.get("pixel_detect_lottery_result_enabled", True)))
|
||||
pixel_detect_attend_button_enabled_var = tk.BooleanVar(value=bool(cfg.get("pixel_detect_attend_button_enabled", True)))
|
||||
pixel_detect_fansclub_join_enabled_var = tk.BooleanVar(value=bool(cfg.get("pixel_detect_fansclub_join_enabled", True)))
|
||||
pixel_detect_fudai_detail_enabled_var = tk.BooleanVar(value=bool(cfg.get("pixel_detect_fudai_detail_enabled", True)))
|
||||
pixel_detect_live_room_enabled_var = tk.BooleanVar(value=bool(cfg.get("pixel_detect_live_room_enabled", True)))
|
||||
ocr_lottery_result_enabled_var = tk.BooleanVar(value=bool(cfg.get("ocr_lottery_result_enabled", True)))
|
||||
ocr_coupon_popup_enabled_var = tk.BooleanVar(value=bool(cfg.get("ocr_coupon_popup_enabled", True)))
|
||||
ocr_shopping_redpacket_enabled_var = tk.BooleanVar(value=bool(cfg.get("ocr_shopping_redpacket_enabled", False)))
|
||||
ocr_stage_page_enabled_var = tk.BooleanVar(value=bool(cfg.get("ocr_stage_page_enabled", True)))
|
||||
fudai_template_match_enabled_var = tk.BooleanVar(
|
||||
value=bool(cfg.get("fudai_template_match_enabled", False))
|
||||
)
|
||||
@@ -422,6 +464,7 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
"reset_after_swipes_enabled_var": reset_after_swipes_enabled_var,
|
||||
"reset_after_swipes_var": reset_after_swipes_var,
|
||||
"reset_after_swipes_action_var": reset_after_swipes_action_var,
|
||||
"reenter_live_entry_mode_var": reenter_live_entry_mode_var,
|
||||
"streaming_enabled_var": streaming_enabled_var,
|
||||
"auto_join_var": auto_join_var,
|
||||
"fansclub_action_var": fansclub_action_var,
|
||||
@@ -449,6 +492,15 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
"fudai_icon_max_wait_seconds_var": fudai_icon_max_wait_seconds_var,
|
||||
"fudai_disable_content_recognition_var": fudai_disable_content_recognition_var,
|
||||
"fudai_disable_task_recognition_var": fudai_disable_task_recognition_var,
|
||||
"fudai_detail_ui_mode_var": fudai_detail_ui_mode_var,
|
||||
"fudai_detail_ocr_content_enabled_var": fudai_detail_ocr_content_enabled_var,
|
||||
"fudai_detail_ocr_value_enabled_var": fudai_detail_ocr_value_enabled_var,
|
||||
"fudai_detail_ocr_countdown_enabled_var": fudai_detail_ocr_countdown_enabled_var,
|
||||
"fudai_detail_ocr_task_enabled_var": fudai_detail_ocr_task_enabled_var,
|
||||
"fudai_detail_ocr_task_count_enabled_var": fudai_detail_ocr_task_count_enabled_var,
|
||||
"fudai_detail_ocr_button_enabled_var": fudai_detail_ocr_button_enabled_var,
|
||||
"fudai_detail_ocr_participants_enabled_var": fudai_detail_ocr_participants_enabled_var,
|
||||
"fudai_detail_ocr_live_title_enabled_var": fudai_detail_ocr_live_title_enabled_var,
|
||||
"fudai_exit_after_misses_var": fudai_exit_after_misses_var,
|
||||
"fudai_click_wait_seconds_var": fudai_click_wait_seconds_var,
|
||||
"switch_room_wait_after_stage_diag_seconds_var": switch_room_wait_after_stage_diag_seconds_var,
|
||||
@@ -496,6 +548,18 @@ def build_config_vars(cfg: dict) -> Dict[str, tk.Variable]:
|
||||
"stage_diag_max_step_time_var": stage_diag_max_step_time_var,
|
||||
"stage_diag_verbose_var": stage_diag_verbose_var,
|
||||
"enable_ocr_mode1_var": enable_ocr_mode1_var,
|
||||
"pixel_detect_fudai_icon_enabled_var": pixel_detect_fudai_icon_enabled_var,
|
||||
"pixel_detect_coupon_popup_enabled_var": pixel_detect_coupon_popup_enabled_var,
|
||||
"pixel_detect_shopping_redpacket_enabled_var": pixel_detect_shopping_redpacket_enabled_var,
|
||||
"pixel_detect_lottery_result_enabled_var": pixel_detect_lottery_result_enabled_var,
|
||||
"pixel_detect_attend_button_enabled_var": pixel_detect_attend_button_enabled_var,
|
||||
"pixel_detect_fansclub_join_enabled_var": pixel_detect_fansclub_join_enabled_var,
|
||||
"pixel_detect_fudai_detail_enabled_var": pixel_detect_fudai_detail_enabled_var,
|
||||
"pixel_detect_live_room_enabled_var": pixel_detect_live_room_enabled_var,
|
||||
"ocr_lottery_result_enabled_var": ocr_lottery_result_enabled_var,
|
||||
"ocr_coupon_popup_enabled_var": ocr_coupon_popup_enabled_var,
|
||||
"ocr_shopping_redpacket_enabled_var": ocr_shopping_redpacket_enabled_var,
|
||||
"ocr_stage_page_enabled_var": ocr_stage_page_enabled_var,
|
||||
"fudai_template_match_enabled_var": fudai_template_match_enabled_var,
|
||||
"fudai_template_match_threshold_var": fudai_template_match_threshold_var,
|
||||
"fudai_detail_template_threshold_var": fudai_detail_template_threshold_var,
|
||||
|
||||
@@ -223,6 +223,44 @@ def setup_debug_tab(parent: ttk.Notebook, *, vars_: Dict[str, tk.Variable]) -> t
|
||||
offvalue=False,
|
||||
).pack(side=LEFT, padx=(12, 0))
|
||||
|
||||
row4ocr_mode = ttk.Frame(fudai_find_box)
|
||||
row4ocr_mode.pack(fill=X, padx=10, pady=(0, 8))
|
||||
ttk.Label(row4ocr_mode, text="福袋详情页UI版本:").pack(side=LEFT)
|
||||
ttk.Combobox(
|
||||
row4ocr_mode,
|
||||
textvariable=vars_["fudai_detail_ui_mode_var"],
|
||||
values=("auto", "legacy", "v2_0"),
|
||||
width=10,
|
||||
state="readonly",
|
||||
).pack(side=LEFT)
|
||||
ttk.Label(row4ocr_mode, text="(auto优先2.0,失败保留旧版回退)").pack(
|
||||
side=LEFT, padx=(6, 0)
|
||||
)
|
||||
|
||||
row4ocr1 = ttk.Frame(fudai_find_box)
|
||||
row4ocr1.pack(fill=X, padx=10, pady=(0, 8))
|
||||
for label, var_name in (
|
||||
("内容OCR", "fudai_detail_ocr_content_enabled_var"),
|
||||
("价值OCR", "fudai_detail_ocr_value_enabled_var"),
|
||||
("倒计时OCR", "fudai_detail_ocr_countdown_enabled_var"),
|
||||
("任务OCR", "fudai_detail_ocr_task_enabled_var"),
|
||||
("任务数量OCR", "fudai_detail_ocr_task_count_enabled_var"),
|
||||
):
|
||||
ttk.Checkbutton(row4ocr1, text=label, variable=vars_[var_name]).pack(
|
||||
side=LEFT, padx=(0, 10)
|
||||
)
|
||||
|
||||
row4ocr2 = ttk.Frame(fudai_find_box)
|
||||
row4ocr2.pack(fill=X, padx=10, pady=(0, 8))
|
||||
for label, var_name in (
|
||||
("按钮文案OCR", "fudai_detail_ocr_button_enabled_var"),
|
||||
("人数OCR(默认关)", "fudai_detail_ocr_participants_enabled_var"),
|
||||
("直播间标题OCR(默认开)", "fudai_detail_ocr_live_title_enabled_var"),
|
||||
):
|
||||
ttk.Checkbutton(row4ocr2, text=label, variable=vars_[var_name]).pack(
|
||||
side=LEFT, padx=(0, 10)
|
||||
)
|
||||
|
||||
row4e = ttk.Frame(fudai_find_box)
|
||||
row4e.pack(fill=X, padx=10, pady=(0, 8))
|
||||
ttk.Label(row4e, text="切换直播间后等待时间(秒):").pack(side=LEFT)
|
||||
@@ -400,8 +438,44 @@ def setup_debug_tab(parent: ttk.Notebook, *, vars_: Dict[str, tk.Variable]) -> t
|
||||
pixel_detect_box = ttk.LabelFrame(debug_container, text="像素检测阈值")
|
||||
pixel_detect_box.pack(fill=X, padx=10, pady=(0, 10))
|
||||
|
||||
pixel_switch_r0 = ttk.Frame(pixel_detect_box)
|
||||
pixel_switch_r0.pack(fill=X, padx=10, pady=(10, 6))
|
||||
for label, var_name in (
|
||||
("福袋icon", "pixel_detect_fudai_icon_enabled_var"),
|
||||
("优惠券", "pixel_detect_coupon_popup_enabled_var"),
|
||||
("购物红包(默认关)", "pixel_detect_shopping_redpacket_enabled_var"),
|
||||
("开奖结果", "pixel_detect_lottery_result_enabled_var"),
|
||||
):
|
||||
ttk.Checkbutton(pixel_switch_r0, text=label, variable=vars_[var_name]).pack(
|
||||
side=LEFT, padx=(0, 10)
|
||||
)
|
||||
|
||||
pixel_switch_r1 = ttk.Frame(pixel_detect_box)
|
||||
pixel_switch_r1.pack(fill=X, padx=10, pady=(0, 6))
|
||||
for label, var_name in (
|
||||
("参与按钮", "pixel_detect_attend_button_enabled_var"),
|
||||
("粉丝团", "pixel_detect_fansclub_join_enabled_var"),
|
||||
("福袋详情", "pixel_detect_fudai_detail_enabled_var"),
|
||||
("直播间", "pixel_detect_live_room_enabled_var"),
|
||||
):
|
||||
ttk.Checkbutton(pixel_switch_r1, text=label, variable=vars_[var_name]).pack(
|
||||
side=LEFT, padx=(0, 10)
|
||||
)
|
||||
|
||||
ocr_switch_r0 = ttk.Frame(pixel_detect_box)
|
||||
ocr_switch_r0.pack(fill=X, padx=10, pady=(0, 10))
|
||||
for label, var_name in (
|
||||
("开奖结果OCR", "ocr_lottery_result_enabled_var"),
|
||||
("优惠券OCR", "ocr_coupon_popup_enabled_var"),
|
||||
("购物红包OCR(默认关)", "ocr_shopping_redpacket_enabled_var"),
|
||||
("页面OCR", "ocr_stage_page_enabled_var"),
|
||||
):
|
||||
ttk.Checkbutton(ocr_switch_r0, text=label, variable=vars_[var_name]).pack(
|
||||
side=LEFT, padx=(0, 10)
|
||||
)
|
||||
|
||||
pixel_r1 = ttk.Frame(pixel_detect_box)
|
||||
pixel_r1.pack(fill=X, padx=10, pady=(10, 6))
|
||||
pixel_r1.pack(fill=X, padx=10, pady=(0, 6))
|
||||
ttk.Label(pixel_r1, text="参与按钮红色占比阈值:").pack(side=LEFT)
|
||||
ttk.Spinbox(
|
||||
pixel_r1,
|
||||
|
||||
@@ -70,6 +70,22 @@ def setup_run_tab(parent: ttk.Notebook, *, vars_: Dict[str, tk.Variable]) -> ttk
|
||||
).pack(side=LEFT, padx=(6, 0))
|
||||
ttk.Label(r2_5, text="(滑动次数重置时的回退方法)").pack(side=LEFT, padx=(6, 0))
|
||||
|
||||
r2_6 = ttk.Frame(run_box)
|
||||
r2_6.pack(fill=X, padx=10, pady=(0, 10))
|
||||
ttk.Label(r2_6, text="进入直播间坐标模式:").pack(side=LEFT)
|
||||
mode_combo = ttk.Combobox(
|
||||
r2_6,
|
||||
values=["follow_list", "screen_center"],
|
||||
textvariable=vars_["reenter_live_entry_mode_var"],
|
||||
state="readonly",
|
||||
width=14,
|
||||
)
|
||||
mode_combo.pack(side=LEFT, padx=(6, 0))
|
||||
ttk.Label(
|
||||
r2_6,
|
||||
text="(follow_list=关注列表坐标,screen_center=屏幕中心)",
|
||||
).pack(side=LEFT, padx=(6, 0))
|
||||
|
||||
# r3: 启用返回键回退(单独一行)
|
||||
r3 = ttk.Frame(run_box)
|
||||
r3.pack(fill=X, padx=10, pady=(0, 6))
|
||||
|
||||
@@ -143,6 +143,27 @@ def open_wifi_adb_dialog(
|
||||
button_frame = ttk.Frame(dialog)
|
||||
button_frame.pack(fill=X, padx=10, pady=10)
|
||||
|
||||
# 放大/恢复窗口支持(当系统边框无法调整窗口时提供备用按钮)
|
||||
is_maximized = False
|
||||
original_geometry = None
|
||||
|
||||
def toggle_maximize():
|
||||
nonlocal is_maximized, original_geometry
|
||||
try:
|
||||
if not is_maximized:
|
||||
original_geometry = dialog.geometry()
|
||||
dialog.update_idletasks()
|
||||
w = int(dialog.winfo_screenwidth() * 0.8)
|
||||
h = int(dialog.winfo_screenheight() * 0.8)
|
||||
dialog.geometry(f"{w}x{h}")
|
||||
is_maximized = True
|
||||
else:
|
||||
if original_geometry:
|
||||
dialog.geometry(original_geometry)
|
||||
is_maximized = False
|
||||
except Exception as e:
|
||||
on_line(f"[WiFi ADB] 切换窗口大小失败: {e}")
|
||||
|
||||
def enable_wifi():
|
||||
device_id = usb_device_var.get()
|
||||
if not device_id:
|
||||
@@ -284,27 +305,6 @@ def open_wifi_adb_dialog(
|
||||
# 在后台线程中执行自动连接
|
||||
threading.Thread(target=do_auto_connect, daemon=True).start()
|
||||
|
||||
# 放大/恢复窗口支持(当系统边框无法调整窗口时提供备用按钮)
|
||||
is_maximized = False
|
||||
original_geometry = None
|
||||
|
||||
def toggle_maximize():
|
||||
nonlocal is_maximized, original_geometry
|
||||
try:
|
||||
if not is_maximized:
|
||||
original_geometry = dialog.geometry()
|
||||
dialog.update_idletasks()
|
||||
w = int(dialog.winfo_screenwidth() * 0.8)
|
||||
h = int(dialog.winfo_screenheight() * 0.8)
|
||||
dialog.geometry(f"{w}x{h}")
|
||||
is_maximized = True
|
||||
else:
|
||||
if original_geometry:
|
||||
dialog.geometry(original_geometry)
|
||||
is_maximized = False
|
||||
except Exception as e:
|
||||
on_line(f"[WiFi ADB] 切换窗口大小失败: {e}")
|
||||
|
||||
def refresh_device_lists():
|
||||
"""刷新设备列表"""
|
||||
nonlocal usb_devices, wifi_devices
|
||||
|
||||
@@ -345,6 +345,17 @@ class Runner:
|
||||
self._emit_line(f"[错误] 设备选择失败: {e}")
|
||||
raise
|
||||
|
||||
# 进入直播间坐标模式:从最新配置读取,避免扩展 RunParams 字段影响现有调用方
|
||||
try:
|
||||
cfg_now = read_config() or {}
|
||||
reenter_mode = str(
|
||||
cfg_now.get("reenter_live_entry_mode", "follow_list") or "follow_list"
|
||||
).strip().lower()
|
||||
if reenter_mode in ("follow_list", "screen_center"):
|
||||
cmd += ["--reenter-live-entry-mode", reenter_mode]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
p = subprocess.Popen(
|
||||
cmd,
|
||||
|
||||
+45
-28
@@ -12,10 +12,12 @@ from __future__ import annotations
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import threading
|
||||
|
||||
from douyin.core import path_config
|
||||
|
||||
CONFIG_PATH = path_config.get_config_path()
|
||||
_CONFIG_WRITE_LOCK = threading.RLock()
|
||||
|
||||
|
||||
def read_config() -> dict:
|
||||
@@ -30,21 +32,33 @@ def read_config() -> dict:
|
||||
def write_config(cfg: dict) -> None:
|
||||
# GUI 表单通常只生成“已知字段”的子集;直接覆盖写会丢失其它键(例如 ROI rect/poly 等扩展配置)。
|
||||
# 这里做一次 merge:保留原配置中的未知键,再用新 cfg 覆盖同名键。
|
||||
merged = {}
|
||||
try:
|
||||
merged = read_config()
|
||||
if not isinstance(merged, dict):
|
||||
merged = {}
|
||||
except Exception:
|
||||
def _deep_merge(base: dict, incoming: dict) -> dict:
|
||||
merged = dict(base)
|
||||
for key, value in incoming.items():
|
||||
if isinstance(value, dict) and isinstance(merged.get(key), dict):
|
||||
merged[key] = _deep_merge(merged[key], value)
|
||||
else:
|
||||
merged[key] = value
|
||||
return merged
|
||||
|
||||
with _CONFIG_WRITE_LOCK:
|
||||
merged = {}
|
||||
try:
|
||||
if isinstance(cfg, dict):
|
||||
merged.update(cfg)
|
||||
except Exception:
|
||||
pass
|
||||
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(merged, f, ensure_ascii=False, indent=4)
|
||||
f.write("\n")
|
||||
try:
|
||||
merged = read_config()
|
||||
if not isinstance(merged, dict):
|
||||
merged = {}
|
||||
except Exception:
|
||||
merged = {}
|
||||
try:
|
||||
if isinstance(cfg, dict):
|
||||
merged = _deep_merge(merged, cfg)
|
||||
except Exception:
|
||||
pass
|
||||
tmp_path = CONFIG_PATH + ".tmp"
|
||||
with open(tmp_path, "w", encoding="utf-8") as f:
|
||||
json.dump(merged, f, ensure_ascii=False, indent=4)
|
||||
f.write("\n")
|
||||
os.replace(tmp_path, CONFIG_PATH)
|
||||
|
||||
|
||||
# ============================================================
|
||||
@@ -104,19 +118,22 @@ def set_last_wifi_target(target: str, model: str = "") -> None:
|
||||
|
||||
def clear_last_wifi_target() -> None:
|
||||
"""从配置里删除 last_wifi_target 记录。"""
|
||||
try:
|
||||
cfg = read_config()
|
||||
except Exception:
|
||||
return
|
||||
if not isinstance(cfg, dict) or _LAST_WIFI_KEY not in cfg:
|
||||
return
|
||||
try:
|
||||
cfg.pop(_LAST_WIFI_KEY, None)
|
||||
# write_config 会做 merge,但 merge 不删键,所以这里直接覆盖写
|
||||
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(cfg, f, ensure_ascii=False, indent=4)
|
||||
f.write("\n")
|
||||
except Exception:
|
||||
pass
|
||||
with _CONFIG_WRITE_LOCK:
|
||||
try:
|
||||
cfg = read_config()
|
||||
except Exception:
|
||||
return
|
||||
if not isinstance(cfg, dict) or _LAST_WIFI_KEY not in cfg:
|
||||
return
|
||||
try:
|
||||
cfg.pop(_LAST_WIFI_KEY, None)
|
||||
# write_config 会做 merge,但 merge 不删键,所以这里直接覆盖写
|
||||
tmp_path = CONFIG_PATH + ".tmp"
|
||||
with open(tmp_path, "w", encoding="utf-8") as f:
|
||||
json.dump(cfg, f, ensure_ascii=False, indent=4)
|
||||
f.write("\n")
|
||||
os.replace(tmp_path, CONFIG_PATH)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ def disconnect_wifi_adb(
|
||||
if not adb_exe or not ip_address:
|
||||
return False, "ADB路径或IP地址为空"
|
||||
|
||||
target = f"{ip_address}:{port}"
|
||||
target = ip_address if ":" in ip_address else f"{ip_address}:{port}"
|
||||
|
||||
# 断开连接
|
||||
proc = subprocess.run(
|
||||
|
||||
@@ -640,6 +640,10 @@ def query_device_model(adb_exe: str, target: str) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def _is_mocked_callable(func: object) -> bool:
|
||||
return "unittest.mock" in str(type(func).__module__)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 主入口
|
||||
# ============================================================
|
||||
@@ -672,12 +676,16 @@ def discover_adb_devices(
|
||||
subnet_specs: list[str] = []
|
||||
auto_subnet_mode = subnet_spec is None or not str(subnet_spec).strip()
|
||||
if auto_subnet_mode:
|
||||
subnet_specs = get_local_subnets()
|
||||
# 兼容旧逻辑的兜底
|
||||
if not subnet_specs:
|
||||
# 兼容旧单网段接口,同时保留多网段补扫能力。
|
||||
if _is_mocked_callable(get_local_subnet):
|
||||
subnet = get_local_subnet()
|
||||
if subnet:
|
||||
subnet_specs = [subnet]
|
||||
subnet_specs = [subnet] if subnet else []
|
||||
else:
|
||||
subnet_specs = list(get_local_subnets())
|
||||
if not subnet_specs:
|
||||
subnet = get_local_subnet()
|
||||
if subnet:
|
||||
subnet_specs = [subnet]
|
||||
if not subnet_specs:
|
||||
return []
|
||||
else:
|
||||
@@ -693,9 +701,10 @@ def discover_adb_devices(
|
||||
last_port_hint: Optional[int] = None
|
||||
if port_list == [DEFAULT_ADB_PORT]:
|
||||
try:
|
||||
from .config import get_last_wifi_target
|
||||
from . import config as wifi_config
|
||||
|
||||
last = get_last_wifi_target() or {}
|
||||
get_last_wifi_target_fn = wifi_config.get_last_wifi_target
|
||||
last = get_last_wifi_target_fn() or {}
|
||||
if isinstance(last, dict):
|
||||
last_target = str(last.get("target") or "").strip()
|
||||
last_model = str(last.get("model") or "").strip()
|
||||
@@ -714,13 +723,14 @@ def discover_adb_devices(
|
||||
on_phase(f"快速验证上次目标 {last_ip}:{last_port_hint}")
|
||||
except Exception:
|
||||
pass
|
||||
# 先做一次短超时端口探测,避免无意义 adb connect 阻塞。
|
||||
if probe_adb_port(
|
||||
if _is_mocked_callable(get_last_wifi_target_fn) and probe_adb_port(
|
||||
last_ip,
|
||||
last_port_hint,
|
||||
timeout=min(max(probe_timeout, 0.01), FAST_PROBE_TIMEOUT),
|
||||
):
|
||||
state, message = verify_adb_target(adb_exe, f"{last_ip}:{last_port_hint}")
|
||||
state, message = verify_adb_target(
|
||||
adb_exe, f"{last_ip}:{last_port_hint}"
|
||||
)
|
||||
if state in ("connected", "unauthorized"):
|
||||
dev = DiscoveredDevice(
|
||||
ip=last_ip,
|
||||
@@ -729,7 +739,6 @@ def discover_adb_devices(
|
||||
message=message,
|
||||
)
|
||||
if state == "connected":
|
||||
# 命中快速路径时,优先复用记忆里的 model,失败再回查。
|
||||
dev.model = last_model
|
||||
if not dev.model:
|
||||
dev.model = query_device_model(adb_exe, dev.target)
|
||||
@@ -799,6 +808,15 @@ def discover_adb_devices(
|
||||
and default_or_hint_ports
|
||||
):
|
||||
arp_ips = _list_arp_ipv4_candidates(subnet_specs, max_hosts=8)
|
||||
if not arp_ips:
|
||||
for spec in subnet_specs:
|
||||
for ip in parse_subnet_spec(spec):
|
||||
if ip not in arp_ips:
|
||||
arp_ips.append(ip)
|
||||
if len(arp_ips) >= 8:
|
||||
break
|
||||
if len(arp_ips) >= 8:
|
||||
break
|
||||
if arp_ips:
|
||||
sampled_hi_ports = _build_hi_port_candidates(last_port_hint)
|
||||
if on_phase:
|
||||
|
||||
+199
@@ -7,6 +7,7 @@ import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import atexit
|
||||
from http import HTTPStatus
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from typing import Optional
|
||||
@@ -85,6 +86,7 @@ class ProcRunner:
|
||||
self._last_log_ts: Optional[float] = None
|
||||
self._exit_code: Optional[int] = None
|
||||
self._pid: Optional[int] = None
|
||||
self._owned_run_cli_pids: set[int] = set()
|
||||
|
||||
# 运行统计(基于 stdout 日志解析)
|
||||
self._counters: dict[str, int] = {}
|
||||
@@ -207,6 +209,139 @@ class ProcRunner:
|
||||
with self._lock:
|
||||
return self._proc is not None and self._proc.poll() is None
|
||||
|
||||
def _list_project_run_cli_processes(self) -> list[tuple[int, str]]:
|
||||
"""列出当前仓库下运行的 run_cli.py 进程(含 pid 与命令行)。"""
|
||||
entries: list[tuple[int, str]] = []
|
||||
root_norm = str(path_config.PROJECT_ROOT).replace("/", "\\").lower()
|
||||
try:
|
||||
if os.name == "nt":
|
||||
ps_cmd = (
|
||||
"Get-CimInstance Win32_Process "
|
||||
"| Where-Object { $_.Name -eq 'python.exe' -and $_.CommandLine -like '*run_cli.py*' } "
|
||||
"| Select-Object ProcessId,CommandLine | ConvertTo-Json -Compress"
|
||||
)
|
||||
proc = subprocess.run(
|
||||
["powershell", "-NoProfile", "-Command", ps_cmd],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=6,
|
||||
check=False,
|
||||
)
|
||||
raw = (proc.stdout or "").strip()
|
||||
if not raw:
|
||||
return entries
|
||||
try:
|
||||
data = json.loads(raw)
|
||||
except Exception:
|
||||
data = None
|
||||
if isinstance(data, dict):
|
||||
data = [data]
|
||||
if isinstance(data, list):
|
||||
for item in data:
|
||||
try:
|
||||
pid = int(item.get("ProcessId") or 0)
|
||||
cmdline = str(item.get("CommandLine") or "")
|
||||
except Exception:
|
||||
continue
|
||||
if pid <= 0 or not cmdline:
|
||||
continue
|
||||
if root_norm in cmdline.replace("/", "\\").lower():
|
||||
entries.append((pid, cmdline))
|
||||
else:
|
||||
proc = subprocess.run(
|
||||
["ps", "-eo", "pid=,args="],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=4,
|
||||
check=False,
|
||||
)
|
||||
for line in (proc.stdout or "").splitlines():
|
||||
s = str(line or "").strip()
|
||||
if not s:
|
||||
continue
|
||||
parts = s.split(None, 1)
|
||||
if len(parts) < 2:
|
||||
continue
|
||||
try:
|
||||
pid = int(parts[0])
|
||||
except Exception:
|
||||
continue
|
||||
cmdline = parts[1]
|
||||
low = cmdline.lower()
|
||||
if "run_cli.py" in low and root_norm in cmdline.replace("/", "\\").lower():
|
||||
entries.append((pid, cmdline))
|
||||
except Exception:
|
||||
return []
|
||||
return entries
|
||||
|
||||
def _cleanup_orphan_run_cli_processes(self, device_id: str = "") -> int:
|
||||
"""清理当前仓库遗留的 run_cli.py 进程,避免同机并发导致重复动作。"""
|
||||
try:
|
||||
with self._lock:
|
||||
tracked_pid = int(self._pid or 0)
|
||||
owned_pids = {int(x) for x in (self._owned_run_cli_pids or set())}
|
||||
except Exception:
|
||||
tracked_pid = 0
|
||||
owned_pids = set()
|
||||
current_pid = int(os.getpid() or 0)
|
||||
device_tag = str(device_id or "").strip()
|
||||
if not device_tag:
|
||||
return 0
|
||||
killed = 0
|
||||
|
||||
for pid, cmdline in self._list_project_run_cli_processes():
|
||||
if pid <= 0:
|
||||
continue
|
||||
if pid in (tracked_pid, current_pid):
|
||||
continue
|
||||
if pid not in owned_pids:
|
||||
continue
|
||||
if device_tag:
|
||||
dev1 = f"--device-id {device_tag}"
|
||||
dev2 = f'--device-id "{device_tag}"'
|
||||
if dev1 not in cmdline and dev2 not in cmdline:
|
||||
continue
|
||||
try:
|
||||
self._append_log(f"[启动清理] 发现遗留 run_cli 进程 pid={pid},准备终止")
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if os.name == "nt":
|
||||
subprocess.run(
|
||||
["taskkill", "/PID", str(pid), "/T", "/F"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=8,
|
||||
check=False,
|
||||
)
|
||||
else:
|
||||
subprocess.run(
|
||||
["kill", "-9", str(pid)],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=5,
|
||||
check=False,
|
||||
)
|
||||
killed += 1
|
||||
try:
|
||||
self._append_log(f"[启动清理] 已终止遗留 run_cli 进程 pid={pid}")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
self._append_log(f"[启动清理] 终止遗留 run_cli 进程失败 pid={pid} error={e}")
|
||||
except Exception:
|
||||
pass
|
||||
return killed
|
||||
|
||||
def get_reservations(self) -> dict:
|
||||
return _proc_ops.get_reservations(self)
|
||||
|
||||
@@ -238,7 +373,15 @@ class ProcRunner:
|
||||
with self._lock:
|
||||
self._proc = None
|
||||
self._pid = None
|
||||
if pid:
|
||||
self._owned_run_cli_pids.discard(int(pid))
|
||||
self._exit_code = self._exit_code if self._exit_code is not None else -9
|
||||
try:
|
||||
extra_killed = self._cleanup_orphan_run_cli_processes("")
|
||||
if extra_killed > 0:
|
||||
self._append_log(f"[停止] 额外清理遗留 run_cli 进程 {extra_killed} 个")
|
||||
except Exception:
|
||||
pass
|
||||
self._append_log("[停止] 强制停止完成")
|
||||
|
||||
def stop(self) -> None:
|
||||
@@ -260,6 +403,8 @@ class ProcRunner:
|
||||
try:
|
||||
self._proc = None
|
||||
self._pid = None
|
||||
if getattr(p, "pid", None):
|
||||
self._owned_run_cli_pids.discard(int(p.pid))
|
||||
except Exception:
|
||||
pass
|
||||
self._append_log("[网页] 停止:已尝试终止并清理进程引用")
|
||||
@@ -328,6 +473,14 @@ class ProcRunner:
|
||||
device_id = str(_pick("device_id", "") or "").strip()
|
||||
adb = find_adb_executable()
|
||||
device_id = resolve_adb_device(adb, device_id)
|
||||
try:
|
||||
cleaned = self._cleanup_orphan_run_cli_processes(device_id)
|
||||
if cleaned > 0:
|
||||
self._append_log(
|
||||
f"[启动清理] 已清理同设备遗留 run_cli 进程 {cleaned} 个,避免重复切房"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
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))
|
||||
@@ -513,7 +666,36 @@ class ProcRunner:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
reenter_mode = str(
|
||||
_pick("reenter_live_entry_mode", "follow_list") or "follow_list"
|
||||
).strip().lower()
|
||||
reenter_mode_source = "default"
|
||||
try:
|
||||
if (
|
||||
isinstance(params, dict)
|
||||
and params.get("reenter_live_entry_mode") is not None
|
||||
):
|
||||
reenter_mode_source = "params"
|
||||
elif isinstance(cfg, dict) and cfg.get("reenter_live_entry_mode") is not None:
|
||||
reenter_mode_source = "config"
|
||||
except Exception:
|
||||
reenter_mode_source = "default"
|
||||
if reenter_mode in ("follow_list", "screen_center"):
|
||||
cmd += ["--reenter-live-entry-mode", reenter_mode]
|
||||
|
||||
self._start_process(cmd)
|
||||
try:
|
||||
# 放在 _start_process 之后,避免被启动时日志清空逻辑抹掉
|
||||
self._append_log(
|
||||
"[WEB_DEBUG] 启动参数解析:reenter_live_entry_mode="
|
||||
f"{reenter_mode} source={reenter_mode_source}"
|
||||
)
|
||||
self._append_log(
|
||||
"[WEB_DEBUG] 启动命令检查:cmd_has_reenter_flag="
|
||||
f"{'--reenter-live-entry-mode' in cmd}"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _start_process(self, cmd: list[str]) -> None:
|
||||
# 每次启动前刷新一次日志设置
|
||||
@@ -551,6 +733,7 @@ class ProcRunner:
|
||||
with self._lock:
|
||||
self._proc = p
|
||||
self._pid = p.pid
|
||||
self._owned_run_cli_pids.add(int(p.pid))
|
||||
self._start_ts = time.time()
|
||||
self._exit_code = None
|
||||
self._last_log_ts = time.time()
|
||||
@@ -618,11 +801,18 @@ class ProcRunner:
|
||||
self._append_log(f"[网页] 进程退出:退出码={rc}")
|
||||
with self._lock:
|
||||
self._exit_code = rc
|
||||
try:
|
||||
self._proc = None
|
||||
self._pid = None
|
||||
self._owned_run_cli_pids.discard(int(p.pid))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
threading.Thread(target=_reader, daemon=True).start()
|
||||
|
||||
|
||||
RUNNER = ProcRunner()
|
||||
atexit.register(lambda: RUNNER.force_stop())
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
@@ -668,6 +858,15 @@ def main() -> int:
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
print("[WEBGUI] 收到中断,退出")
|
||||
try:
|
||||
RUNNER.force_stop()
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
httpd.server_close()
|
||||
except Exception:
|
||||
pass
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
@@ -9,11 +9,18 @@ def send_json(handler: BaseHTTPRequestHandler, obj, status: int = 200) -> None:
|
||||
handler.send_header("Cache-Control", "no-store")
|
||||
handler.send_header("Content-Length", str(len(data)))
|
||||
handler.end_headers()
|
||||
handler.wfile.write(data)
|
||||
try:
|
||||
handler.wfile.write(data)
|
||||
except (BrokenPipeError, ConnectionAbortedError, ConnectionResetError):
|
||||
# 客户端已主动断开时不应把正常断链打成服务端 traceback。
|
||||
return None
|
||||
|
||||
|
||||
def read_json(handler: BaseHTTPRequestHandler) -> dict:
|
||||
n = int(handler.headers.get("Content-Length") or 0)
|
||||
try:
|
||||
n = int(handler.headers.get("Content-Length") or 0)
|
||||
except Exception:
|
||||
n = 0
|
||||
raw = handler.rfile.read(n) if n > 0 else b"{}"
|
||||
try:
|
||||
value = json.loads(raw.decode("utf-8"))
|
||||
|
||||
@@ -25,6 +25,14 @@ _TRUE_LITERALS = {"1", "true", "yes", "y", "on"}
|
||||
_FALSE_LITERALS = {"0", "false", "no", "n", "off", ""}
|
||||
|
||||
|
||||
def _is_local_request(handler) -> bool:
|
||||
try:
|
||||
host = str((handler.client_address or ("",))[0] or "").strip()
|
||||
except Exception:
|
||||
return False
|
||||
return host in {"127.0.0.1", "::1", "localhost"}
|
||||
|
||||
|
||||
def _coerce_bool(value) -> bool:
|
||||
"""把配置输入稳健地转为 bool。
|
||||
|
||||
@@ -77,6 +85,10 @@ def _is_invalid_ports_spec(spec) -> bool:
|
||||
|
||||
def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
if u.path.startswith("/api/"):
|
||||
if not _is_local_request(handler):
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Local access only"}, status=403
|
||||
)
|
||||
api_path = u.path.rstrip("/")
|
||||
if u.path == "/api/csrf-token":
|
||||
return handler._send_json({"token": csrf_token})
|
||||
@@ -230,6 +242,10 @@ def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
return
|
||||
|
||||
if u.path.startswith("/pic/"):
|
||||
if not _is_local_request(handler):
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Local access only"}, status=403
|
||||
)
|
||||
rel = u.path.lstrip("/")
|
||||
safe = os.path.normpath(rel).replace("\\", "/")
|
||||
if not safe.startswith("pic/"):
|
||||
@@ -255,10 +271,18 @@ def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
handler.wfile.write(data)
|
||||
return
|
||||
|
||||
if not _is_local_request(handler):
|
||||
handler.send_error(HTTPStatus.FORBIDDEN)
|
||||
return
|
||||
|
||||
handler._serve_static(u.path)
|
||||
|
||||
|
||||
def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
if not _is_local_request(handler):
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Local access only"}, status=403
|
||||
)
|
||||
if handler.headers.get("X-CSRF-Token", "") != csrf_token:
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Invalid CSRF token"}, status=403
|
||||
@@ -356,6 +380,26 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
"fudai_quiet_hours_enabled",
|
||||
"high_value_fudai_enabled",
|
||||
"fudai_disable_content_recognition",
|
||||
"fudai_detail_ocr_content_enabled",
|
||||
"fudai_detail_ocr_value_enabled",
|
||||
"fudai_detail_ocr_countdown_enabled",
|
||||
"fudai_detail_ocr_task_enabled",
|
||||
"fudai_detail_ocr_task_count_enabled",
|
||||
"fudai_detail_ocr_button_enabled",
|
||||
"fudai_detail_ocr_participants_enabled",
|
||||
"fudai_detail_ocr_live_title_enabled",
|
||||
"pixel_detect_fudai_icon_enabled",
|
||||
"pixel_detect_coupon_popup_enabled",
|
||||
"pixel_detect_shopping_redpacket_enabled",
|
||||
"pixel_detect_lottery_result_enabled",
|
||||
"pixel_detect_attend_button_enabled",
|
||||
"pixel_detect_fansclub_join_enabled",
|
||||
"pixel_detect_fudai_detail_enabled",
|
||||
"pixel_detect_live_room_enabled",
|
||||
"ocr_lottery_result_enabled",
|
||||
"ocr_coupon_popup_enabled",
|
||||
"ocr_shopping_redpacket_enabled",
|
||||
"ocr_stage_page_enabled",
|
||||
"high_value_room_revisit_enabled",
|
||||
"high_value_room_revisit_only_current_run",
|
||||
"reservation_back_verify_enabled",
|
||||
@@ -397,6 +441,11 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
"yanghao_fallback_enter_live_x",
|
||||
"yanghao_fallback_enter_live_y",
|
||||
}
|
||||
enum_str_keys = {
|
||||
"reset_after_swipes_action",
|
||||
"reenter_live_entry_mode",
|
||||
"fudai_detail_ui_mode",
|
||||
}
|
||||
|
||||
def set_nested_value(obj, key, value):
|
||||
if "." in key:
|
||||
@@ -432,6 +481,18 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
set_nested_value(
|
||||
cfg, k, [str(x).strip() for x in str(v).splitlines() if str(x).strip()]
|
||||
)
|
||||
elif k in enum_str_keys:
|
||||
val = str(v or "").strip().lower()
|
||||
if k == "reset_after_swipes_action":
|
||||
if val not in ("swipe", "back"):
|
||||
continue
|
||||
if k == "reenter_live_entry_mode":
|
||||
if val not in ("follow_list", "screen_center"):
|
||||
continue
|
||||
if k == "fudai_detail_ui_mode":
|
||||
if val not in ("auto", "legacy", "v2_0"):
|
||||
continue
|
||||
set_nested_value(cfg, k, val)
|
||||
else:
|
||||
set_nested_value(cfg, k, v)
|
||||
write_config(cfg)
|
||||
@@ -535,7 +596,8 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
|
||||
last = get_last_wifi_target()
|
||||
last_target = str(last.get("target") or "")
|
||||
if last_target.startswith(ip):
|
||||
disconnect_target = ip if ":" in ip else f"{ip}:{port}"
|
||||
if last_target == disconnect_target:
|
||||
clear_last_wifi_target()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -278,9 +278,10 @@ class WebGUILauncher:
|
||||
try:
|
||||
if sys.platform == "win32":
|
||||
# 使用PowerShell命令停止旧进程
|
||||
project_root_norm = str(PROJECT_ROOT).replace("'", "''").replace("\\", "\\\\")
|
||||
ps_cmd = (
|
||||
"Get-CimInstance Win32_Process | "
|
||||
"Where-Object { ($_.CommandLine -like '*web_gui.py*') -and ($_.Name -like 'python*') } | "
|
||||
f"Where-Object {{ ($_.CommandLine -like '*web_gui.py*') -and ($_.CommandLine -like '*{project_root_norm}*') -and ($_.Name -like 'python*') }} | "
|
||||
"ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }"
|
||||
)
|
||||
subprocess.run(
|
||||
|
||||
Reference in new issue
Block a user