refactor(gui): 抽 load_config_to_ui + save_ui_to_config 到 components/config_io (3538 → 3052)
This commit is contained in:
1 parent
3d433080c2
commit
6bac014c3d
3 files changed
+836
-638
No files matched your search
@@ -0,0 +1,678 @@
|
||||
"""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
|
||||
|
||||
+150
-636
@@ -83,6 +83,10 @@ from gui.components.run_log_view import refresh_run_log as _refresh_run_log_impl
|
||||
from gui.components.text_search import generic_search_widget as _generic_search_widget_impl
|
||||
from gui.components.logging_config_io import save_logging_config as _save_logging_config_impl
|
||||
from gui.components.run_params_builder import get_params as _get_params_impl
|
||||
from gui.components.config_io import (
|
||||
load_config_to_ui as _load_config_to_ui_impl,
|
||||
save_ui_to_config as _save_ui_to_config_impl,
|
||||
)
|
||||
|
||||
# 导入日志颜色配置模块
|
||||
try:
|
||||
@@ -1935,648 +1939,158 @@ def main():
|
||||
not_want_text = ScrolledText(kw_box, height=8)
|
||||
not_want_text.pack(fill=X, padx=10, pady=(0, 10))
|
||||
|
||||
_config_io_vars = {
|
||||
"attend_button_red_ratio_threshold_var": attend_button_red_ratio_threshold_var,
|
||||
"auto_join_var": auto_join_var,
|
||||
"coupon_template_match_threshold_var": coupon_template_match_threshold_var,
|
||||
"debug_captures_async_save_var": debug_captures_async_save_var,
|
||||
"debug_captures_auto_cleanup_var": debug_captures_auto_cleanup_var,
|
||||
"debug_captures_enabled_var": debug_captures_enabled_var,
|
||||
"debug_captures_keep_days_var": debug_captures_keep_days_var,
|
||||
"debug_captures_log_on_complete_var": debug_captures_log_on_complete_var,
|
||||
"debug_captures_max_files_var": debug_captures_max_files_var,
|
||||
"enable_back_on_misses_var": enable_back_on_misses_var,
|
||||
"enable_ocr_mode1_var": enable_ocr_mode1_var,
|
||||
"fansclub_action_var": fansclub_action_var,
|
||||
"fansclub_auto_wait_var": fansclub_auto_wait_var,
|
||||
"fansclub_click_delay_var": fansclub_click_delay_var,
|
||||
"fansclub_join_red_ratio_threshold_var": fansclub_join_red_ratio_threshold_var,
|
||||
"fansclub_manual_wait_var": fansclub_manual_wait_var,
|
||||
"fudai_click_wait_seconds_var": fudai_click_wait_seconds_var,
|
||||
"fudai_detail_template_threshold_var": fudai_detail_template_threshold_var,
|
||||
"fudai_disable_content_recognition_var": fudai_disable_content_recognition_var,
|
||||
"fudai_disable_task_recognition_var": fudai_disable_task_recognition_var,
|
||||
"fudai_exit_after_misses_var": fudai_exit_after_misses_var,
|
||||
"fudai_find_max_attempts_var": fudai_find_max_attempts_var,
|
||||
"fudai_icon_max_wait_seconds_var": fudai_icon_max_wait_seconds_var,
|
||||
"fudai_icon_retry_delay_seconds_var": fudai_icon_retry_delay_seconds_var,
|
||||
"fudai_quiet_end_hour_var": fudai_quiet_end_hour_var,
|
||||
"fudai_quiet_hours_enabled_var": fudai_quiet_hours_enabled_var,
|
||||
"fudai_quiet_start_hour_var": fudai_quiet_start_hour_var,
|
||||
"fudai_template_match_enabled_var": fudai_template_match_enabled_var,
|
||||
"fudai_template_match_threshold_var": fudai_template_match_threshold_var,
|
||||
"gui_realtime_refresh_interval_ms_var": gui_realtime_refresh_interval_ms_var,
|
||||
"gui_realtime_tail_items_var": gui_realtime_tail_items_var,
|
||||
"gui_theme_var": gui_theme_var,
|
||||
"high_value_fudai_after_action_var": high_value_fudai_after_action_var,
|
||||
"high_value_fudai_enabled_var": high_value_fudai_enabled_var,
|
||||
"high_value_fudai_join_ahead_seconds_var": high_value_fudai_join_ahead_seconds_var,
|
||||
"high_value_fudai_max_reservations_var": high_value_fudai_max_reservations_var,
|
||||
"high_value_fudai_max_swipe_back_var": high_value_fudai_max_swipe_back_var,
|
||||
"high_value_fudai_poll_before_seconds_var": high_value_fudai_poll_before_seconds_var,
|
||||
"high_value_fudai_threshold_yuan_var": high_value_fudai_threshold_yuan_var,
|
||||
"high_value_room_revisit_enabled_var": high_value_room_revisit_enabled_var,
|
||||
"high_value_room_revisit_max_age_days_var": high_value_room_revisit_max_age_days_var,
|
||||
"high_value_room_revisit_max_per_run_var": high_value_room_revisit_max_per_run_var,
|
||||
"high_value_room_revisit_min_interval_seconds_var": high_value_room_revisit_min_interval_seconds_var,
|
||||
"high_value_room_revisit_min_prize_value_var": high_value_room_revisit_min_prize_value_var,
|
||||
"high_value_room_revisit_only_current_run_var": high_value_room_revisit_only_current_run_var,
|
||||
"infinite_loop_var": infinite_loop_var,
|
||||
"live_room_match_threshold_var": live_room_match_threshold_var,
|
||||
"log_unified_enabled_var": log_unified_enabled_var,
|
||||
"log_unified_path_var": log_unified_path_var,
|
||||
"logging_action_format_var": logging_action_format_var,
|
||||
"logging_beautify_var": logging_beautify_var,
|
||||
"logging_color_var": logging_color_var,
|
||||
"logging_compress_after_days_var": logging_compress_after_days_var,
|
||||
"logging_compress_logs_var": logging_compress_logs_var,
|
||||
"logging_debug_level_var": logging_debug_level_var,
|
||||
"logging_enable_monitor_var": logging_enable_monitor_var,
|
||||
"logging_error_level_var": logging_error_level_var,
|
||||
"logging_format_mode_var": logging_format_mode_var,
|
||||
"logging_keep_days_var": logging_keep_days_var,
|
||||
"logging_max_total_size_gb_var": logging_max_total_size_gb_var,
|
||||
"logging_monitor_critical_mb_var": logging_monitor_critical_mb_var,
|
||||
"logging_monitor_warning_mb_var": logging_monitor_warning_mb_var,
|
||||
"logging_performance_enabled_var": logging_performance_enabled_var,
|
||||
"logging_show_timestamps_var": logging_show_timestamps_var,
|
||||
"logging_track_functions_var": logging_track_functions_var,
|
||||
"logging_use_dated_logs_var": logging_use_dated_logs_var,
|
||||
"lucky_draw_red_ratio_threshold_var": lucky_draw_red_ratio_threshold_var,
|
||||
"max_participants_var": max_participants_var,
|
||||
"min_participants_var": min_participants_var,
|
||||
"min_value_var": min_value_var,
|
||||
"needswitch_var": needswitch_var,
|
||||
"reservation_back_swipe_delay_var": reservation_back_swipe_delay_var,
|
||||
"reservation_back_verify_enabled_var": reservation_back_verify_enabled_var,
|
||||
"reservation_back_verify_wait_seconds_var": reservation_back_verify_wait_seconds_var,
|
||||
"reset_after_swipes_action_var": reset_after_swipes_action_var,
|
||||
"reset_after_swipes_enabled_var": reset_after_swipes_enabled_var,
|
||||
"reset_after_swipes_var": reset_after_swipes_var,
|
||||
"shopping_redpacket_red_ratio_threshold_var": shopping_redpacket_red_ratio_threshold_var,
|
||||
"skip_gt_seconds_var": skip_gt_seconds_var,
|
||||
"skip_lt_seconds_var": skip_lt_seconds_var,
|
||||
"stage_diag_max_step_time_var": stage_diag_max_step_time_var,
|
||||
"stage_diag_max_time_var": stage_diag_max_time_var,
|
||||
"stage_diag_verbose_var": stage_diag_verbose_var,
|
||||
"streaming_enabled_var": streaming_enabled_var,
|
||||
"swipe_down_back_count_var": swipe_down_back_count_var,
|
||||
"swipe_down_back_enabled_var": swipe_down_back_enabled_var,
|
||||
"swipe_duration_ms_var": swipe_duration_ms_var,
|
||||
"swipe_up_end_y_var": swipe_up_end_y_var,
|
||||
"swipe_up_start_y_var": swipe_up_start_y_var,
|
||||
"switch_room_wait_after_stage_diag_seconds_var": switch_room_wait_after_stage_diag_seconds_var,
|
||||
"wait_minutes_var": wait_minutes_var,
|
||||
"y_var": y_var,
|
||||
"yg_actions_enabled_var": yg_actions_enabled_var,
|
||||
"yg_after_dwell_direction_var": yg_after_dwell_direction_var,
|
||||
"yg_after_dwell_distance_var": yg_after_dwell_distance_var,
|
||||
"yg_comment_btn_x_var": yg_comment_btn_x_var,
|
||||
"yg_comment_btn_y_var": yg_comment_btn_y_var,
|
||||
"yg_comment_close_x_var": yg_comment_close_x_var,
|
||||
"yg_comment_close_y_var": yg_comment_close_y_var,
|
||||
"yg_comment_input_x_var": yg_comment_input_x_var,
|
||||
"yg_comment_input_y_var": yg_comment_input_y_var,
|
||||
"yg_comment_prob_var": yg_comment_prob_var,
|
||||
"yg_comment_send_x_var": yg_comment_send_x_var,
|
||||
"yg_comment_send_y_var": yg_comment_send_y_var,
|
||||
"yg_dwell_on_action_max_var": yg_dwell_on_action_max_var,
|
||||
"yg_dwell_on_action_min_var": yg_dwell_on_action_min_var,
|
||||
"yg_enabled_var": yg_enabled_var,
|
||||
"yg_fav_icon_x_var": yg_fav_icon_x_var,
|
||||
"yg_fav_icon_y_var": yg_fav_icon_y_var,
|
||||
"yg_fav_prob_var": yg_fav_prob_var,
|
||||
"yg_fav_roi_offset_x_var": yg_fav_roi_offset_x_var,
|
||||
"yg_fav_roi_offset_y_var": yg_fav_roi_offset_y_var,
|
||||
"yg_fav_template_path_var": yg_fav_template_path_var,
|
||||
"yg_icon_match_threshold_var": yg_icon_match_threshold_var,
|
||||
"yg_icon_roi_size_var": yg_icon_roi_size_var,
|
||||
"yg_like_icon_x_var": yg_like_icon_x_var,
|
||||
"yg_like_icon_y_var": yg_like_icon_y_var,
|
||||
"yg_like_prob_var": yg_like_prob_var,
|
||||
"yg_like_roi_offset_x_var": yg_like_roi_offset_x_var,
|
||||
"yg_like_roi_offset_y_var": yg_like_roi_offset_y_var,
|
||||
"yg_like_template_path_var": yg_like_template_path_var,
|
||||
"yg_only_var": yg_only_var,
|
||||
"yg_recommend_duration_var": yg_recommend_duration_var,
|
||||
"yg_recommend_interval_var": yg_recommend_interval_var,
|
||||
"yg_step_screenshot_var": yg_step_screenshot_var,
|
||||
}
|
||||
_config_io_texts = {
|
||||
"not_want_text": not_want_text,
|
||||
"want_text": want_text,
|
||||
"yg_comment_texts": yg_comment_texts,
|
||||
"yg_fav_keywords_text": yg_fav_keywords_text,
|
||||
"yg_like_keywords_text": yg_like_keywords_text,
|
||||
}
|
||||
|
||||
def load_config_to_ui():
|
||||
nonlocal cfg
|
||||
cfg = read_config()
|
||||
needswitch_var.set(bool(cfg.get("needswitch", True)))
|
||||
infinite_loop_var.set(bool(cfg.get("infinite_loop_enabled", False)))
|
||||
wait_minutes_var.set(int(cfg.get("wait_minutes", 5) or 5))
|
||||
yg_enabled_var.set(bool(cfg.get("yanghao_enabled", True)))
|
||||
yg_actions_enabled_var.set(bool(cfg.get("yanghao_enable_actions", True)))
|
||||
yg_only_var.set(bool(cfg.get("yanghao_only", False)))
|
||||
yg_recommend_duration_var.set(
|
||||
int(cfg.get("yanghao_recommend_duration_seconds", 60) or 60)
|
||||
cfg = _load_config_to_ui_impl(
|
||||
vars_=_config_io_vars,
|
||||
texts_=_config_io_texts,
|
||||
read_config=read_config,
|
||||
)
|
||||
yg_recommend_interval_var.set(
|
||||
int(cfg.get("yanghao_recommend_interval_seconds", 0) or 0)
|
||||
)
|
||||
min_value_var.set(float(cfg.get("min_prize_value_yuan", 0) or 0))
|
||||
min_participants_var.set(int(cfg.get("min_participants", 0) or 0))
|
||||
max_participants_var.set(int(cfg.get("max_participants", 0) or 0))
|
||||
skip_gt_seconds_var.set(
|
||||
int(cfg.get("skip_if_countdown_gt_seconds", 900) or 900)
|
||||
)
|
||||
reset_after_swipes_enabled_var.set(
|
||||
bool(cfg.get("reset_after_swipes_enabled", False))
|
||||
)
|
||||
reset_after_swipes_var.set(int(cfg.get("reset_after_swipes", 10) or 10))
|
||||
reset_after_swipes_action_var.set(
|
||||
str(cfg.get("reset_after_swipes_action", "swipe") or "swipe")
|
||||
)
|
||||
enable_back_on_misses_var.set(bool(cfg.get("enable_back_on_misses", True)))
|
||||
swipe_down_back_enabled_var.set(
|
||||
bool(cfg.get("swipe_down_back_enabled", False))
|
||||
)
|
||||
swipe_down_back_count_var.set(int(cfg.get("swipe_down_back_count", 3) or 3))
|
||||
auto_join_var.set(bool(cfg.get("auto_join_fansclub", False)))
|
||||
fansclub_action_var.set(
|
||||
str(cfg.get("fansclub_fail_action", "stay") or "stay").lower()
|
||||
)
|
||||
streaming_enabled_var.set(bool(cfg.get("enable_streaming_screenshot", True)))
|
||||
lucky_draw_red_ratio_threshold_var.set(
|
||||
float(cfg.get("lucky_draw_red_ratio_threshold", 0.9) or 0.9)
|
||||
)
|
||||
y_var.set(int(cfg.get("y_pianyi", 0) or 0))
|
||||
|
||||
# Web端新增配置 - 高价值预约相关
|
||||
high_value_fudai_enabled_var.set(
|
||||
bool(cfg.get("high_value_fudai_enabled", False))
|
||||
)
|
||||
high_value_fudai_threshold_yuan_var.set(
|
||||
float(cfg.get("high_value_fudai_threshold_yuan", 1000) or 1000)
|
||||
)
|
||||
high_value_fudai_join_ahead_seconds_var.set(
|
||||
int(cfg.get("high_value_fudai_join_ahead_seconds", 300) or 300)
|
||||
)
|
||||
high_value_fudai_max_swipe_back_var.set(
|
||||
int(cfg.get("high_value_fudai_max_swipe_back", 60) or 60)
|
||||
)
|
||||
high_value_fudai_max_reservations_var.set(
|
||||
int(cfg.get("high_value_fudai_max_reservations", 5) or 5)
|
||||
)
|
||||
high_value_fudai_after_action_var.set(
|
||||
str(cfg.get("high_value_fudai_after_action", "continue") or "continue")
|
||||
)
|
||||
high_value_fudai_poll_before_seconds_var.set(
|
||||
float(cfg.get("high_value_fudai_poll_before_seconds", 10.0) or 10.0)
|
||||
)
|
||||
high_value_room_revisit_enabled_var.set(
|
||||
bool(cfg.get("high_value_room_revisit_enabled", True))
|
||||
)
|
||||
high_value_room_revisit_only_current_run_var.set(
|
||||
bool(cfg.get("high_value_room_revisit_only_current_run", False))
|
||||
)
|
||||
high_value_room_revisit_min_interval_seconds_var.set(
|
||||
int(cfg.get("high_value_room_revisit_min_interval_seconds", 300))
|
||||
)
|
||||
high_value_room_revisit_max_per_run_var.set(
|
||||
int(cfg.get("high_value_room_revisit_max_per_run", 5))
|
||||
)
|
||||
high_value_room_revisit_min_prize_value_var.set(
|
||||
float(cfg.get("high_value_room_revisit_min_prize_value", 0.0))
|
||||
)
|
||||
high_value_room_revisit_max_age_days_var.set(
|
||||
int(cfg.get("high_value_room_revisit_max_age_days", 30))
|
||||
)
|
||||
reservation_back_verify_enabled_var.set(
|
||||
bool(cfg.get("reservation_back_verify_enabled", True))
|
||||
)
|
||||
reservation_back_swipe_delay_var.set(
|
||||
float(cfg.get("reservation_back_swipe_delay", 0) or 0)
|
||||
)
|
||||
reservation_back_verify_wait_seconds_var.set(
|
||||
float(cfg.get("reservation_back_verify_wait_seconds", 5.0) or 5.0)
|
||||
)
|
||||
fudai_find_max_attempts_var.set(int(cfg.get("fudai_find_max_attempts", 0) or 0))
|
||||
fudai_icon_retry_delay_seconds_var.set(
|
||||
float(cfg.get("fudai_icon_retry_delay_seconds", 0.6) or 0.6)
|
||||
)
|
||||
fudai_icon_max_wait_seconds_var.set(
|
||||
float(cfg.get("fudai_icon_max_wait_seconds", 5.0) or 5.0)
|
||||
)
|
||||
fudai_click_wait_seconds_var.set(
|
||||
float(cfg.get("fudai_click_wait_seconds", 1.0) or 1.0)
|
||||
)
|
||||
fudai_disable_content_recognition_var.set(
|
||||
bool(cfg.get("fudai_disable_content_recognition", False))
|
||||
)
|
||||
fudai_disable_task_recognition_var.set(
|
||||
bool(cfg.get("fudai_disable_task_recognition", False))
|
||||
)
|
||||
try:
|
||||
fudai_exit_after_misses_var.set(
|
||||
int(cfg.get("fudai_exit_after_misses", 30) or 30)
|
||||
)
|
||||
except Exception:
|
||||
fudai_exit_after_misses_var.set(30)
|
||||
try:
|
||||
enable_back_on_misses_var.set(bool(cfg.get("enable_back_on_misses", True)))
|
||||
except Exception:
|
||||
enable_back_on_misses_var.set(True)
|
||||
try:
|
||||
reset_after_swipes_action_var.set(
|
||||
str(cfg.get("reset_after_swipes_action", "swipe"))
|
||||
)
|
||||
except Exception:
|
||||
reset_after_swipes_action_var.set("swipe")
|
||||
switch_room_wait_after_stage_diag_seconds_var.set(
|
||||
float(cfg.get("switch_room_wait_after_stage_diag_seconds", 7.0) or 7.0)
|
||||
)
|
||||
# GUI 主题
|
||||
try:
|
||||
gui_theme_var.set(
|
||||
str(cfg.get("gui", {}).get("theme", "litera") or "litera")
|
||||
)
|
||||
except Exception:
|
||||
gui_theme_var.set("litera")
|
||||
live_room_match_threshold_var.set(
|
||||
float(cfg.get("live_room_match_threshold", 0.8) or 0.8)
|
||||
)
|
||||
swipe_duration_ms_var.set(int(cfg.get("swipe_duration_ms", 600) or 600))
|
||||
swipe_up_start_y_var.set(int(cfg.get("swipe_up_start_y", 1200) or 1200))
|
||||
swipe_up_end_y_var.set(int(cfg.get("swipe_up_end_y", 600) or 600))
|
||||
fudai_quiet_hours_enabled_var.set(
|
||||
bool(cfg.get("fudai_quiet_hours_enabled", True))
|
||||
)
|
||||
fudai_quiet_start_hour_var.set(int(cfg.get("fudai_quiet_start_hour", 2) or 2))
|
||||
fudai_quiet_end_hour_var.set(int(cfg.get("fudai_quiet_end_hour", 7) or 7))
|
||||
stage_diag_max_time_var.set(float(cfg.get("stage_diag_max_time", 10.0) or 10.0))
|
||||
stage_diag_max_step_time_var.set(
|
||||
float(cfg.get("stage_diag_max_step_time", 2.0) or 2.0)
|
||||
)
|
||||
stage_diag_verbose_var.set(
|
||||
bool(cfg.get("logging", {}).get("stage_diag_verbose", True))
|
||||
)
|
||||
enable_ocr_mode1_var.set(bool(cfg.get("enable_ocr_mode1", False)))
|
||||
fudai_template_match_enabled_var.set(
|
||||
bool(cfg.get("fudai_template_match_enabled", False))
|
||||
)
|
||||
fudai_template_match_threshold_var.set(
|
||||
float(cfg.get("fudai_template_match_threshold", 0.7) or 0.7)
|
||||
)
|
||||
fudai_detail_template_threshold_var.set(
|
||||
float(cfg.get("fudai_detail_template_threshold", 0.7) or 0.7)
|
||||
)
|
||||
coupon_template_match_threshold_var.set(
|
||||
float(cfg.get("coupon_template_match_threshold", 0.75) or 0.75)
|
||||
)
|
||||
attend_button_red_ratio_threshold_var.set(
|
||||
float(cfg.get("attend_button_red_ratio_threshold", 0.25) or 0.25)
|
||||
)
|
||||
fansclub_join_red_ratio_threshold_var.set(
|
||||
float(cfg.get("fansclub_join_red_ratio_threshold", 0.25) or 0.25)
|
||||
)
|
||||
shopping_redpacket_red_ratio_threshold_var.set(
|
||||
float(cfg.get("shopping_redpacket_red_ratio_threshold", 0.15) or 0.15)
|
||||
)
|
||||
# 粉丝团等待/点击延迟配置
|
||||
fansclub_click_delay_var.set(float(cfg.get("fansclub_click_delay", 0.6) or 0.6))
|
||||
fansclub_auto_wait_var.set(
|
||||
float(cfg.get("fansclub_auto_join_wait_seconds", 5.0) or 5.0)
|
||||
)
|
||||
fansclub_manual_wait_var.set(
|
||||
float(cfg.get("fansclub_manual_wait_seconds", 3.0) or 3.0)
|
||||
)
|
||||
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):
|
||||
debug_captures_enabled_var.set(
|
||||
bool(debug_captures_config.get("enabled", False))
|
||||
)
|
||||
debug_captures_auto_cleanup_var.set(
|
||||
bool(debug_captures_config.get("auto_cleanup", True))
|
||||
)
|
||||
debug_captures_keep_days_var.set(
|
||||
int(debug_captures_config.get("keep_days", 7) or 7)
|
||||
)
|
||||
debug_captures_max_files_var.set(
|
||||
int(debug_captures_config.get("max_files", 2000) or 2000)
|
||||
)
|
||||
debug_captures_async_save_var.set(
|
||||
bool(debug_captures_config.get("async_save", True))
|
||||
)
|
||||
debug_captures_log_on_complete_var.set(
|
||||
bool(debug_captures_config.get("log_on_complete", False))
|
||||
)
|
||||
else:
|
||||
debug_captures_auto_cleanup_var.set(True)
|
||||
debug_captures_keep_days_var.set(7)
|
||||
debug_captures_max_files_var.set(2000)
|
||||
|
||||
# 日志配置(load_config_to_ui 需要覆盖 UI 变量,避免“保存后再加载不生效”)
|
||||
logging_config = cfg.get("logging", {})
|
||||
if isinstance(logging_config, dict):
|
||||
logging_beautify_var.set(bool(logging_config.get("beautify_output", True)))
|
||||
logging_color_var.set(bool(logging_config.get("color_output", True)))
|
||||
logging_show_timestamps_var.set(
|
||||
bool(logging_config.get("show_timestamps", True))
|
||||
)
|
||||
logging_use_dated_logs_var.set(
|
||||
bool(logging_config.get("use_dated_logs", True))
|
||||
)
|
||||
logging_enable_monitor_var.set(
|
||||
bool(logging_config.get("enable_monitor", True))
|
||||
)
|
||||
log_unified_enabled_var.set(bool(cfg.get("log_unified_enabled", True)))
|
||||
log_unified_path_var.set(
|
||||
str(cfg.get("log_unified_path", "logs/unified.log") or "logs/unified.log")
|
||||
)
|
||||
logging_keep_days_var.set(int(logging_config.get("keep_days", 30) or 30))
|
||||
logging_compress_logs_var.set(
|
||||
bool(logging_config.get("compress_logs", True))
|
||||
)
|
||||
logging_max_total_size_gb_var.set(
|
||||
float(logging_config.get("max_total_size_gb", 10.0) or 10.0)
|
||||
)
|
||||
logging_compress_after_days_var.set(
|
||||
int(logging_config.get("compress_after_days", 7) or 7)
|
||||
)
|
||||
logging_debug_level_var.set(
|
||||
str(logging_config.get("debug_detail_level", "normal") or "normal")
|
||||
)
|
||||
logging_error_level_var.set(
|
||||
str(logging_config.get("error_detail_level", "full") or "full")
|
||||
)
|
||||
logging_action_format_var.set(
|
||||
str(logging_config.get("action_log_format", "concise") or "concise")
|
||||
)
|
||||
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):
|
||||
logging_performance_enabled_var.set(bool(perf_cfg.get("enabled", True)))
|
||||
logging_track_functions_var.set(
|
||||
bool(perf_cfg.get("track_function_calls", True))
|
||||
)
|
||||
logging_monitor_warning_mb_var.set(
|
||||
float(logging_config.get("monitor_warning_mb", 500.0) or 500.0)
|
||||
)
|
||||
logging_monitor_critical_mb_var.set(
|
||||
float(logging_config.get("monitor_critical_mb", 2000.0) or 2000.0)
|
||||
)
|
||||
|
||||
yg_like_prob_var.set(float(cfg.get("yanghao_like_prob", 0.0) or 0.0))
|
||||
yg_fav_prob_var.set(float(cfg.get("yanghao_fav_prob", 0.0) or 0.0))
|
||||
yg_comment_prob_var.set(float(cfg.get("yanghao_comment_prob", 0.0) or 0.0))
|
||||
yg_dwell_on_action_min_var.set(
|
||||
float(cfg.get("yanghao_dwell_on_action_min_seconds", 5) or 5)
|
||||
)
|
||||
yg_dwell_on_action_max_var.set(
|
||||
float(cfg.get("yanghao_dwell_on_action_max_seconds", 30) or 30)
|
||||
)
|
||||
yg_icon_roi_size_var.set(int(cfg.get("yanghao_icon_roi_size", 240) or 240))
|
||||
yg_icon_match_threshold_var.set(
|
||||
float(cfg.get("yanghao_icon_match_threshold", 0.72) or 0.72)
|
||||
)
|
||||
yg_step_screenshot_var.set(bool(cfg.get("yanghao_step_screenshot", False)))
|
||||
yg_like_roi_offset_x_var.set(int(cfg.get("yanghao_like_roi_offset_x", 0) or 0))
|
||||
yg_like_roi_offset_y_var.set(int(cfg.get("yanghao_like_roi_offset_y", 0) or 0))
|
||||
yg_fav_roi_offset_x_var.set(int(cfg.get("yanghao_fav_roi_offset_x", 0) or 0))
|
||||
yg_fav_roi_offset_y_var.set(int(cfg.get("yanghao_fav_roi_offset_y", 0) or 0))
|
||||
yg_like_icon_x_var.set(int(cfg.get("yanghao_like_icon_x", 0) or 0))
|
||||
yg_like_icon_y_var.set(int(cfg.get("yanghao_like_icon_y", 0) or 0))
|
||||
yg_fav_icon_x_var.set(int(cfg.get("yanghao_fav_icon_x", 0) or 0))
|
||||
yg_fav_icon_y_var.set(int(cfg.get("yanghao_fav_icon_y", 0) or 0))
|
||||
yg_like_template_path_var.set(
|
||||
str(
|
||||
cfg.get("yanghao_like_template_path", "assets/like.png")
|
||||
or "assets/like.png"
|
||||
)
|
||||
)
|
||||
yg_fav_template_path_var.set(
|
||||
str(
|
||||
cfg.get("yanghao_fav_template_path", "assets/fav.png")
|
||||
or "assets/fav.png"
|
||||
)
|
||||
)
|
||||
yg_after_dwell_direction_var.set(
|
||||
str(cfg.get("yanghao_after_dwell_swipe_direction", "up") or "up")
|
||||
)
|
||||
yg_after_dwell_distance_var.set(
|
||||
int(cfg.get("yanghao_after_dwell_swipe_distance_px", 900) or 900)
|
||||
)
|
||||
yg_comment_btn_x_var.set(int(cfg.get("yanghao_comment_btn_x", 0) or 0))
|
||||
yg_comment_btn_y_var.set(int(cfg.get("yanghao_comment_btn_y", 0) or 0))
|
||||
yg_comment_input_x_var.set(int(cfg.get("yanghao_comment_input_x", 0) or 0))
|
||||
yg_comment_input_y_var.set(int(cfg.get("yanghao_comment_input_y", 0) or 0))
|
||||
yg_comment_send_x_var.set(int(cfg.get("yanghao_comment_send_x", 0) or 0))
|
||||
yg_comment_send_y_var.set(int(cfg.get("yanghao_comment_send_y", 0) or 0))
|
||||
yg_comment_close_x_var.set(int(cfg.get("yanghao_comment_close_x", 0) or 0))
|
||||
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 []
|
||||
want_text.delete("1.0", "end")
|
||||
want_text.insert("1.0", "\n".join(want))
|
||||
not_want_text.delete("1.0", "end")
|
||||
not_want_text.insert("1.0", "\n".join(not_want))
|
||||
yg_comment_texts.delete("1.0", "end")
|
||||
yg_comment_texts.insert("1.0", "\n".join(yg_comment_texts_list))
|
||||
yg_like_keywords_text.delete("1.0", "end")
|
||||
yg_like_keywords_text.insert("1.0", "\n".join(yg_like_keywords_list))
|
||||
yg_fav_keywords_text.delete("1.0", "end")
|
||||
yg_fav_keywords_text.insert("1.0", "\n".join(yg_fav_keywords_list))
|
||||
|
||||
def save_ui_to_config():
|
||||
want_lines = [
|
||||
x.strip() for x in want_text.get("1.0", "end").splitlines() if x.strip()
|
||||
]
|
||||
not_want_lines = [
|
||||
x.strip() for x in not_want_text.get("1.0", "end").splitlines() if x.strip()
|
||||
]
|
||||
yg_comment_text_lines = [
|
||||
x.strip()
|
||||
for x in yg_comment_texts.get("1.0", "end").splitlines()
|
||||
if x.strip()
|
||||
]
|
||||
yg_like_kw_lines = [
|
||||
x.strip()
|
||||
for x in yg_like_keywords_text.get("1.0", "end").splitlines()
|
||||
if x.strip()
|
||||
]
|
||||
yg_fav_kw_lines = [
|
||||
x.strip()
|
||||
for x in yg_fav_keywords_text.get("1.0", "end").splitlines()
|
||||
if x.strip()
|
||||
]
|
||||
|
||||
cfg2 = read_config()
|
||||
cfg2["needswitch"] = bool(needswitch_var.get())
|
||||
cfg2["infinite_loop_enabled"] = bool(infinite_loop_var.get())
|
||||
cfg2["wait_minutes"] = int(wait_minutes_var.get() or 5)
|
||||
cfg2["y_pianyi"] = int(y_var.get() or 0)
|
||||
cfg2["contains_want"] = want_lines
|
||||
cfg2["contains_not_want"] = not_want_lines
|
||||
cfg2["min_prize_value_yuan"] = float(min_value_var.get() or 0)
|
||||
cfg2["min_participants"] = int(min_participants_var.get() or 0)
|
||||
cfg2["max_participants"] = int(max_participants_var.get() or 0)
|
||||
cfg2["skip_if_countdown_gt_seconds"] = int(skip_gt_seconds_var.get() or 900)
|
||||
cfg2["reset_after_swipes_enabled"] = bool(reset_after_swipes_enabled_var.get())
|
||||
cfg2["reset_after_swipes"] = int(reset_after_swipes_var.get() or 10)
|
||||
cfg2["auto_join_fansclub"] = bool(auto_join_var.get())
|
||||
cfg2["fansclub_fail_action"] = str(fansclub_action_var.get() or "stay").lower()
|
||||
cfg2["lucky_draw_red_ratio_threshold"] = float(
|
||||
lucky_draw_red_ratio_threshold_var.get() or 0.9
|
||||
_save_ui_to_config_impl(
|
||||
vars_=_config_io_vars,
|
||||
texts_=_config_io_texts,
|
||||
cfg=cfg,
|
||||
read_config=read_config,
|
||||
write_config=write_config,
|
||||
on_line=on_line,
|
||||
)
|
||||
|
||||
# Web端新增配置 - 高价值预约相关
|
||||
cfg2["high_value_fudai_enabled"] = bool(high_value_fudai_enabled_var.get())
|
||||
cfg2["high_value_fudai_threshold_yuan"] = float(
|
||||
high_value_fudai_threshold_yuan_var.get() or 1000
|
||||
)
|
||||
cfg2["high_value_fudai_join_ahead_seconds"] = int(
|
||||
high_value_fudai_join_ahead_seconds_var.get() or 300
|
||||
)
|
||||
cfg2["high_value_fudai_max_swipe_back"] = int(
|
||||
high_value_fudai_max_swipe_back_var.get() or 60
|
||||
)
|
||||
cfg2["high_value_fudai_max_reservations"] = int(
|
||||
high_value_fudai_max_reservations_var.get() or 5
|
||||
)
|
||||
cfg2["high_value_fudai_after_action"] = str(
|
||||
high_value_fudai_after_action_var.get() or "continue"
|
||||
).lower()
|
||||
cfg2["high_value_fudai_poll_before_seconds"] = float(
|
||||
high_value_fudai_poll_before_seconds_var.get() or 10.0
|
||||
)
|
||||
cfg2["high_value_room_revisit_enabled"] = bool(
|
||||
high_value_room_revisit_enabled_var.get()
|
||||
)
|
||||
cfg2["high_value_room_revisit_only_current_run"] = bool(
|
||||
high_value_room_revisit_only_current_run_var.get()
|
||||
)
|
||||
cfg2["high_value_room_revisit_min_interval_seconds"] = int(
|
||||
high_value_room_revisit_min_interval_seconds_var.get()
|
||||
)
|
||||
cfg2["high_value_room_revisit_max_per_run"] = int(
|
||||
high_value_room_revisit_max_per_run_var.get()
|
||||
)
|
||||
cfg2["high_value_room_revisit_min_prize_value"] = float(
|
||||
high_value_room_revisit_min_prize_value_var.get()
|
||||
)
|
||||
cfg2["high_value_room_revisit_max_age_days"] = int(
|
||||
high_value_room_revisit_max_age_days_var.get()
|
||||
)
|
||||
cfg2["reservation_back_verify_enabled"] = bool(
|
||||
reservation_back_verify_enabled_var.get()
|
||||
)
|
||||
cfg2["reservation_back_swipe_delay"] = float(
|
||||
reservation_back_swipe_delay_var.get() or 0
|
||||
)
|
||||
cfg2["reservation_back_verify_wait_seconds"] = float(
|
||||
reservation_back_verify_wait_seconds_var.get() or 5.0
|
||||
)
|
||||
cfg2["fudai_find_max_attempts"] = int(fudai_find_max_attempts_var.get() or 0)
|
||||
cfg2["fudai_icon_retry_delay_seconds"] = float(
|
||||
fudai_icon_retry_delay_seconds_var.get() or 0.6
|
||||
)
|
||||
cfg2["fudai_icon_max_wait_seconds"] = float(
|
||||
fudai_icon_max_wait_seconds_var.get() or 5.0
|
||||
)
|
||||
cfg2["fudai_click_wait_seconds"] = float(
|
||||
fudai_click_wait_seconds_var.get() or 2.0
|
||||
)
|
||||
cfg2["fudai_exit_after_misses"] = int(fudai_exit_after_misses_var.get() or 30)
|
||||
cfg2["enable_back_on_misses"] = bool(enable_back_on_misses_var.get())
|
||||
cfg2["swipe_down_back_enabled"] = bool(swipe_down_back_enabled_var.get())
|
||||
cfg2["swipe_down_back_count"] = int(swipe_down_back_count_var.get() or 3)
|
||||
cfg2["reset_after_swipes_action"] = str(
|
||||
reset_after_swipes_action_var.get() or "swipe"
|
||||
)
|
||||
cfg2["fudai_disable_content_recognition"] = bool(
|
||||
fudai_disable_content_recognition_var.get()
|
||||
)
|
||||
cfg2["fudai_disable_task_recognition"] = bool(
|
||||
fudai_disable_task_recognition_var.get()
|
||||
)
|
||||
cfg2["switch_room_wait_after_stage_diag_seconds"] = float(
|
||||
switch_room_wait_after_stage_diag_seconds_var.get() or 7.0
|
||||
)
|
||||
cfg2["live_room_match_threshold"] = float(
|
||||
live_room_match_threshold_var.get() or 0.8
|
||||
)
|
||||
cfg2["swipe_duration_ms"] = int(swipe_duration_ms_var.get() or 600)
|
||||
cfg2["swipe_up_start_y"] = int(swipe_up_start_y_var.get() or 1200)
|
||||
cfg2["swipe_up_end_y"] = int(swipe_up_end_y_var.get() or 600)
|
||||
cfg2["fudai_quiet_hours_enabled"] = bool(fudai_quiet_hours_enabled_var.get())
|
||||
cfg2["fudai_quiet_start_hour"] = int(fudai_quiet_start_hour_var.get() or 0)
|
||||
cfg2["fudai_quiet_end_hour"] = int(fudai_quiet_end_hour_var.get() or 0)
|
||||
cfg2["stage_diag_max_time"] = float(stage_diag_max_time_var.get() or 10.0)
|
||||
cfg2["stage_diag_max_step_time"] = float(
|
||||
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(
|
||||
fudai_template_match_enabled_var.get()
|
||||
)
|
||||
cfg2["fudai_template_match_threshold"] = float(
|
||||
fudai_template_match_threshold_var.get() or 0.7
|
||||
)
|
||||
cfg2["fudai_detail_template_threshold"] = float(
|
||||
fudai_detail_template_threshold_var.get() or 0.7
|
||||
)
|
||||
cfg2["coupon_template_match_threshold"] = float(
|
||||
coupon_template_match_threshold_var.get() or 0.75
|
||||
)
|
||||
cfg2["attend_button_red_ratio_threshold"] = float(
|
||||
attend_button_red_ratio_threshold_var.get() or 0.25
|
||||
)
|
||||
cfg2["fansclub_join_red_ratio_threshold"] = float(
|
||||
fansclub_join_red_ratio_threshold_var.get() or 0.25
|
||||
)
|
||||
cfg2["shopping_redpacket_red_ratio_threshold"] = float(
|
||||
shopping_redpacket_red_ratio_threshold_var.get() or 0.15
|
||||
)
|
||||
# 粉丝团等待/点击延迟配置
|
||||
cfg2["fansclub_click_delay"] = float(fansclub_click_delay_var.get() or 0.6)
|
||||
cfg2["fansclub_auto_join_wait_seconds"] = float(
|
||||
fansclub_auto_wait_var.get() or 5.0
|
||||
)
|
||||
cfg2["fansclub_manual_wait_seconds"] = float(
|
||||
fansclub_manual_wait_var.get() or 3.0
|
||||
)
|
||||
cfg2["skip_if_countdown_lt_seconds"] = int(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(debug_captures_enabled_var.get())
|
||||
cfg2["debug_captures"]["auto_cleanup"] = bool(
|
||||
debug_captures_auto_cleanup_var.get()
|
||||
)
|
||||
cfg2["debug_captures"]["keep_days"] = int(
|
||||
debug_captures_keep_days_var.get() or 7
|
||||
)
|
||||
cfg2["debug_captures"]["max_files"] = int(
|
||||
debug_captures_max_files_var.get() or 2000
|
||||
)
|
||||
cfg2["debug_captures"]["async_save"] = bool(debug_captures_async_save_var.get())
|
||||
cfg2["debug_captures"]["log_on_complete"] = bool(
|
||||
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(logging_beautify_var.get())
|
||||
cfg2["logging"]["color_output"] = bool(logging_color_var.get())
|
||||
cfg2["logging"]["show_timestamps"] = bool(logging_show_timestamps_var.get())
|
||||
cfg2["logging"]["use_dated_logs"] = bool(logging_use_dated_logs_var.get())
|
||||
cfg2["logging"]["enable_monitor"] = bool(logging_enable_monitor_var.get())
|
||||
cfg2["logging"]["keep_days"] = int(logging_keep_days_var.get() or 30)
|
||||
cfg2["logging"]["compress_logs"] = bool(logging_compress_logs_var.get())
|
||||
cfg2["logging"]["max_total_size_gb"] = float(
|
||||
logging_max_total_size_gb_var.get() or 10.0
|
||||
)
|
||||
cfg2["logging"]["compress_after_days"] = int(
|
||||
logging_compress_after_days_var.get() or 7
|
||||
)
|
||||
cfg2["logging"]["debug_detail_level"] = str(
|
||||
logging_debug_level_var.get() or "normal"
|
||||
)
|
||||
cfg2["logging"]["error_detail_level"] = str(
|
||||
logging_error_level_var.get() or "full"
|
||||
)
|
||||
cfg2["logging"]["action_log_format"] = str(
|
||||
logging_action_format_var.get() or "concise"
|
||||
)
|
||||
cfg2["logging"]["log_format_mode"] = str(
|
||||
logging_format_mode_var.get() or "simple"
|
||||
)
|
||||
cfg2["logging"]["stage_diag_verbose"] = bool(stage_diag_verbose_var.get())
|
||||
cfg2["logging"]["monitor_warning_mb"] = float(
|
||||
logging_monitor_warning_mb_var.get() or 500.0
|
||||
)
|
||||
cfg2["logging"]["monitor_critical_mb"] = float(
|
||||
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(
|
||||
logging_performance_enabled_var.get()
|
||||
)
|
||||
cfg2["logging"]["performance_tracking"]["track_function_calls"] = bool(
|
||||
logging_track_functions_var.get()
|
||||
)
|
||||
cfg2["log_unified_enabled"] = bool(log_unified_enabled_var.get())
|
||||
cfg2["log_unified_path"] = str(log_unified_path_var.get() or "logs/unified.log")
|
||||
|
||||
cfg2["yanghao_enabled"] = bool(yg_enabled_var.get())
|
||||
cfg2["yanghao_enable_actions"] = bool(yg_actions_enabled_var.get())
|
||||
cfg2["yanghao_only"] = bool(yg_only_var.get())
|
||||
cfg2["yanghao_recommend_duration_seconds"] = int(
|
||||
yg_recommend_duration_var.get() or 60
|
||||
)
|
||||
cfg2["yanghao_recommend_interval_seconds"] = int(
|
||||
yg_recommend_interval_var.get() or 0
|
||||
)
|
||||
cfg2["yanghao_like_prob"] = float(yg_like_prob_var.get() or 0.0)
|
||||
cfg2["yanghao_fav_prob"] = float(yg_fav_prob_var.get() or 0.0)
|
||||
cfg2["yanghao_comment_prob"] = float(yg_comment_prob_var.get() or 0.0)
|
||||
cfg2["yanghao_dwell_on_action_min_seconds"] = float(
|
||||
yg_dwell_on_action_min_var.get() or 5
|
||||
)
|
||||
cfg2["yanghao_dwell_on_action_max_seconds"] = float(
|
||||
yg_dwell_on_action_max_var.get() or 30
|
||||
)
|
||||
cfg2["yanghao_icon_roi_size"] = int(yg_icon_roi_size_var.get() or 240)
|
||||
cfg2["yanghao_icon_match_threshold"] = float(
|
||||
yg_icon_match_threshold_var.get() or 0.72
|
||||
)
|
||||
cfg2["yanghao_step_screenshot"] = bool(yg_step_screenshot_var.get())
|
||||
cfg2["yanghao_like_roi_offset_x"] = int(yg_like_roi_offset_x_var.get() or 0)
|
||||
cfg2["yanghao_like_roi_offset_y"] = int(yg_like_roi_offset_y_var.get() or 0)
|
||||
cfg2["yanghao_fav_roi_offset_x"] = int(yg_fav_roi_offset_x_var.get() or 0)
|
||||
cfg2["yanghao_fav_roi_offset_y"] = int(yg_fav_roi_offset_y_var.get() or 0)
|
||||
cfg2["yanghao_like_icon_x"] = int(yg_like_icon_x_var.get() or 0)
|
||||
cfg2["yanghao_like_icon_y"] = int(yg_like_icon_y_var.get() or 0)
|
||||
cfg2["yanghao_fav_icon_x"] = int(yg_fav_icon_x_var.get() or 0)
|
||||
cfg2["yanghao_fav_icon_y"] = int(yg_fav_icon_y_var.get() or 0)
|
||||
cfg2["yanghao_like_template_path"] = str(
|
||||
yg_like_template_path_var.get() or "assets/like.png"
|
||||
)
|
||||
cfg2["yanghao_fav_template_path"] = str(
|
||||
yg_fav_template_path_var.get() or "assets/fav.png"
|
||||
)
|
||||
cfg2["yanghao_after_dwell_swipe_direction"] = str(
|
||||
yg_after_dwell_direction_var.get() or "up"
|
||||
)
|
||||
cfg2["yanghao_after_dwell_swipe_distance_px"] = int(
|
||||
yg_after_dwell_distance_var.get() or 900
|
||||
)
|
||||
cfg2["yanghao_comment_btn_x"] = int(yg_comment_btn_x_var.get() or 0)
|
||||
cfg2["yanghao_comment_btn_y"] = int(yg_comment_btn_y_var.get() or 0)
|
||||
cfg2["yanghao_comment_input_x"] = int(yg_comment_input_x_var.get() or 0)
|
||||
cfg2["yanghao_comment_input_y"] = int(yg_comment_input_y_var.get() or 0)
|
||||
cfg2["yanghao_comment_send_x"] = int(yg_comment_send_x_var.get() or 0)
|
||||
cfg2["yanghao_comment_send_y"] = int(yg_comment_send_y_var.get() or 0)
|
||||
cfg2["yanghao_comment_close_x"] = int(yg_comment_close_x_var.get() or 0)
|
||||
cfg2["yanghao_comment_close_y"] = int(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(streaming_enabled_var.get())
|
||||
|
||||
# GUI 配置
|
||||
if "gui" not in cfg2 or not isinstance(cfg2["gui"], dict):
|
||||
cfg2["gui"] = {}
|
||||
cfg2["gui"]["theme"] = str(gui_theme_var.get() or "litera")
|
||||
cfg2["gui"]["realtime_status"] = {
|
||||
"refresh_interval_ms": int(
|
||||
gui_realtime_refresh_interval_ms_var.get() or 1000
|
||||
),
|
||||
"tail_items": int(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
|
||||
|
||||
load_config_to_ui()
|
||||
|
||||
# 顶部常驻按钮区域(与设备选择同一行,不随左侧滚动)
|
||||
|
||||
@@ -21,6 +21,10 @@ from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
GUI_APP = ROOT / "gui" / "gui_app.py"
|
||||
# load_config_to_ui / save_ui_to_config 已抽到 components/config_io.py,
|
||||
# 但 GUI 启动时仍通过 main() 内的薄包装调用它们。本工具的同步检查需要从
|
||||
# config_io.py 抽 cfg/cfg2 赋值,从 gui_app.py 抽 gui_cfg 引用(仍在 main 里)。
|
||||
GUI_CONFIG_IO = ROOT / "gui" / "components" / "config_io.py"
|
||||
WEB_INDEX = ROOT / "webui" / "index.html"
|
||||
MANIFEST_PATH = ROOT / "tools" / "dev" / "web_gui_config_manifest.json"
|
||||
|
||||
@@ -101,10 +105,12 @@ def extract_web_keys(source: str) -> set[str]:
|
||||
|
||||
def build_manifest() -> dict[str, object]:
|
||||
gui_source = _read(GUI_APP)
|
||||
config_io_source = _read(GUI_CONFIG_IO)
|
||||
web_source = _read(WEB_INDEX)
|
||||
|
||||
gui_saved = extract_gui_saved_keys(gui_source)
|
||||
gui_loaded = extract_gui_loaded_keys(gui_source)
|
||||
# save/load 函数现在在 components/config_io.py 里;gui_cfg 引用仍在 gui_app.py
|
||||
gui_saved = extract_gui_saved_keys(config_io_source)
|
||||
gui_loaded = extract_gui_loaded_keys(config_io_source + "\n" + gui_source)
|
||||
web_keys = extract_web_keys(web_source)
|
||||
|
||||
expected_gui_keys = web_keys - GUI_RUNTIME_ONLY_KEYS
|
||||
|
||||
Reference in new issue
Block a user