- Introduced a comprehensive CSS file for styling the web interface, including variables for colors, layout styles, and responsive design adjustments. - Added a batch script to automate the process of stopping any existing instances of the web GUI and launching the new instance, along with opening the browser to the appropriate URL.
709 lines
29 KiB
Python
709 lines
29 KiB
Python
import json
|
||
import os
|
||
import queue
|
||
import re
|
||
import shutil
|
||
import subprocess
|
||
import sys
|
||
import threading
|
||
from dataclasses import dataclass
|
||
from typing import Optional
|
||
|
||
from PIL import Image, ImageTk
|
||
|
||
|
||
CONFIG_PATH = os.path.join(os.path.dirname(__file__), "config.json")
|
||
|
||
|
||
def find_adb_executable() -> str:
|
||
"""返回可用的 adb 可执行文件路径(优先 PATH,其次默认安装目录)。"""
|
||
adb = shutil.which("adb")
|
||
if adb:
|
||
return adb
|
||
|
||
# 默认安装目录(我们之前下载的 platform-tools)
|
||
localapp = os.environ.get("LOCALAPPDATA") or ""
|
||
candidates = []
|
||
if localapp:
|
||
candidates.append(os.path.join(localapp, "platform-tools", "adb.exe"))
|
||
|
||
# 兼容某些人手动放到用户目录的情况
|
||
userprofile = os.environ.get("USERPROFILE") or ""
|
||
if userprofile:
|
||
candidates.append(os.path.join(userprofile, "AppData", "Local", "platform-tools", "adb.exe"))
|
||
|
||
for p in candidates:
|
||
if os.path.exists(p):
|
||
return p
|
||
return ""
|
||
|
||
|
||
def list_adb_devices(adb_exe: str) -> list[str]:
|
||
try:
|
||
if not adb_exe:
|
||
return []
|
||
proc = subprocess.run([adb_exe, "devices", "-l"], capture_output=True, text=True, encoding="utf-8", errors="replace")
|
||
except FileNotFoundError:
|
||
return []
|
||
text = (proc.stdout or "") + "\n" + (proc.stderr or "")
|
||
pattern = r"(\b(?:[0-9]{1,3}(?:\.[0-9]{1,3}){3}(?::[0-9]+)?|[A-Za-z0-9]{8,})\b)\s*device\b"
|
||
return re.findall(pattern, text)
|
||
|
||
|
||
def read_config() -> dict:
|
||
if not os.path.exists(CONFIG_PATH):
|
||
return {}
|
||
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
||
return json.load(f)
|
||
|
||
|
||
def write_config(cfg: dict) -> None:
|
||
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
|
||
json.dump(cfg, f, ensure_ascii=False, indent=4)
|
||
f.write("\n")
|
||
|
||
|
||
@dataclass
|
||
class RunParams:
|
||
device_id: str
|
||
y_pianyi: int
|
||
needswitch: bool
|
||
wait_minutes: int
|
||
skip_if_countdown_lt_seconds: int
|
||
reset_after_swipes: int
|
||
min_prize_value_yuan: float
|
||
min_participants: int
|
||
max_participants: int
|
||
auto_join_fansclub: bool
|
||
fansclub_fail_action: str
|
||
|
||
|
||
class Runner:
|
||
def __init__(self, on_line):
|
||
self._proc: Optional[subprocess.Popen] = None
|
||
self._on_line = on_line
|
||
self._reader_thread: Optional[threading.Thread] = None
|
||
|
||
def is_running(self) -> bool:
|
||
return self._proc is not None and self._proc.poll() is None
|
||
|
||
def start(self, params: RunParams) -> None:
|
||
if self.is_running():
|
||
raise RuntimeError("已经在运行")
|
||
|
||
cmd = [
|
||
sys.executable,
|
||
os.path.join(os.path.dirname(__file__), "run_cli.py"),
|
||
"--y-pianyi",
|
||
str(params.y_pianyi),
|
||
"--wait-minutes",
|
||
str(params.wait_minutes),
|
||
]
|
||
if params.device_id:
|
||
cmd += ["--device-id", params.device_id]
|
||
if params.needswitch:
|
||
cmd.append("--needswitch")
|
||
|
||
cmd += ["--min-prize-value-yuan", str(params.min_prize_value_yuan)]
|
||
|
||
# 这些参数是新增可调节项:倒计时太短跳过、参与人数范围
|
||
cmd += ["--skip-if-countdown-lt-seconds", str(int(params.skip_if_countdown_lt_seconds or 15))]
|
||
if int(params.reset_after_swipes or 0) > 0:
|
||
cmd += ["--reset-after-swipes", str(int(params.reset_after_swipes))]
|
||
else:
|
||
cmd += ["--reset-after-swipes", "0"]
|
||
if int(params.min_participants or 0) > 0:
|
||
cmd += ["--min-participants", str(int(params.min_participants))]
|
||
if int(params.max_participants or 0) > 0:
|
||
cmd += ["--max-participants", str(int(params.max_participants))]
|
||
|
||
if params.auto_join_fansclub:
|
||
cmd.append("--auto-join-fansclub")
|
||
if params.fansclub_fail_action:
|
||
cmd += ["--fansclub-fail-action", params.fansclub_fail_action]
|
||
|
||
# 继承当前环境,并确保 adb 在 PATH(即使用户没手动刷新 PATH)
|
||
env = os.environ.copy()
|
||
env.setdefault("PYTHONIOENCODING", "utf-8")
|
||
|
||
adb_exe = find_adb_executable()
|
||
if adb_exe:
|
||
adb_dir = os.path.dirname(adb_exe)
|
||
env["PATH"] = adb_dir + os.pathsep + env.get("PATH", "")
|
||
env["ADB_EXECUTABLE"] = adb_exe
|
||
else:
|
||
self._on_line("[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH")
|
||
|
||
self._proc = subprocess.Popen(
|
||
cmd,
|
||
stdout=subprocess.PIPE,
|
||
stderr=subprocess.STDOUT,
|
||
text=True,
|
||
encoding="utf-8",
|
||
errors="replace",
|
||
env=env,
|
||
cwd=os.path.dirname(__file__),
|
||
)
|
||
|
||
def _reader():
|
||
assert self._proc is not None
|
||
out = self._proc.stdout
|
||
if out is None:
|
||
return
|
||
for line in out:
|
||
self._on_line(line.rstrip("\n"))
|
||
rc = self._proc.wait()
|
||
self._on_line(f"[进程结束] exit_code={rc}")
|
||
|
||
self._reader_thread = threading.Thread(target=_reader, daemon=True)
|
||
self._reader_thread.start()
|
||
|
||
def start_test_yanghao_flow(self, device_id: str, seconds: int) -> None:
|
||
if self.is_running():
|
||
raise RuntimeError("已经在运行")
|
||
|
||
seconds = int(seconds or 0)
|
||
if seconds <= 0:
|
||
seconds = 90
|
||
|
||
cmd = [
|
||
sys.executable,
|
||
os.path.join(os.path.dirname(__file__), "run_cli.py"),
|
||
"--test-yanghao-flow",
|
||
"--test-yanghao-flow-seconds",
|
||
str(seconds),
|
||
]
|
||
if device_id:
|
||
cmd += ["--device-id", device_id]
|
||
|
||
env = os.environ.copy()
|
||
env.setdefault("PYTHONIOENCODING", "utf-8")
|
||
|
||
adb_exe = find_adb_executable()
|
||
if adb_exe:
|
||
adb_dir = os.path.dirname(adb_exe)
|
||
env["PATH"] = adb_dir + os.pathsep + env.get("PATH", "")
|
||
env["ADB_EXECUTABLE"] = adb_exe
|
||
else:
|
||
self._on_line("[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH")
|
||
|
||
self._proc = subprocess.Popen(
|
||
cmd,
|
||
stdout=subprocess.PIPE,
|
||
stderr=subprocess.STDOUT,
|
||
text=True,
|
||
encoding="utf-8",
|
||
errors="replace",
|
||
env=env,
|
||
cwd=os.path.dirname(__file__),
|
||
)
|
||
|
||
def _reader():
|
||
assert self._proc is not None
|
||
out = self._proc.stdout
|
||
if out is None:
|
||
return
|
||
for line in out:
|
||
self._on_line(line.rstrip("\n"))
|
||
rc = self._proc.wait()
|
||
self._on_line(f"[进程结束] exit_code={rc}")
|
||
|
||
self._reader_thread = threading.Thread(target=_reader, daemon=True)
|
||
self._reader_thread.start()
|
||
|
||
def stop(self) -> None:
|
||
if not self.is_running():
|
||
return
|
||
assert self._proc is not None
|
||
self._on_line("[停止] 正在终止进程...")
|
||
self._proc.terminate()
|
||
try:
|
||
self._proc.wait(timeout=5)
|
||
except subprocess.TimeoutExpired:
|
||
self._on_line("[停止] 进程未退出,强制结束...")
|
||
self._proc.kill()
|
||
|
||
|
||
def main():
|
||
# ttkbootstrap 优先(更美观);没装则回退到原生 tkinter
|
||
try:
|
||
import ttkbootstrap as tb
|
||
from ttkbootstrap.scrolled import ScrolledText
|
||
|
||
import tkinter as tk
|
||
from tkinter import ttk
|
||
from ttkbootstrap.constants import LEFT, RIGHT, BOTH, X, Y
|
||
|
||
root = tb.Window(themename="darkly")
|
||
except Exception:
|
||
import tkinter as tk
|
||
from tkinter import ttk
|
||
from tkinter.constants import LEFT, RIGHT, BOTH, X, Y
|
||
from tkinter.scrolledtext import ScrolledText
|
||
|
||
root = tk.Tk()
|
||
|
||
root.title("抖音福袋挂机 - 可视化控制台")
|
||
root.geometry("1180x760")
|
||
|
||
q: queue.Queue[str] = queue.Queue()
|
||
|
||
def on_line(line: str):
|
||
q.put(line)
|
||
|
||
runner = Runner(on_line=on_line)
|
||
|
||
# 顶部:设备选择 + Y偏移(其余运行参数放到左侧分组,避免重复)
|
||
top = ttk.Frame(root)
|
||
top.pack(fill=X, padx=12, pady=10)
|
||
|
||
adb_exe = find_adb_executable()
|
||
devices = list_adb_devices(adb_exe)
|
||
device_var = tk.StringVar(value=(devices[0] if devices else ""))
|
||
|
||
ttk.Label(top, text="设备:").pack(side=LEFT)
|
||
device_combo = ttk.Combobox(top, textvariable=device_var, values=devices, width=28)
|
||
device_combo.pack(side=LEFT, padx=(0, 10))
|
||
|
||
def refresh_devices():
|
||
nonlocal adb_exe
|
||
adb_exe = find_adb_executable()
|
||
devs = list_adb_devices(adb_exe)
|
||
device_combo["values"] = devs
|
||
if devs and not device_var.get():
|
||
device_var.set(devs[0])
|
||
if not adb_exe:
|
||
on_line("[设备] 未找到 adb.exe(请确认已安装 platform-tools)")
|
||
elif not devs:
|
||
on_line("[设备] adb 可用,但未发现 device 状态设备(可能未授权/未连接)")
|
||
|
||
ttk.Button(top, text="刷新设备", command=refresh_devices).pack(side=LEFT, padx=(0, 20))
|
||
|
||
y_var = tk.IntVar(value=0)
|
||
ttk.Label(top, text="Y偏移:").pack(side=LEFT)
|
||
ttk.Spinbox(top, from_=-200, to=200, textvariable=y_var, width=6).pack(side=LEFT, padx=(0, 12))
|
||
|
||
# 中部:左侧配置 + 右侧日志/预览(支持拖拽调整宽度;左侧可滚动)
|
||
mid = ttk.PanedWindow(root, orient="horizontal")
|
||
mid.pack(fill=BOTH, expand=True, padx=12, pady=(0, 12))
|
||
|
||
left_wrap = ttk.Frame(mid)
|
||
right = ttk.Frame(mid)
|
||
mid.add(left_wrap, weight=0)
|
||
mid.add(right, weight=1)
|
||
|
||
left_canvas = tk.Canvas(left_wrap, highlightthickness=0, borderwidth=0)
|
||
left_scroll = ttk.Scrollbar(left_wrap, orient="vertical", command=left_canvas.yview)
|
||
left_canvas.configure(yscrollcommand=left_scroll.set)
|
||
left_scroll.pack(side=RIGHT, fill=Y)
|
||
left_canvas.pack(side=LEFT, fill=BOTH, expand=True)
|
||
|
||
left = ttk.Frame(left_canvas)
|
||
_left_win = left_canvas.create_window((0, 0), window=left, anchor="nw")
|
||
|
||
def _left_on_configure(_evt=None):
|
||
left_canvas.configure(scrollregion=left_canvas.bbox("all"))
|
||
|
||
def _left_on_canvas_configure(evt):
|
||
try:
|
||
left_canvas.itemconfigure(_left_win, width=evt.width)
|
||
except Exception:
|
||
pass
|
||
|
||
left.bind("<Configure>", _left_on_configure)
|
||
left_canvas.bind("<Configure>", _left_on_canvas_configure)
|
||
|
||
# 配置区
|
||
cfg = read_config()
|
||
needswitch_var = tk.BooleanVar(value=True)
|
||
wait_minutes_var = tk.IntVar(value=5)
|
||
|
||
min_value_var = tk.DoubleVar(value=float(cfg.get("min_prize_value_yuan", 0) or 0))
|
||
min_participants_var = tk.IntVar(value=int(cfg.get("min_participants", 0) or 0))
|
||
max_participants_var = tk.IntVar(value=int(cfg.get("max_participants", 0) or 0))
|
||
skip_lt_seconds_var = tk.IntVar(value=int(cfg.get("skip_if_countdown_lt_seconds", 15) or 15))
|
||
reset_after_swipes_var = tk.IntVar(value=int(cfg.get("reset_after_swipes", 15) or 15))
|
||
# 按需求:删除“自动养号/随机等待/轻微扰动/定时休息”等设置,仅保留“推荐页养号(爱心/收藏/评论)”配置。
|
||
auto_join_var = tk.BooleanVar(value=bool(cfg.get("auto_join_fansclub", False)))
|
||
fansclub_action_var = tk.StringVar(value=str(cfg.get("fansclub_fail_action", "stay") or "stay").lower())
|
||
|
||
# 推荐页养号:爱心/收藏/评论(基于图标模板匹配 + 坐标点击)
|
||
yg_recommend_duration_var = tk.IntVar(value=int(cfg.get("yanghao_recommend_duration_seconds", 60) or 60))
|
||
yg_recommend_interval_var = tk.IntVar(value=int(cfg.get("yanghao_recommend_interval_seconds", 0) or 0))
|
||
yg_like_prob_var = tk.DoubleVar(value=float(cfg.get("yanghao_like_prob", 0.0) or 0.0))
|
||
yg_fav_prob_var = tk.DoubleVar(value=float(cfg.get("yanghao_fav_prob", 0.0) or 0.0))
|
||
yg_comment_prob_var = tk.DoubleVar(value=float(cfg.get("yanghao_comment_prob", 0.0) or 0.0))
|
||
yg_icon_roi_size_var = tk.IntVar(value=int(cfg.get("yanghao_icon_roi_size", 240) or 240))
|
||
yg_icon_match_threshold_var = tk.DoubleVar(value=float(cfg.get("yanghao_icon_match_threshold", 0.72) or 0.72))
|
||
yg_step_screenshot_var = tk.BooleanVar(value=bool(cfg.get("yanghao_step_screenshot", False)))
|
||
yg_like_roi_offset_x_var = tk.IntVar(value=int(cfg.get("yanghao_like_roi_offset_x", 0) or 0))
|
||
yg_like_roi_offset_y_var = tk.IntVar(value=int(cfg.get("yanghao_like_roi_offset_y", 0) or 0))
|
||
yg_fav_roi_offset_x_var = tk.IntVar(value=int(cfg.get("yanghao_fav_roi_offset_x", 0) or 0))
|
||
yg_fav_roi_offset_y_var = tk.IntVar(value=int(cfg.get("yanghao_fav_roi_offset_y", 0) or 0))
|
||
|
||
run_box = ttk.LabelFrame(left, text="运行设置")
|
||
run_box.pack(fill=X, pady=(0, 10))
|
||
|
||
r0 = ttk.Frame(run_box)
|
||
r0.pack(fill=X, padx=10, pady=(10, 6))
|
||
ttk.Checkbutton(r0, text="允许切换直播间", variable=needswitch_var).pack(side=LEFT)
|
||
|
||
r1 = ttk.Frame(run_box)
|
||
r1.pack(fill=X, padx=10, pady=(0, 10))
|
||
ttk.Label(r1, text="倒计时阈值(分钟):").pack(side=LEFT)
|
||
ttk.Spinbox(r1, from_=1, to=60, textvariable=wait_minutes_var, width=6).pack(side=LEFT, padx=(0, 12))
|
||
ttk.Label(r1, text="倒计时小于(秒)跳过:").pack(side=LEFT)
|
||
ttk.Spinbox(r1, from_=0, to=120, textvariable=skip_lt_seconds_var, width=6).pack(side=LEFT)
|
||
|
||
r2 = ttk.Frame(run_box)
|
||
r2.pack(fill=X, padx=10, pady=(0, 10))
|
||
ttk.Label(r2, text="切换N次后回到第一个:").pack(side=LEFT)
|
||
ttk.Spinbox(r2, from_=0, to=9999, textvariable=reset_after_swipes_var, width=6).pack(side=LEFT)
|
||
ttk.Label(r2, text="(0=不启用;触发后会下滑回退)").pack(side=LEFT)
|
||
|
||
# 说明:推荐页养号流程始终启用;具体养号动作请在下方“推荐页养号(爱心/收藏/评论)”配置。
|
||
|
||
yg_box = ttk.LabelFrame(left, text="推荐页养号(爱心/收藏/评论)")
|
||
yg_box.pack(fill=X, pady=(0, 10))
|
||
|
||
yg0 = ttk.Frame(yg_box)
|
||
yg0.pack(fill=X, padx=10, pady=(10, 8))
|
||
ttk.Checkbutton(yg0, text="逐步截图(调试用,生成 pic/*/latest.png)", variable=yg_step_screenshot_var).pack(side=LEFT)
|
||
|
||
yg_time = ttk.Frame(yg_box)
|
||
yg_time.pack(fill=X, padx=10, pady=(0, 8))
|
||
ttk.Label(yg_time, text="养号时长(秒):").pack(side=LEFT)
|
||
ttk.Spinbox(yg_time, from_=1, to=3600, increment=5, textvariable=yg_recommend_duration_var, width=8).pack(side=LEFT)
|
||
ttk.Label(yg_time, text="养号间隔(秒):").pack(side=LEFT, padx=(12, 0))
|
||
ttk.Spinbox(yg_time, from_=0, to=3600, increment=10, textvariable=yg_recommend_interval_var, width=8).pack(side=LEFT)
|
||
ttk.Label(yg_time, text="(0=每次触发都执行)").pack(side=LEFT, padx=(6, 0))
|
||
|
||
yg1 = ttk.Frame(yg_box)
|
||
yg1.pack(fill=X, padx=10, pady=(0, 8))
|
||
ttk.Label(yg1, text="爱心概率:").pack(side=LEFT)
|
||
ttk.Spinbox(yg1, from_=0.0, to=1.0, increment=0.05, textvariable=yg_like_prob_var, width=6).pack(side=LEFT)
|
||
ttk.Label(yg1, text="收藏概率:").pack(side=LEFT, padx=(10, 0))
|
||
ttk.Spinbox(yg1, from_=0.0, to=1.0, increment=0.05, textvariable=yg_fav_prob_var, width=6).pack(side=LEFT)
|
||
ttk.Label(yg1, text="评论概率:").pack(side=LEFT, padx=(10, 0))
|
||
ttk.Spinbox(yg1, from_=0.0, to=1.0, increment=0.05, textvariable=yg_comment_prob_var, width=6).pack(side=LEFT)
|
||
ttk.Label(yg1, text="(0~1)").pack(side=LEFT, padx=(6, 0))
|
||
|
||
yg2 = ttk.Frame(yg_box)
|
||
yg2.pack(fill=X, padx=10, pady=(0, 8))
|
||
ttk.Label(yg2, text="图标ROI大小(px):").pack(side=LEFT)
|
||
ttk.Spinbox(yg2, from_=80, to=600, increment=10, textvariable=yg_icon_roi_size_var, width=6).pack(side=LEFT)
|
||
ttk.Label(yg2, text="匹配阈值:").pack(side=LEFT, padx=(10, 0))
|
||
ttk.Spinbox(yg2, from_=0.0, to=1.0, increment=0.01, textvariable=yg_icon_match_threshold_var, width=6).pack(side=LEFT)
|
||
|
||
yg3 = ttk.Frame(yg_box)
|
||
yg3.pack(fill=X, padx=10, pady=(0, 10))
|
||
ttk.Label(yg3, text="爱心ROI偏移(x,y):").pack(side=LEFT)
|
||
ttk.Spinbox(yg3, from_=-300, to=300, increment=5, textvariable=yg_like_roi_offset_x_var, width=6).pack(side=LEFT)
|
||
ttk.Label(yg3, text=",").pack(side=LEFT)
|
||
ttk.Spinbox(yg3, from_=-300, to=300, increment=5, textvariable=yg_like_roi_offset_y_var, width=6).pack(side=LEFT)
|
||
ttk.Label(yg3, text=" 收藏ROI偏移(x,y):").pack(side=LEFT, padx=(10, 0))
|
||
ttk.Spinbox(yg3, from_=-300, to=300, increment=5, textvariable=yg_fav_roi_offset_x_var, width=6).pack(side=LEFT)
|
||
ttk.Label(yg3, text=",").pack(side=LEFT)
|
||
ttk.Spinbox(yg3, from_=-300, to=300, increment=5, textvariable=yg_fav_roi_offset_y_var, width=6).pack(side=LEFT)
|
||
|
||
# 删除自动养号后,无需联动控件
|
||
|
||
cfg_box = ttk.LabelFrame(left, text="筛选设置")
|
||
cfg_box.pack(fill=X, pady=(0, 10))
|
||
|
||
row = ttk.Frame(cfg_box)
|
||
row.pack(fill=X, padx=10, pady=(10, 8))
|
||
ttk.Label(row, text="最低价值(元):").pack(side=LEFT)
|
||
ttk.Spinbox(row, from_=0, to=99999, increment=1, textvariable=min_value_var, width=10).pack(side=LEFT)
|
||
|
||
rowp = ttk.Frame(cfg_box)
|
||
rowp.pack(fill=X, padx=10, pady=(0, 8))
|
||
ttk.Label(rowp, text="参与人数范围:").pack(side=LEFT)
|
||
ttk.Spinbox(rowp, from_=0, to=99999999, increment=1, textvariable=min_participants_var, width=10).pack(side=LEFT)
|
||
ttk.Label(rowp, text=" ~ ").pack(side=LEFT)
|
||
ttk.Spinbox(rowp, from_=0, to=99999999, increment=1, textvariable=max_participants_var, width=10).pack(side=LEFT)
|
||
ttk.Label(rowp, text="(填0表示不限制)").pack(side=LEFT)
|
||
|
||
row2 = ttk.Frame(cfg_box)
|
||
row2.pack(fill=X, padx=10, pady=(0, 8))
|
||
ttk.Checkbutton(row2, text="自动加入粉丝团(谨慎:可能消耗钻石)", variable=auto_join_var).pack(side=LEFT)
|
||
|
||
row3 = ttk.Frame(cfg_box)
|
||
row3.pack(fill=X, padx=10, pady=(0, 10))
|
||
ttk.Label(row3, text="粉丝团失败策略:").pack(side=LEFT)
|
||
ttk.Combobox(row3, textvariable=fansclub_action_var, values=["stay", "switch"], width=10, state="readonly").pack(side=LEFT)
|
||
|
||
kw_box = ttk.LabelFrame(left, text="关键词(每行一个)")
|
||
kw_box.pack(fill=BOTH, expand=True)
|
||
|
||
ttk.Label(kw_box, text="想要 contains_want").pack(anchor="w", padx=10, pady=(8, 4))
|
||
want_text = ScrolledText(kw_box, height=8)
|
||
want_text.pack(fill=X, padx=10)
|
||
|
||
ttk.Label(kw_box, text="不想要 contains_not_want").pack(anchor="w", padx=10, pady=(10, 4))
|
||
not_want_text = ScrolledText(kw_box, height=8)
|
||
not_want_text.pack(fill=X, padx=10, pady=(0, 10))
|
||
|
||
def load_config_to_ui():
|
||
nonlocal cfg
|
||
cfg = read_config()
|
||
yg_recommend_duration_var.set(int(cfg.get("yanghao_recommend_duration_seconds", 60) or 60))
|
||
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_lt_seconds_var.set(int(cfg.get("skip_if_countdown_lt_seconds", 15) or 15))
|
||
reset_after_swipes_var.set(int(cfg.get("reset_after_swipes", 15) or 15))
|
||
# 自动养号相关配置已删除
|
||
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())
|
||
|
||
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_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))
|
||
|
||
want = cfg.get("contains_want", []) or []
|
||
not_want = cfg.get("contains_not_want", []) 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))
|
||
|
||
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()]
|
||
|
||
cfg2 = read_config()
|
||
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_lt_seconds"] = int(skip_lt_seconds_var.get() or 15)
|
||
cfg2["reset_after_swipes"] = int(reset_after_swipes_var.get() or 0)
|
||
# 自动养号相关配置已删除(推荐页养号流程在程序内固定启用)
|
||
cfg2["auto_join_fansclub"] = bool(auto_join_var.get())
|
||
cfg2["fansclub_fail_action"] = str(fansclub_action_var.get() or "stay").lower()
|
||
|
||
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_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)
|
||
write_config(cfg2)
|
||
on_line("[配置] 已保存到 config.json")
|
||
|
||
load_config_to_ui()
|
||
|
||
btns = ttk.Frame(left)
|
||
btns.pack(fill=X, pady=(10, 0))
|
||
ttk.Button(btns, text="加载配置", command=load_config_to_ui).pack(side=LEFT, padx=(0, 8))
|
||
ttk.Button(btns, text="保存配置", command=save_ui_to_config).pack(side=LEFT)
|
||
|
||
# 右侧:Notebook(日志 / 截图预览)
|
||
notebook = ttk.Notebook(right)
|
||
notebook.pack(fill=BOTH, expand=True)
|
||
|
||
log_tab = ttk.Frame(notebook)
|
||
preview_tab = ttk.Frame(notebook)
|
||
notebook.add(log_tab, text="运行日志")
|
||
notebook.add(preview_tab, text="截图预览")
|
||
|
||
# 日志区
|
||
log_box = ttk.Frame(log_tab)
|
||
log_box.pack(fill=BOTH, expand=True)
|
||
log_text = ScrolledText(log_box)
|
||
try:
|
||
log_text.configure(font=("Consolas", 10))
|
||
except Exception:
|
||
pass
|
||
log_text.pack(fill=BOTH, expand=True, padx=10, pady=10)
|
||
|
||
# 截图预览
|
||
preview_top = ttk.Frame(preview_tab)
|
||
preview_top.pack(fill=X, padx=10, pady=10)
|
||
|
||
images_dir = os.path.join(os.path.dirname(__file__), "pic")
|
||
image_choices = [
|
||
"screenshot.png",
|
||
"fudai_content.png",
|
||
"fudai_countdown.png",
|
||
"fudai_value.png",
|
||
"zhibo_yanzheng.png",
|
||
]
|
||
image_var = tk.StringVar(value="fudai_value.png")
|
||
|
||
ttk.Label(preview_top, text="选择图片:").pack(side=LEFT)
|
||
# 允许手工输入子路径(例如 start/latest.png),方便查看逐步截图
|
||
ttk.Combobox(preview_top, textvariable=image_var, values=image_choices, width=24, state="normal").pack(
|
||
side=LEFT, padx=(0, 10)
|
||
)
|
||
|
||
preview_status = tk.StringVar(value="")
|
||
ttk.Label(preview_top, textvariable=preview_status).pack(side=RIGHT)
|
||
|
||
preview_body = ttk.Frame(preview_tab)
|
||
preview_body.pack(fill=BOTH, expand=True, padx=10, pady=(0, 10))
|
||
|
||
image_label = ttk.Label(preview_body)
|
||
image_label.pack(fill=BOTH, expand=True)
|
||
_img_ref = {"photo": None} # 防止 PhotoImage 被回收
|
||
|
||
def _load_and_fit_image(img_path: str):
|
||
if not os.path.exists(img_path):
|
||
preview_status.set(f"未找到:{os.path.basename(img_path)}")
|
||
image_label.configure(image="")
|
||
_img_ref["photo"] = None
|
||
return
|
||
|
||
img = Image.open(img_path).convert("RGB")
|
||
w = preview_body.winfo_width() or 900
|
||
h = preview_body.winfo_height() or 520
|
||
max_w = max(300, w - 20)
|
||
max_h = max(200, h - 20)
|
||
img.thumbnail((max_w, max_h), Image.LANCZOS)
|
||
photo = ImageTk.PhotoImage(img)
|
||
_img_ref["photo"] = photo
|
||
image_label.configure(image=photo)
|
||
preview_status.set(f"{os.path.basename(img_path)} {img.width}x{img.height}")
|
||
|
||
def refresh_preview():
|
||
name = image_var.get().strip() or "fudai_value.png"
|
||
path = os.path.join(images_dir, name)
|
||
_load_and_fit_image(path)
|
||
|
||
ttk.Button(preview_top, text="刷新预览", command=refresh_preview).pack(side=LEFT)
|
||
|
||
def open_pic_folder():
|
||
try:
|
||
os.makedirs(images_dir, exist_ok=True)
|
||
os.startfile(images_dir) # type: ignore[attr-defined]
|
||
except Exception as e:
|
||
on_line(f"[预览] 打开图片目录失败:{e}")
|
||
|
||
ttk.Button(preview_top, text="打开pic目录", command=open_pic_folder).pack(side=LEFT, padx=(10, 0))
|
||
|
||
status_var = tk.StringVar(value="就绪")
|
||
|
||
def get_params() -> RunParams:
|
||
return RunParams(
|
||
device_id=device_var.get().strip(),
|
||
y_pianyi=int(y_var.get()),
|
||
needswitch=bool(needswitch_var.get()),
|
||
wait_minutes=int(wait_minutes_var.get()),
|
||
skip_if_countdown_lt_seconds=int(skip_lt_seconds_var.get() or 15),
|
||
reset_after_swipes=int(reset_after_swipes_var.get() or 0),
|
||
min_prize_value_yuan=float(min_value_var.get() or 0),
|
||
min_participants=int(min_participants_var.get() or 0),
|
||
max_participants=int(max_participants_var.get() or 0),
|
||
auto_join_fansclub=bool(auto_join_var.get()),
|
||
fansclub_fail_action=str(fansclub_action_var.get() or "stay").lower(),
|
||
)
|
||
|
||
def start_run():
|
||
if runner.is_running():
|
||
on_line("[运行] 已在运行中")
|
||
return
|
||
save_ui_to_config()
|
||
params = get_params()
|
||
on_line(
|
||
f"[运行] 启动:device={params.device_id or '(auto)'} y={params.y_pianyi} "
|
||
f"needswitch={params.needswitch} wait={params.wait_minutes}m "
|
||
f"skip_lt={params.skip_if_countdown_lt_seconds}s reset_after={params.reset_after_swipes} "
|
||
f"value>={params.min_prize_value_yuan} participants=[{params.min_participants},{params.max_participants}] "
|
||
f"yanghao=recommend_flow_only"
|
||
)
|
||
status_var.set("运行中")
|
||
try:
|
||
runner.start(params)
|
||
except Exception as e:
|
||
status_var.set("启动失败")
|
||
on_line(f"[错误] {e}")
|
||
|
||
def stop_run():
|
||
runner.stop()
|
||
status_var.set("已停止")
|
||
|
||
actions = ttk.Frame(right)
|
||
actions.pack(fill=X, pady=(10, 0))
|
||
|
||
ttk.Button(actions, text="开始运行", command=start_run).pack(side=LEFT, padx=(0, 8))
|
||
ttk.Button(actions, text="停止", command=stop_run).pack(side=LEFT)
|
||
|
||
ttk.Separator(actions, orient="vertical").pack(side=LEFT, fill=Y, padx=10, pady=3)
|
||
test_seconds_var = tk.IntVar(value=int(cfg.get("yanghao_recommend_duration_seconds", 60) or 60))
|
||
ttk.Label(actions, text="测试养号(秒):").pack(side=LEFT)
|
||
ttk.Spinbox(actions, from_=10, to=3600, increment=10, textvariable=test_seconds_var, width=8).pack(side=LEFT, padx=(0, 8))
|
||
|
||
def start_test_yanghao():
|
||
if runner.is_running():
|
||
on_line("[运行] 已在运行中")
|
||
return
|
||
save_ui_to_config()
|
||
secs = int(test_seconds_var.get() or 90)
|
||
dev = device_var.get().strip()
|
||
on_line(f"[测试] 启动养号流程:device={dev or '(auto)'} seconds={secs}")
|
||
status_var.set("运行中")
|
||
try:
|
||
runner.start_test_yanghao_flow(dev, secs)
|
||
except Exception as e:
|
||
status_var.set("启动失败")
|
||
on_line(f"[错误] {e}")
|
||
|
||
ttk.Button(actions, text="测试养号流程", command=start_test_yanghao).pack(side=LEFT)
|
||
ttk.Label(actions, textvariable=status_var).pack(side=RIGHT)
|
||
|
||
def pump_logs():
|
||
changed = False
|
||
try:
|
||
while True:
|
||
line = q.get_nowait()
|
||
log_text.insert("end", line + "\n")
|
||
log_text.see("end")
|
||
changed = True
|
||
except queue.Empty:
|
||
pass
|
||
|
||
if changed and not runner.is_running() and status_var.get() == "运行中":
|
||
status_var.set("已结束")
|
||
|
||
root.after(100, pump_logs)
|
||
|
||
pump_logs()
|
||
root.after(300, refresh_preview)
|
||
|
||
def on_close():
|
||
try:
|
||
runner.stop()
|
||
except Exception:
|
||
pass
|
||
root.destroy()
|
||
|
||
root.protocol("WM_DELETE_WINDOW", on_close)
|
||
refresh_devices()
|
||
root.mainloop()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
try:
|
||
from version import print_version_banner
|
||
|
||
print_version_banner("gui_app")
|
||
except Exception:
|
||
pass
|
||
main()
|