679 lines
31 KiB
Python
679 lines
31 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
|
|
|
|
|
|
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")
|
|
)
|
|
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))
|
|
)
|
|
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")
|
|
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", True))
|
|
)
|
|
vars_["enable_ocr_mode1_var"].set(bool(cfg.get("enable_ocr_mode1", False)))
|
|
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_["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))
|
|
|
|
# 调试图像清理配置
|
|
debug_captures_config = cfg.get("debug_captures", {})
|
|
if isinstance(debug_captures_config, dict):
|
|
vars_["debug_captures_enabled_var"].set(
|
|
bool(debug_captures_config.get("enabled", False))
|
|
)
|
|
vars_["debug_captures_auto_cleanup_var"].set(
|
|
bool(debug_captures_config.get("auto_cleanup", True))
|
|
)
|
|
vars_["debug_captures_keep_days_var"].set(
|
|
int(debug_captures_config.get("keep_days", 7) or 7)
|
|
)
|
|
vars_["debug_captures_max_files_var"].set(
|
|
int(debug_captures_config.get("max_files", 2000) or 2000)
|
|
)
|
|
vars_["debug_captures_async_save_var"].set(
|
|
bool(debug_captures_config.get("async_save", True))
|
|
)
|
|
vars_["debug_captures_log_on_complete_var"].set(
|
|
bool(debug_captures_config.get("log_on_complete", False))
|
|
)
|
|
else:
|
|
vars_["debug_captures_auto_cleanup_var"].set(True)
|
|
vars_["debug_captures_keep_days_var"].set(7)
|
|
vars_["debug_captures_max_files_var"].set(2000)
|
|
|
|
# 日志配置(load_config_to_ui 需要覆盖 UI 变量,避免“保存后再加载不生效”)
|
|
logging_config = cfg.get("logging", {})
|
|
if isinstance(logging_config, dict):
|
|
vars_["logging_beautify_var"].set(bool(logging_config.get("beautify_output", True)))
|
|
vars_["logging_color_var"].set(bool(logging_config.get("color_output", True)))
|
|
vars_["logging_show_timestamps_var"].set(
|
|
bool(logging_config.get("show_timestamps", True))
|
|
)
|
|
vars_["logging_use_dated_logs_var"].set(
|
|
bool(logging_config.get("use_dated_logs", True))
|
|
)
|
|
vars_["logging_enable_monitor_var"].set(
|
|
bool(logging_config.get("enable_monitor", True))
|
|
)
|
|
vars_["log_unified_enabled_var"].set(bool(cfg.get("log_unified_enabled", True)))
|
|
vars_["log_unified_path_var"].set(
|
|
str(cfg.get("log_unified_path", "logs/unified.log") or "logs/unified.log")
|
|
)
|
|
vars_["logging_keep_days_var"].set(int(logging_config.get("keep_days", 30) or 30))
|
|
vars_["logging_compress_logs_var"].set(
|
|
bool(logging_config.get("compress_logs", True))
|
|
)
|
|
vars_["logging_max_total_size_gb_var"].set(
|
|
float(logging_config.get("max_total_size_gb", 10.0) or 10.0)
|
|
)
|
|
vars_["logging_compress_after_days_var"].set(
|
|
int(logging_config.get("compress_after_days", 7) or 7)
|
|
)
|
|
vars_["logging_debug_level_var"].set(
|
|
str(logging_config.get("debug_detail_level", "normal") or "normal")
|
|
)
|
|
vars_["logging_error_level_var"].set(
|
|
str(logging_config.get("error_detail_level", "full") or "full")
|
|
)
|
|
vars_["logging_action_format_var"].set(
|
|
str(logging_config.get("action_log_format", "concise") or "concise")
|
|
)
|
|
vars_["logging_format_mode_var"].set(
|
|
str(logging_config.get("log_format_mode", "simple") or "simple")
|
|
)
|
|
perf_cfg = logging_config.get("performance_tracking", {})
|
|
if isinstance(perf_cfg, dict):
|
|
vars_["logging_performance_enabled_var"].set(bool(perf_cfg.get("enabled", True)))
|
|
vars_["logging_track_functions_var"].set(
|
|
bool(perf_cfg.get("track_function_calls", True))
|
|
)
|
|
vars_["logging_monitor_warning_mb_var"].set(
|
|
float(logging_config.get("monitor_warning_mb", 500.0) or 500.0)
|
|
)
|
|
vars_["logging_monitor_critical_mb_var"].set(
|
|
float(logging_config.get("monitor_critical_mb", 2000.0) or 2000.0)
|
|
)
|
|
|
|
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 []
|
|
texts_["want_text"].delete("1.0", "end")
|
|
texts_["want_text"].insert("1.0", "\n".join(want))
|
|
texts_["not_want_text"].delete("1.0", "end")
|
|
texts_["not_want_text"].insert("1.0", "\n".join(not_want))
|
|
texts_["yg_comment_texts"].delete("1.0", "end")
|
|
texts_["yg_comment_texts"].insert("1.0", "\n".join(yg_comment_texts_list))
|
|
texts_["yg_like_keywords_text"].delete("1.0", "end")
|
|
texts_["yg_like_keywords_text"].insert("1.0", "\n".join(yg_like_keywords_list))
|
|
texts_["yg_fav_keywords_text"].delete("1.0", "end")
|
|
texts_["yg_fav_keywords_text"].insert("1.0", "\n".join(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 = [
|
|
x.strip() for x in texts_["want_text"].get("1.0", "end").splitlines() if x.strip()
|
|
]
|
|
not_want_lines = [
|
|
x.strip() for x in texts_["not_want_text"].get("1.0", "end").splitlines() if x.strip()
|
|
]
|
|
yg_comment_text_lines = [
|
|
x.strip()
|
|
for x in texts_["yg_comment_texts"].get("1.0", "end").splitlines()
|
|
if x.strip()
|
|
]
|
|
yg_like_kw_lines = [
|
|
x.strip()
|
|
for x in texts_["yg_like_keywords_text"].get("1.0", "end").splitlines()
|
|
if x.strip()
|
|
]
|
|
yg_fav_kw_lines = [
|
|
x.strip()
|
|
for x in texts_["yg_fav_keywords_text"].get("1.0", "end").splitlines()
|
|
if x.strip()
|
|
]
|
|
|
|
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["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()
|
|
)
|
|
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(cfg.get("enable_ocr_mode1", False))
|
|
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["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)
|
|
|
|
# 调试图像清理配置
|
|
if "debug_captures" not in cfg2 or not isinstance(cfg2["debug_captures"], dict):
|
|
cfg2["debug_captures"] = {}
|
|
cfg2["debug_captures"]["enabled"] = bool(vars_["debug_captures_enabled_var"].get())
|
|
cfg2["debug_captures"]["auto_cleanup"] = bool(
|
|
vars_["debug_captures_auto_cleanup_var"].get()
|
|
)
|
|
cfg2["debug_captures"]["keep_days"] = int(
|
|
vars_["debug_captures_keep_days_var"].get() or 7
|
|
)
|
|
cfg2["debug_captures"]["max_files"] = int(
|
|
vars_["debug_captures_max_files_var"].get() or 2000
|
|
)
|
|
cfg2["debug_captures"]["async_save"] = bool(vars_["debug_captures_async_save_var"].get())
|
|
cfg2["debug_captures"]["log_on_complete"] = bool(
|
|
vars_["debug_captures_log_on_complete_var"].get()
|
|
)
|
|
|
|
# 日志配置
|
|
if "logging" not in cfg2 or not isinstance(cfg2["logging"], dict):
|
|
cfg2["logging"] = {}
|
|
cfg2["logging"]["beautify_output"] = bool(vars_["logging_beautify_var"].get())
|
|
cfg2["logging"]["color_output"] = bool(vars_["logging_color_var"].get())
|
|
cfg2["logging"]["show_timestamps"] = bool(vars_["logging_show_timestamps_var"].get())
|
|
cfg2["logging"]["use_dated_logs"] = bool(vars_["logging_use_dated_logs_var"].get())
|
|
cfg2["logging"]["enable_monitor"] = bool(vars_["logging_enable_monitor_var"].get())
|
|
cfg2["logging"]["keep_days"] = int(vars_["logging_keep_days_var"].get() or 30)
|
|
cfg2["logging"]["compress_logs"] = bool(vars_["logging_compress_logs_var"].get())
|
|
cfg2["logging"]["max_total_size_gb"] = float(
|
|
vars_["logging_max_total_size_gb_var"].get() or 10.0
|
|
)
|
|
cfg2["logging"]["compress_after_days"] = int(
|
|
vars_["logging_compress_after_days_var"].get() or 7
|
|
)
|
|
cfg2["logging"]["debug_detail_level"] = str(
|
|
vars_["logging_debug_level_var"].get() or "normal"
|
|
)
|
|
cfg2["logging"]["error_detail_level"] = str(
|
|
vars_["logging_error_level_var"].get() or "full"
|
|
)
|
|
cfg2["logging"]["action_log_format"] = str(
|
|
vars_["logging_action_format_var"].get() or "concise"
|
|
)
|
|
cfg2["logging"]["log_format_mode"] = str(
|
|
vars_["logging_format_mode_var"].get() or "simple"
|
|
)
|
|
cfg2["logging"]["stage_diag_verbose"] = bool(vars_["stage_diag_verbose_var"].get())
|
|
cfg2["logging"]["monitor_warning_mb"] = float(
|
|
vars_["logging_monitor_warning_mb_var"].get() or 500.0
|
|
)
|
|
cfg2["logging"]["monitor_critical_mb"] = float(
|
|
vars_["logging_monitor_critical_mb_var"].get() or 2000.0
|
|
)
|
|
|
|
# 性能追踪配置
|
|
if "performance_tracking" not in cfg2["logging"] or not isinstance(
|
|
cfg2["logging"]["performance_tracking"], dict
|
|
):
|
|
cfg2["logging"]["performance_tracking"] = {}
|
|
cfg2["logging"]["performance_tracking"]["enabled"] = bool(
|
|
vars_["logging_performance_enabled_var"].get()
|
|
)
|
|
cfg2["logging"]["performance_tracking"]["track_function_calls"] = bool(
|
|
vars_["logging_track_functions_var"].get()
|
|
)
|
|
cfg2["log_unified_enabled"] = bool(vars_["log_unified_enabled_var"].get())
|
|
cfg2["log_unified_path"] = str(vars_["log_unified_path_var"].get() or "logs/unified.log")
|
|
|
|
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),
|
|
}
|
|
|
|
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
|
|
|