733 lines
33 KiB
Python
733 lines
33 KiB
Python
"""GUI 配置序列化:从 config.json 加载 → tk Vars,以及 Vars → config.json 保存。
|
|
|
|
从 ``gui/gui_app.py`` 抽出。原本是 ``main()`` 内的两个闭包
|
|
``load_config_to_ui`` 和 ``save_ui_to_config``,共依赖 122 个 tk Var 和 5 个 Text widget。
|
|
|
|
依赖通过显式参数注入:
|
|
- ``vars_`` - 一个名→Var 的 ``Dict[str, tk.Variable]``,键名与原 main() 中的变量名一致
|
|
- ``texts_`` - 一个名→Text widget 的 ``Dict[str, tk.Text]``(want_text/not_want_text 等)
|
|
- ``read_config`` - 读配置回调
|
|
- ``write_config`` - 写配置回调
|
|
- ``on_line`` - 日志回调
|
|
|
|
``load_config_to_ui`` 把 ``cfg`` 当作 nonlocal 变量原地赋值,这里改为返回新 cfg 让调用方更新。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tkinter as tk
|
|
from typing import Callable, Dict
|
|
|
|
from douyin.fudai.core.coords import FUDAI_DETAIL_REGION_DEFAULTS, PIXEL_REGION_DEFAULTS
|
|
|
|
from .config_io_helpers import (
|
|
apply_debug_captures_from_cfg,
|
|
apply_logging_from_cfg,
|
|
collect_text_lines,
|
|
populate_text_widgets,
|
|
write_debug_captures_to_cfg,
|
|
write_logging_to_cfg,
|
|
)
|
|
|
|
|
|
_REGION_CONFIG_SPECS = (
|
|
("fudai_detail_regions", "legacy", "content"),
|
|
("fudai_detail_regions", "legacy", "value"),
|
|
("fudai_detail_regions", "legacy", "countdown_full"),
|
|
("fudai_detail_regions", "legacy", "task_list"),
|
|
("fudai_detail_regions", "legacy", "task_count"),
|
|
("fudai_detail_regions", "legacy", "participants"),
|
|
("fudai_detail_regions", "legacy", "button"),
|
|
("fudai_detail_regions", "legacy", "live_title"),
|
|
("fudai_detail_regions", "v2_0_two_task", "content"),
|
|
("fudai_detail_regions", "v2_0_two_task", "value"),
|
|
("fudai_detail_regions", "v2_0_two_task", "countdown_full"),
|
|
("fudai_detail_regions", "v2_0_two_task", "task_list"),
|
|
("fudai_detail_regions", "v2_0_two_task", "task_count"),
|
|
("fudai_detail_regions", "v2_0_two_task", "participants"),
|
|
("fudai_detail_regions", "v2_0_two_task", "button"),
|
|
("fudai_detail_regions", "v2_0_two_task", "live_title"),
|
|
("fudai_detail_regions", "v2_0_one_task", "content"),
|
|
("fudai_detail_regions", "v2_0_one_task", "value"),
|
|
("fudai_detail_regions", "v2_0_one_task", "countdown_full"),
|
|
("fudai_detail_regions", "v2_0_one_task", "info_line"),
|
|
("fudai_detail_regions", "v2_0_one_task", "task_list"),
|
|
("fudai_detail_regions", "v2_0_one_task", "task_count"),
|
|
("fudai_detail_regions", "v2_0_one_task", "participants"),
|
|
("fudai_detail_regions", "v2_0_one_task", "button"),
|
|
("fudai_detail_regions", "v2_0_one_task", "live_title"),
|
|
("pixel_regions", "lottery_result", "button"),
|
|
("pixel_regions", "lottery_result", "pixel"),
|
|
("pixel_regions", "lottery_result", "click"),
|
|
("pixel_regions", "attend_button", None),
|
|
("pixel_regions", "fansclub_join", None),
|
|
("pixel_regions", "coupon_popup", None),
|
|
("pixel_regions", "shopping_redpacket", None),
|
|
("pixel_regions", "fudai_detail_body", None),
|
|
("pixel_regions", "fudai_task_status", None),
|
|
("pixel_regions", "live_room_icon_bbox", None),
|
|
)
|
|
|
|
|
|
def _deep_get(obj: dict, *parts: str):
|
|
cur = obj
|
|
for part in parts:
|
|
if not isinstance(cur, dict) or part not in cur:
|
|
return None
|
|
cur = cur[part]
|
|
return cur
|
|
|
|
|
|
def _deep_set(obj: dict, parts: tuple[str, ...], value) -> None:
|
|
cur = obj
|
|
for part in parts[:-1]:
|
|
if part not in cur or not isinstance(cur[part], dict):
|
|
cur[part] = {}
|
|
cur = cur[part]
|
|
cur[parts[-1]] = value
|
|
|
|
|
|
def _make_region_var_key(root: str, scope: str, name: str | None, axis: str) -> str:
|
|
if name:
|
|
return f"{root}_{scope}_{name}_{axis}_var"
|
|
return f"{root}_{scope}_{axis}_var"
|
|
|
|
|
|
def _default_region_values(root: str, scope: str, name: str | None) -> list[int]:
|
|
if root == "fudai_detail_regions":
|
|
source = FUDAI_DETAIL_REGION_DEFAULTS.get(scope, {})
|
|
raw = source.get(name or "", (0, 0, 0, 0)) if isinstance(source, dict) else (0, 0, 0, 0)
|
|
else:
|
|
source = PIXEL_REGION_DEFAULTS.get(scope, (0, 0, 0, 0))
|
|
if isinstance(source, dict):
|
|
raw = source.get(name or "", (0, 0, 0, 0))
|
|
else:
|
|
raw = source
|
|
try:
|
|
values = [int(v) for v in list(raw)]
|
|
except Exception:
|
|
values = [0, 0, 0, 0]
|
|
if len(values) < 4:
|
|
values = (values + [0, 0, 0, 0])[:4]
|
|
return values
|
|
|
|
|
|
def load_config_to_ui(
|
|
*,
|
|
vars_: Dict[str, tk.Variable],
|
|
texts_: Dict[str, tk.Text],
|
|
read_config: Callable[[], dict],
|
|
) -> dict:
|
|
cfg = read_config()
|
|
vars_["needswitch_var"].set(bool(cfg.get("needswitch", True)))
|
|
vars_["infinite_loop_var"].set(bool(cfg.get("infinite_loop_enabled", False)))
|
|
vars_["wait_minutes_var"].set(int(cfg.get("wait_minutes", 5) or 5))
|
|
vars_["yg_enabled_var"].set(bool(cfg.get("yanghao_enabled", True)))
|
|
vars_["yg_actions_enabled_var"].set(bool(cfg.get("yanghao_enable_actions", True)))
|
|
vars_["yg_only_var"].set(bool(cfg.get("yanghao_only", False)))
|
|
vars_["yg_recommend_duration_var"].set(
|
|
int(cfg.get("yanghao_recommend_duration_seconds", 60) or 60)
|
|
)
|
|
vars_["yg_recommend_interval_var"].set(
|
|
int(cfg.get("yanghao_recommend_interval_seconds", 0) or 0)
|
|
)
|
|
vars_["min_value_var"].set(float(cfg.get("min_prize_value_yuan", 0) or 0))
|
|
vars_["min_participants_var"].set(int(cfg.get("min_participants", 0) or 0))
|
|
vars_["max_participants_var"].set(int(cfg.get("max_participants", 0) or 0))
|
|
vars_["skip_gt_seconds_var"].set(
|
|
int(cfg.get("skip_if_countdown_gt_seconds", 900) or 900)
|
|
)
|
|
vars_["reset_after_swipes_enabled_var"].set(
|
|
bool(cfg.get("reset_after_swipes_enabled", False))
|
|
)
|
|
vars_["reset_after_swipes_var"].set(int(cfg.get("reset_after_swipes", 10) or 10))
|
|
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))
|
|
)
|
|
vars_["swipe_down_back_count_var"].set(int(cfg.get("swipe_down_back_count", 3) or 3))
|
|
vars_["auto_join_var"].set(bool(cfg.get("auto_join_fansclub", False)))
|
|
vars_["fansclub_action_var"].set(
|
|
str(cfg.get("fansclub_fail_action", "stay") or "stay").lower()
|
|
)
|
|
vars_["streaming_enabled_var"].set(bool(cfg.get("enable_streaming_screenshot", True)))
|
|
vars_["lucky_draw_red_ratio_threshold_var"].set(
|
|
float(cfg.get("lucky_draw_red_ratio_threshold", 0.9) or 0.9)
|
|
)
|
|
vars_["y_var"].set(int(cfg.get("y_pianyi", 0) or 0))
|
|
|
|
# Web端新增配置 - 高价值预约相关
|
|
vars_["high_value_fudai_enabled_var"].set(
|
|
bool(cfg.get("high_value_fudai_enabled", False))
|
|
)
|
|
vars_["high_value_fudai_threshold_yuan_var"].set(
|
|
float(cfg.get("high_value_fudai_threshold_yuan", 1000) or 1000)
|
|
)
|
|
vars_["high_value_fudai_join_ahead_seconds_var"].set(
|
|
int(cfg.get("high_value_fudai_join_ahead_seconds", 300) or 300)
|
|
)
|
|
vars_["high_value_fudai_max_swipe_back_var"].set(
|
|
int(cfg.get("high_value_fudai_max_swipe_back", 60) or 60)
|
|
)
|
|
vars_["high_value_fudai_max_reservations_var"].set(
|
|
int(cfg.get("high_value_fudai_max_reservations", 5) or 5)
|
|
)
|
|
vars_["high_value_fudai_after_action_var"].set(
|
|
str(cfg.get("high_value_fudai_after_action", "continue") or "continue")
|
|
)
|
|
vars_["high_value_fudai_poll_before_seconds_var"].set(
|
|
float(cfg.get("high_value_fudai_poll_before_seconds", 10.0) or 10.0)
|
|
)
|
|
vars_["high_value_room_revisit_enabled_var"].set(
|
|
bool(cfg.get("high_value_room_revisit_enabled", True))
|
|
)
|
|
vars_["high_value_room_revisit_only_current_run_var"].set(
|
|
bool(cfg.get("high_value_room_revisit_only_current_run", False))
|
|
)
|
|
vars_["high_value_room_revisit_min_interval_seconds_var"].set(
|
|
int(cfg.get("high_value_room_revisit_min_interval_seconds", 300))
|
|
)
|
|
vars_["high_value_room_revisit_max_per_run_var"].set(
|
|
int(cfg.get("high_value_room_revisit_max_per_run", 5))
|
|
)
|
|
vars_["high_value_room_revisit_min_prize_value_var"].set(
|
|
float(cfg.get("high_value_room_revisit_min_prize_value", 0.0))
|
|
)
|
|
vars_["high_value_room_revisit_max_age_days_var"].set(
|
|
int(cfg.get("high_value_room_revisit_max_age_days", 30))
|
|
)
|
|
vars_["reservation_back_verify_enabled_var"].set(
|
|
bool(cfg.get("reservation_back_verify_enabled", True))
|
|
)
|
|
vars_["reservation_back_swipe_delay_var"].set(
|
|
float(cfg.get("reservation_back_swipe_delay", 0) or 0)
|
|
)
|
|
vars_["reservation_back_verify_wait_seconds_var"].set(
|
|
float(cfg.get("reservation_back_verify_wait_seconds", 5.0) or 5.0)
|
|
)
|
|
vars_["fudai_find_max_attempts_var"].set(int(cfg.get("fudai_find_max_attempts", 0) or 0))
|
|
vars_["fudai_icon_retry_delay_seconds_var"].set(
|
|
float(cfg.get("fudai_icon_retry_delay_seconds", 0.6) or 0.6)
|
|
)
|
|
vars_["fudai_icon_max_wait_seconds_var"].set(
|
|
float(cfg.get("fudai_icon_max_wait_seconds", 5.0) or 5.0)
|
|
)
|
|
vars_["fudai_click_wait_seconds_var"].set(
|
|
float(cfg.get("fudai_click_wait_seconds", 1.0) or 1.0)
|
|
)
|
|
vars_["fudai_disable_content_recognition_var"].set(
|
|
bool(cfg.get("fudai_disable_content_recognition", False))
|
|
)
|
|
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")
|
|
)
|
|
vars_["fudai_detail_save_debug_images_var"].set(
|
|
bool(cfg.get("fudai_detail_save_debug_images", False))
|
|
)
|
|
vars_["region_coords_edit_enabled_var"].set(
|
|
bool(cfg.get("region_coords_edit_enabled", False))
|
|
)
|
|
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": False,
|
|
}.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)
|
|
)
|
|
except Exception:
|
|
vars_["fudai_exit_after_misses_var"].set(30)
|
|
try:
|
|
vars_["enable_back_on_misses_var"].set(bool(cfg.get("enable_back_on_misses", True)))
|
|
except Exception:
|
|
vars_["enable_back_on_misses_var"].set(True)
|
|
try:
|
|
vars_["reset_after_swipes_action_var"].set(
|
|
str(cfg.get("reset_after_swipes_action", "swipe"))
|
|
)
|
|
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)
|
|
)
|
|
# GUI 主题
|
|
try:
|
|
vars_["gui_theme_var"].set(
|
|
str(cfg.get("gui", {}).get("theme", "litera") or "litera")
|
|
)
|
|
except Exception:
|
|
vars_["gui_theme_var"].set("litera")
|
|
vars_["live_room_match_threshold_var"].set(
|
|
float(cfg.get("live_room_match_threshold", 0.8) or 0.8)
|
|
)
|
|
vars_["swipe_duration_ms_var"].set(int(cfg.get("swipe_duration_ms", 600) or 600))
|
|
vars_["swipe_up_start_y_var"].set(int(cfg.get("swipe_up_start_y", 1200) or 1200))
|
|
vars_["swipe_up_end_y_var"].set(int(cfg.get("swipe_up_end_y", 600) or 600))
|
|
vars_["fudai_quiet_hours_enabled_var"].set(
|
|
bool(cfg.get("fudai_quiet_hours_enabled", True))
|
|
)
|
|
vars_["fudai_quiet_start_hour_var"].set(int(cfg.get("fudai_quiet_start_hour", 2) or 2))
|
|
vars_["fudai_quiet_end_hour_var"].set(int(cfg.get("fudai_quiet_end_hour", 7) or 7))
|
|
vars_["stage_diag_max_time_var"].set(float(cfg.get("stage_diag_max_time", 10.0) or 10.0))
|
|
vars_["stage_diag_max_step_time_var"].set(
|
|
float(cfg.get("stage_diag_max_step_time", 2.0) or 2.0)
|
|
)
|
|
vars_["stage_diag_verbose_var"].set(
|
|
bool(cfg.get("logging", {}).get("stage_diag_verbose", False))
|
|
)
|
|
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))
|
|
)
|
|
vars_["fudai_template_match_threshold_var"].set(
|
|
float(cfg.get("fudai_template_match_threshold", 0.7) or 0.7)
|
|
)
|
|
vars_["fudai_detail_template_threshold_var"].set(
|
|
float(cfg.get("fudai_detail_template_threshold", 0.7) or 0.7)
|
|
)
|
|
vars_["coupon_template_match_threshold_var"].set(
|
|
float(cfg.get("coupon_template_match_threshold", 0.75) or 0.75)
|
|
)
|
|
vars_["attend_button_red_ratio_threshold_var"].set(
|
|
float(cfg.get("attend_button_red_ratio_threshold", 0.25) or 0.25)
|
|
)
|
|
vars_["fansclub_join_red_ratio_threshold_var"].set(
|
|
float(cfg.get("fansclub_join_red_ratio_threshold", 0.25) or 0.25)
|
|
)
|
|
vars_["shopping_redpacket_red_ratio_threshold_var"].set(
|
|
float(cfg.get("shopping_redpacket_red_ratio_threshold", 0.15) or 0.15)
|
|
)
|
|
vars_["fudai_detail_body_bluepurple_threshold_var"].set(
|
|
float(cfg.get("fudai_detail_body_bluepurple_threshold", 0.45) or 0.45)
|
|
)
|
|
vars_["fudai_detail_body_dark_threshold_var"].set(
|
|
float(cfg.get("fudai_detail_body_dark_threshold", 0.35) or 0.35)
|
|
)
|
|
vars_["fudai_task_status_template_threshold_var"].set(
|
|
float(cfg.get("fudai_task_status_template_threshold", 0.26) or 0.26)
|
|
)
|
|
# 粉丝团等待/点击延迟配置
|
|
vars_["fansclub_click_delay_var"].set(float(cfg.get("fansclub_click_delay", 0.6) or 0.6))
|
|
vars_["fansclub_auto_wait_var"].set(
|
|
float(cfg.get("fansclub_auto_join_wait_seconds", 5.0) or 5.0)
|
|
)
|
|
vars_["fansclub_manual_wait_var"].set(
|
|
float(cfg.get("fansclub_manual_wait_seconds", 3.0) or 3.0)
|
|
)
|
|
vars_["skip_lt_seconds_var"].set(int(cfg.get("skip_if_countdown_lt_seconds", 10) or 10))
|
|
for root, scope, name in _REGION_CONFIG_SPECS:
|
|
raw = _deep_get(cfg, root, scope, name) if name else _deep_get(cfg, root, scope)
|
|
values = list(raw) if isinstance(raw, (list, tuple)) else _default_region_values(root, scope, name)
|
|
if len(values) < 4:
|
|
values = _default_region_values(root, scope, name)
|
|
for idx, axis in enumerate(("x1", "y1", "x2", "y2")):
|
|
vars_[_make_region_var_key(root, scope, name, axis)].set(int(values[idx] or 0))
|
|
|
|
apply_debug_captures_from_cfg(vars_, cfg)
|
|
apply_logging_from_cfg(vars_, cfg)
|
|
|
|
vars_["yg_like_prob_var"].set(float(cfg.get("yanghao_like_prob", 0.0) or 0.0))
|
|
vars_["yg_fav_prob_var"].set(float(cfg.get("yanghao_fav_prob", 0.0) or 0.0))
|
|
vars_["yg_comment_prob_var"].set(float(cfg.get("yanghao_comment_prob", 0.0) or 0.0))
|
|
vars_["yg_dwell_on_action_min_var"].set(
|
|
float(cfg.get("yanghao_dwell_on_action_min_seconds", 5) or 5)
|
|
)
|
|
vars_["yg_dwell_on_action_max_var"].set(
|
|
float(cfg.get("yanghao_dwell_on_action_max_seconds", 30) or 30)
|
|
)
|
|
vars_["yg_icon_roi_size_var"].set(int(cfg.get("yanghao_icon_roi_size", 240) or 240))
|
|
vars_["yg_icon_match_threshold_var"].set(
|
|
float(cfg.get("yanghao_icon_match_threshold", 0.72) or 0.72)
|
|
)
|
|
vars_["yg_step_screenshot_var"].set(bool(cfg.get("yanghao_step_screenshot", False)))
|
|
vars_["yg_like_roi_offset_x_var"].set(int(cfg.get("yanghao_like_roi_offset_x", 0) or 0))
|
|
vars_["yg_like_roi_offset_y_var"].set(int(cfg.get("yanghao_like_roi_offset_y", 0) or 0))
|
|
vars_["yg_fav_roi_offset_x_var"].set(int(cfg.get("yanghao_fav_roi_offset_x", 0) or 0))
|
|
vars_["yg_fav_roi_offset_y_var"].set(int(cfg.get("yanghao_fav_roi_offset_y", 0) or 0))
|
|
vars_["yg_like_icon_x_var"].set(int(cfg.get("yanghao_like_icon_x", 0) or 0))
|
|
vars_["yg_like_icon_y_var"].set(int(cfg.get("yanghao_like_icon_y", 0) or 0))
|
|
vars_["yg_fav_icon_x_var"].set(int(cfg.get("yanghao_fav_icon_x", 0) or 0))
|
|
vars_["yg_fav_icon_y_var"].set(int(cfg.get("yanghao_fav_icon_y", 0) or 0))
|
|
vars_["yg_like_template_path_var"].set(
|
|
str(
|
|
cfg.get("yanghao_like_template_path", "assets/like.png")
|
|
or "assets/like.png"
|
|
)
|
|
)
|
|
vars_["yg_fav_template_path_var"].set(
|
|
str(
|
|
cfg.get("yanghao_fav_template_path", "assets/fav.png")
|
|
or "assets/fav.png"
|
|
)
|
|
)
|
|
vars_["yg_after_dwell_direction_var"].set(
|
|
str(cfg.get("yanghao_after_dwell_swipe_direction", "up") or "up")
|
|
)
|
|
vars_["yg_after_dwell_distance_var"].set(
|
|
int(cfg.get("yanghao_after_dwell_swipe_distance_px", 900) or 900)
|
|
)
|
|
vars_["yg_comment_btn_x_var"].set(int(cfg.get("yanghao_comment_btn_x", 0) or 0))
|
|
vars_["yg_comment_btn_y_var"].set(int(cfg.get("yanghao_comment_btn_y", 0) or 0))
|
|
vars_["yg_comment_input_x_var"].set(int(cfg.get("yanghao_comment_input_x", 0) or 0))
|
|
vars_["yg_comment_input_y_var"].set(int(cfg.get("yanghao_comment_input_y", 0) or 0))
|
|
vars_["yg_comment_send_x_var"].set(int(cfg.get("yanghao_comment_send_x", 0) or 0))
|
|
vars_["yg_comment_send_y_var"].set(int(cfg.get("yanghao_comment_send_y", 0) or 0))
|
|
vars_["yg_comment_close_x_var"].set(int(cfg.get("yanghao_comment_close_x", 0) or 0))
|
|
vars_["yg_comment_close_y_var"].set(int(cfg.get("yanghao_comment_close_y", 0) or 0))
|
|
|
|
# 仅保留黑名单 contains_not_want
|
|
want = cfg.get("contains_want", []) or []
|
|
not_want = cfg.get("contains_not_want", []) or []
|
|
yg_comment_texts_list = cfg.get("yanghao_comment_texts", []) or []
|
|
yg_like_keywords_list = cfg.get("yanghao_like_keywords", []) or []
|
|
yg_fav_keywords_list = cfg.get("yanghao_fav_keywords", []) or []
|
|
populate_text_widgets(
|
|
texts_,
|
|
want,
|
|
not_want,
|
|
yg_comment_texts_list,
|
|
yg_like_keywords_list,
|
|
yg_fav_keywords_list,
|
|
)
|
|
|
|
return cfg
|
|
|
|
|
|
def save_ui_to_config(
|
|
*,
|
|
vars_: Dict[str, tk.Variable],
|
|
texts_: Dict[str, tk.Text],
|
|
cfg: dict,
|
|
read_config: Callable[[], dict],
|
|
write_config: Callable[[dict], None],
|
|
on_line: Callable[[str], None],
|
|
) -> None:
|
|
(
|
|
want_lines,
|
|
not_want_lines,
|
|
yg_comment_text_lines,
|
|
yg_like_kw_lines,
|
|
yg_fav_kw_lines,
|
|
) = collect_text_lines(texts_)
|
|
|
|
cfg2 = read_config()
|
|
cfg2["needswitch"] = bool(vars_["needswitch_var"].get())
|
|
cfg2["infinite_loop_enabled"] = bool(vars_["infinite_loop_var"].get())
|
|
cfg2["wait_minutes"] = int(vars_["wait_minutes_var"].get() or 5)
|
|
cfg2["y_pianyi"] = int(vars_["y_var"].get() or 0)
|
|
cfg2["contains_want"] = want_lines
|
|
cfg2["contains_not_want"] = not_want_lines
|
|
cfg2["min_prize_value_yuan"] = float(vars_["min_value_var"].get() or 0)
|
|
cfg2["min_participants"] = int(vars_["min_participants_var"].get() or 0)
|
|
cfg2["max_participants"] = int(vars_["max_participants_var"].get() or 0)
|
|
cfg2["skip_if_countdown_gt_seconds"] = int(vars_["skip_gt_seconds_var"].get() or 900)
|
|
cfg2["reset_after_swipes_enabled"] = bool(vars_["reset_after_swipes_enabled_var"].get())
|
|
cfg2["reset_after_swipes"] = int(vars_["reset_after_swipes_var"].get() or 10)
|
|
cfg2["auto_join_fansclub"] = bool(vars_["auto_join_var"].get())
|
|
cfg2["fansclub_fail_action"] = str(vars_["fansclub_action_var"].get() or "stay").lower()
|
|
cfg2["lucky_draw_red_ratio_threshold"] = float(
|
|
vars_["lucky_draw_red_ratio_threshold_var"].get() or 0.9
|
|
)
|
|
|
|
# Web端新增配置 - 高价值预约相关
|
|
cfg2["high_value_fudai_enabled"] = bool(vars_["high_value_fudai_enabled_var"].get())
|
|
cfg2["high_value_fudai_threshold_yuan"] = float(
|
|
vars_["high_value_fudai_threshold_yuan_var"].get() or 1000
|
|
)
|
|
cfg2["high_value_fudai_join_ahead_seconds"] = int(
|
|
vars_["high_value_fudai_join_ahead_seconds_var"].get() or 300
|
|
)
|
|
cfg2["high_value_fudai_max_swipe_back"] = int(
|
|
vars_["high_value_fudai_max_swipe_back_var"].get() or 60
|
|
)
|
|
cfg2["high_value_fudai_max_reservations"] = int(
|
|
vars_["high_value_fudai_max_reservations_var"].get() or 5
|
|
)
|
|
cfg2["high_value_fudai_after_action"] = str(
|
|
vars_["high_value_fudai_after_action_var"].get() or "continue"
|
|
).lower()
|
|
cfg2["high_value_fudai_poll_before_seconds"] = float(
|
|
vars_["high_value_fudai_poll_before_seconds_var"].get() or 10.0
|
|
)
|
|
cfg2["high_value_room_revisit_enabled"] = bool(
|
|
vars_["high_value_room_revisit_enabled_var"].get()
|
|
)
|
|
cfg2["high_value_room_revisit_only_current_run"] = bool(
|
|
vars_["high_value_room_revisit_only_current_run_var"].get()
|
|
)
|
|
cfg2["high_value_room_revisit_min_interval_seconds"] = int(
|
|
vars_["high_value_room_revisit_min_interval_seconds_var"].get()
|
|
)
|
|
cfg2["high_value_room_revisit_max_per_run"] = int(
|
|
vars_["high_value_room_revisit_max_per_run_var"].get()
|
|
)
|
|
cfg2["high_value_room_revisit_min_prize_value"] = float(
|
|
vars_["high_value_room_revisit_min_prize_value_var"].get()
|
|
)
|
|
cfg2["high_value_room_revisit_max_age_days"] = int(
|
|
vars_["high_value_room_revisit_max_age_days_var"].get()
|
|
)
|
|
cfg2["reservation_back_verify_enabled"] = bool(
|
|
vars_["reservation_back_verify_enabled_var"].get()
|
|
)
|
|
cfg2["reservation_back_swipe_delay"] = float(
|
|
vars_["reservation_back_swipe_delay_var"].get() or 0
|
|
)
|
|
cfg2["reservation_back_verify_wait_seconds"] = float(
|
|
vars_["reservation_back_verify_wait_seconds_var"].get() or 5.0
|
|
)
|
|
cfg2["fudai_find_max_attempts"] = int(vars_["fudai_find_max_attempts_var"].get() or 0)
|
|
cfg2["fudai_icon_retry_delay_seconds"] = float(
|
|
vars_["fudai_icon_retry_delay_seconds_var"].get() or 0.6
|
|
)
|
|
cfg2["fudai_icon_max_wait_seconds"] = float(
|
|
vars_["fudai_icon_max_wait_seconds_var"].get() or 5.0
|
|
)
|
|
cfg2["fudai_click_wait_seconds"] = float(
|
|
vars_["fudai_click_wait_seconds_var"].get() or 2.0
|
|
)
|
|
cfg2["fudai_exit_after_misses"] = int(vars_["fudai_exit_after_misses_var"].get() or 30)
|
|
cfg2["enable_back_on_misses"] = bool(vars_["enable_back_on_misses_var"].get())
|
|
cfg2["swipe_down_back_enabled"] = bool(vars_["swipe_down_back_enabled_var"].get())
|
|
cfg2["swipe_down_back_count"] = int(vars_["swipe_down_back_count_var"].get() or 3)
|
|
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"
|
|
cfg2["fudai_detail_save_debug_images"] = bool(
|
|
vars_["fudai_detail_save_debug_images_var"].get()
|
|
)
|
|
cfg2["region_coords_edit_enabled"] = bool(
|
|
vars_["region_coords_edit_enabled_var"].get()
|
|
)
|
|
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
|
|
)
|
|
cfg2["live_room_match_threshold"] = float(
|
|
vars_["live_room_match_threshold_var"].get() or 0.8
|
|
)
|
|
cfg2["swipe_duration_ms"] = int(vars_["swipe_duration_ms_var"].get() or 600)
|
|
cfg2["swipe_up_start_y"] = int(vars_["swipe_up_start_y_var"].get() or 1200)
|
|
cfg2["swipe_up_end_y"] = int(vars_["swipe_up_end_y_var"].get() or 600)
|
|
cfg2["fudai_quiet_hours_enabled"] = bool(vars_["fudai_quiet_hours_enabled_var"].get())
|
|
cfg2["fudai_quiet_start_hour"] = int(vars_["fudai_quiet_start_hour_var"].get() or 0)
|
|
cfg2["fudai_quiet_end_hour"] = int(vars_["fudai_quiet_end_hour_var"].get() or 0)
|
|
cfg2["stage_diag_max_time"] = float(vars_["stage_diag_max_time_var"].get() or 10.0)
|
|
cfg2["stage_diag_max_step_time"] = float(
|
|
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()
|
|
)
|
|
cfg2["fudai_template_match_threshold"] = float(
|
|
vars_["fudai_template_match_threshold_var"].get() or 0.7
|
|
)
|
|
cfg2["fudai_detail_template_threshold"] = float(
|
|
vars_["fudai_detail_template_threshold_var"].get() or 0.7
|
|
)
|
|
cfg2["coupon_template_match_threshold"] = float(
|
|
vars_["coupon_template_match_threshold_var"].get() or 0.75
|
|
)
|
|
cfg2["attend_button_red_ratio_threshold"] = float(
|
|
vars_["attend_button_red_ratio_threshold_var"].get() or 0.25
|
|
)
|
|
cfg2["fansclub_join_red_ratio_threshold"] = float(
|
|
vars_["fansclub_join_red_ratio_threshold_var"].get() or 0.25
|
|
)
|
|
cfg2["shopping_redpacket_red_ratio_threshold"] = float(
|
|
vars_["shopping_redpacket_red_ratio_threshold_var"].get() or 0.15
|
|
)
|
|
cfg2["fudai_detail_body_bluepurple_threshold"] = float(
|
|
vars_["fudai_detail_body_bluepurple_threshold_var"].get() or 0.45
|
|
)
|
|
cfg2["fudai_detail_body_dark_threshold"] = float(
|
|
vars_["fudai_detail_body_dark_threshold_var"].get() or 0.35
|
|
)
|
|
cfg2["fudai_task_status_template_threshold"] = float(
|
|
vars_["fudai_task_status_template_threshold_var"].get() or 0.26
|
|
)
|
|
# 粉丝团等待/点击延迟配置
|
|
cfg2["fansclub_click_delay"] = float(vars_["fansclub_click_delay_var"].get() or 0.6)
|
|
cfg2["fansclub_auto_join_wait_seconds"] = float(
|
|
vars_["fansclub_auto_wait_var"].get() or 5.0
|
|
)
|
|
cfg2["fansclub_manual_wait_seconds"] = float(
|
|
vars_["fansclub_manual_wait_var"].get() or 3.0
|
|
)
|
|
cfg2["skip_if_countdown_lt_seconds"] = int(vars_["skip_lt_seconds_var"].get() or 10)
|
|
for root, scope, name in _REGION_CONFIG_SPECS:
|
|
values = [
|
|
int(vars_[_make_region_var_key(root, scope, name, axis)].get() or 0)
|
|
for axis in ("x1", "y1", "x2", "y2")
|
|
]
|
|
target_parts = (root, scope, name) if name else (root, scope)
|
|
_deep_set(cfg2, target_parts, values)
|
|
|
|
write_debug_captures_to_cfg(cfg2, vars_)
|
|
write_logging_to_cfg(cfg2, vars_)
|
|
|
|
cfg2["yanghao_enabled"] = bool(vars_["yg_enabled_var"].get())
|
|
cfg2["yanghao_enable_actions"] = bool(vars_["yg_actions_enabled_var"].get())
|
|
cfg2["yanghao_only"] = bool(vars_["yg_only_var"].get())
|
|
cfg2["yanghao_recommend_duration_seconds"] = int(
|
|
vars_["yg_recommend_duration_var"].get() or 60
|
|
)
|
|
cfg2["yanghao_recommend_interval_seconds"] = int(
|
|
vars_["yg_recommend_interval_var"].get() or 0
|
|
)
|
|
cfg2["yanghao_like_prob"] = float(vars_["yg_like_prob_var"].get() or 0.0)
|
|
cfg2["yanghao_fav_prob"] = float(vars_["yg_fav_prob_var"].get() or 0.0)
|
|
cfg2["yanghao_comment_prob"] = float(vars_["yg_comment_prob_var"].get() or 0.0)
|
|
cfg2["yanghao_dwell_on_action_min_seconds"] = float(
|
|
vars_["yg_dwell_on_action_min_var"].get() or 5
|
|
)
|
|
cfg2["yanghao_dwell_on_action_max_seconds"] = float(
|
|
vars_["yg_dwell_on_action_max_var"].get() or 30
|
|
)
|
|
cfg2["yanghao_icon_roi_size"] = int(vars_["yg_icon_roi_size_var"].get() or 240)
|
|
cfg2["yanghao_icon_match_threshold"] = float(
|
|
vars_["yg_icon_match_threshold_var"].get() or 0.72
|
|
)
|
|
cfg2["yanghao_step_screenshot"] = bool(vars_["yg_step_screenshot_var"].get())
|
|
cfg2["yanghao_like_roi_offset_x"] = int(vars_["yg_like_roi_offset_x_var"].get() or 0)
|
|
cfg2["yanghao_like_roi_offset_y"] = int(vars_["yg_like_roi_offset_y_var"].get() or 0)
|
|
cfg2["yanghao_fav_roi_offset_x"] = int(vars_["yg_fav_roi_offset_x_var"].get() or 0)
|
|
cfg2["yanghao_fav_roi_offset_y"] = int(vars_["yg_fav_roi_offset_y_var"].get() or 0)
|
|
cfg2["yanghao_like_icon_x"] = int(vars_["yg_like_icon_x_var"].get() or 0)
|
|
cfg2["yanghao_like_icon_y"] = int(vars_["yg_like_icon_y_var"].get() or 0)
|
|
cfg2["yanghao_fav_icon_x"] = int(vars_["yg_fav_icon_x_var"].get() or 0)
|
|
cfg2["yanghao_fav_icon_y"] = int(vars_["yg_fav_icon_y_var"].get() or 0)
|
|
cfg2["yanghao_like_template_path"] = str(
|
|
vars_["yg_like_template_path_var"].get() or "assets/like.png"
|
|
)
|
|
cfg2["yanghao_fav_template_path"] = str(
|
|
vars_["yg_fav_template_path_var"].get() or "assets/fav.png"
|
|
)
|
|
cfg2["yanghao_after_dwell_swipe_direction"] = str(
|
|
vars_["yg_after_dwell_direction_var"].get() or "up"
|
|
)
|
|
cfg2["yanghao_after_dwell_swipe_distance_px"] = int(
|
|
vars_["yg_after_dwell_distance_var"].get() or 900
|
|
)
|
|
cfg2["yanghao_comment_btn_x"] = int(vars_["yg_comment_btn_x_var"].get() or 0)
|
|
cfg2["yanghao_comment_btn_y"] = int(vars_["yg_comment_btn_y_var"].get() or 0)
|
|
cfg2["yanghao_comment_input_x"] = int(vars_["yg_comment_input_x_var"].get() or 0)
|
|
cfg2["yanghao_comment_input_y"] = int(vars_["yg_comment_input_y_var"].get() or 0)
|
|
cfg2["yanghao_comment_send_x"] = int(vars_["yg_comment_send_x_var"].get() or 0)
|
|
cfg2["yanghao_comment_send_y"] = int(vars_["yg_comment_send_y_var"].get() or 0)
|
|
cfg2["yanghao_comment_close_x"] = int(vars_["yg_comment_close_x_var"].get() or 0)
|
|
cfg2["yanghao_comment_close_y"] = int(vars_["yg_comment_close_y_var"].get() or 0)
|
|
cfg2["yanghao_comment_texts"] = yg_comment_text_lines
|
|
cfg2["yanghao_like_keywords"] = yg_like_kw_lines
|
|
cfg2["yanghao_fav_keywords"] = yg_fav_kw_lines
|
|
|
|
# 流式后台截图配置
|
|
cfg2["enable_streaming_screenshot"] = bool(vars_["streaming_enabled_var"].get())
|
|
|
|
# GUI 配置
|
|
if "gui" not in cfg2 or not isinstance(cfg2["gui"], dict):
|
|
cfg2["gui"] = {}
|
|
cfg2["gui"]["theme"] = str(vars_["gui_theme_var"].get() or "litera")
|
|
cfg2["gui"]["realtime_status"] = {
|
|
"refresh_interval_ms": int(
|
|
vars_["gui_realtime_refresh_interval_ms_var"].get() or 1000
|
|
),
|
|
"tail_items": int(vars_["gui_realtime_tail_items_var"].get() or 50),
|
|
}
|
|
# Keep an explicit assignment for sync checker parity with load_config_to_ui.
|
|
cfg2["logging"]["stage_diag_verbose"] = bool(vars_["stage_diag_verbose_var"].get())
|
|
|
|
write_config(cfg2)
|
|
on_line("[配置] 已保存到 config.json")
|
|
# 如果用户关闭了流式后台截图,尝试停止正在运行的服务实例以立即生效
|
|
try:
|
|
from operations.screenshot_service import ScreenshotService
|
|
|
|
if not bool(cfg2.get("enable_streaming_screenshot", True)):
|
|
try:
|
|
ScreenshotService.get_instance().stop()
|
|
on_line("[截图服务] 已停止后台流式截图(配置更新)")
|
|
except Exception:
|
|
on_line("[截图服务] 停止后台截图服务失败(请重启程序以确保生效)")
|
|
except Exception:
|
|
# ignore if service module not available
|
|
pass
|
|
|