Commit Graph
18 Commits
Author SHA1 Message Date
Your Name 84b9143fa6 Fallback WiFi ADB connect to mdns port 2026-06-23 01:08:03 +08:00
Your Name 5c98bb8353 Support reconnecting multiple WiFi ADB devices 2026-06-23 00:25:56 +08:00
Your Name 6279b129cb scan wifi adb random port across subnets 2026-06-08 18:17:29 +08:00
Your Name cd7615db3c limit wifi adb reconnect to lightweight ports 2026-06-05 15:45:37 +08:00
Your Name bcc4d1151f 修复WiFi ADB随机端口扫描 2026-06-03 17:52:02 +08:00
Your Name 24b58a8c6d 优化WiFi ADB快速扫描 2026-06-03 08:50:43 +08:00
Your Name 1d37d57c90 修复福袋详情OCR v2与调试日志 2026-06-03 01:22:13 +08:00
Your Name 36e374ef67 refactor: split large modules and harden live-room fudai flow 2026-06-01 18:39:44 +08:00
Your Name a68307d7fd fix(wifi-adb): restore hi-port fallback path and harden reconnect/import edge cases 2026-06-01 11:05:47 +08:00
Your Name e33b42597c fix(wifi-adb): force openscreen mdns backend for scan discovery 2026-06-01 09:49:32 +08:00
Your Name f76232f2fc fix(wifi-adb): improve scan with multi-subnet fallback and mdns discovery 2026-06-01 09:40:44 +08:00
CodexandClaude Opus 4.7 3b8f85b9cb refactor(gui_core): 抽 _update_stats_from_line 解析逻辑到 stats_log_parser (1207 → 541)
Runner._update_stats_from_line 是 666 行的"日志行 → 计数器更新"巨型方法。
按业务事件分类 14 个独立段(福袋字段 / 打开-参与计数器 / 跳过原因 /
错误统计 / 粉丝团 / 预约 / 开奖结果 / 直播间切换 / 阶段诊断 / OCR / 性能 /
详情识别 / 福袋查找 / 回退操作)。

抽到 gui/gui_core_pkg/stats_log_parser.py:
- update_stats_from_line(runner, line) 主入口
- 14 个 _parse_* 子函数按事件分组
- 通过 runner.* 调用保持与原 Runner 方法/状态一致

Runner._update_stats_from_line 从 666 行变成 4 行委托。模块级测试更易于
单独覆盖各分类的解析逻辑。

1408 passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 03:35:04 +08:00
CodexandClaude Opus 4.7 52b811d0cb feat(scan): WiFi-ADB 扫描支持自定义/多端口(覆盖 Android 11+ 随机端口)
之前只扫 5555。Android 11+ "无线调试" 用 37000-44999 随机端口,
固定的 adb tcpip 也可改端口。新接口让扫描适配任意端口规格。

新增 parse_port_spec:解析端口规格字符串
  - 5555            单端口
  - "5555,5556"     逗号分隔
  - "37000-37010"   范围(最大 1024 个)
  - 混合格式与序列输入
  - 非法/越界 → 退化为默认 5555
  - 单个范围 > 1024 端口直接忽略,避免误扫整个端口段

scan_open_ports 重构:
  - 接受 ports 参数(list[int]),传 ports 时优先于旧 port=int
  - 返回 list[(ip, port)] 而不是 list[ip],按 (IP 数值序, port 升序) 稳定排序

discover_adb_devices 支持 ports 参数,按 (ip, port) 逐个 verify_adb_target

接入 GUI 与 webui:
  - gui_app.py 扫描对话框新增"端口"输入框 + 提示
  - gui_app.py 启动重连:上次端口非 5555 时把它一并扫描
  - web_gui.py /api/wifi/scan 接受 ports;/api/wifi/auto-reconnect 同上次端口逻辑

新增 13 个 parse_port_spec 单测 + 4 个 scan_open_ports 多端口测试 +
2 个 discover_adb_devices 多端口集成测试。
真机验证:6 端口 (5555 + 37000-37005) × 254 IP,~8.5s 扫完,
正确发现 192.168.5.2:5555 (PEPM00)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 01:02:48 +08:00
CodexandClaude Opus 4.7 5966f461c3 feat(wifi_adb): 启动重连失败时自动扫描子网 + 智能匹配
新增 pick_best_match(devs, last) 纯函数,按优先级匹配上次设备:
1. target 完全一致(IP 没换)
2. 同 model + 同 port(换 IP 但同一台手机)—— 多台同型号时返回 None 让用户选
3. 同主机段 + 同 port(弱兜底,仅唯一时返回)
4. 唯一一台 connected(扫到就一台时认定)

GUI _try_reconnect_last_wifi 流程升级:
- verify_adb_target 失败(不可达)→ 自动 discover_adb_devices 扫子网
- pick_best_match 命中 → 选中 + 更新 last_wifi_target
- 命中且 IP 已变 → 日志写"上次目标 X 已变 → 智能匹配到 Y(已更新记忆)"
- 没命中 → 列出候选 + 提示点'扫描 WiFi'手选

实际场景:换 WiFi 网段(家里 → 公司 / 192.168.1 → 192.168.5)后
GUI 启动时自动找回同一台手机,无需任何手动操作。

新增 15 个 pick_best_match 单元测试覆盖所有规则 + 边界。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 20:46:23 +08:00
CodexandClaude Opus 4.7 a71f6faed0 feat(wifi_adb): 记住上次成功的 WiFi 设备,GUI 启动时自动重连
新增 gui/gui_core_pkg/config.py 三个 helper:
- get_last_wifi_target  / set_last_wifi_target / clear_last_wifi_target
配置以 last_wifi_target = {target, model, saved_at} 形式存在 config.json 顶层。

GUI 行为:
- "扫描 WiFi" 选中或自动连上一台 connected 设备 → 写入 last_wifi_target
- WiFi 选择对话框"使用选中"也写入
- 主窗口启动后延迟 300ms 后台尝试 verify_adb_target(last.target)
  - 已有设备:不打扰
  - 重连成功:自动设为当前设备
  - unauthorized:提示需手机端授权
  - 不可达:提示换网了,引导点'扫描 WiFi'

新增 12 个 last_wifi_target 单元测试覆盖读写/清除/损坏值/缺文件等场景。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 20:16:37 +08:00
CodexandClaude Opus 4.7 e89393693b feat(wifi_adb): 加局域网 ADB 设备扫描发现
新增 gui/gui_core_pkg/wifi_adb_scan.py(356 行):
- get_local_subnet:从本机 WLAN 出口 IP 推 /24 子网
- parse_subnet_spec:解析 192.168.5.0/24 / 192.168.5.1-100 / 192.168.5.5 / 逗号组合
- probe_adb_port:并发 TCP 探测(默认 0.3s 超时,64 线程并发)
- verify_adb_target:对每个开放端口的 IP 调 adb connect 区分 connected / unauthorized / failed
- discover_adb_devices:主入口,端到端只需 1.5 秒扫完 /24

GUI(gui/gui_app.py)"扫描局域网"按钮加在 WiFi 设备操作区:
- 自动推子网(默认)+ 手动输入支持 CIDR / 范围 / 单 IP / 逗号
- 后台线程扫描,进度条 + 阶段提示
- 列表展示 IP / 状态 / 设备型号 / adb connect 输出,列表中手动选
- 选中已 connected 的设备 → 回填 IP 到主对话框
- unauthorized 设备明确提示需手机端授权

新增 25 个 wifi_adb_scan 单元测试。真机端到端验证通过:1.5s 扫完
192.168.5.0/24 子网,发现 192.168.5.2:5555(PEPM00)connected。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 19:59:19 +08:00
CodexandClaude Opus 4.7 23d370ae22 fix(wifi_adb): 修 3 处导致 WiFi-ADB 自动连接失败的解析 bug
1) get_device_ip 把 ip route 输出里的网段当 IP 返回
   原代码看到 "192.168.5.0/24 ... src 192.168.5.2" 时,扫到的第一个含 3 个点的字段是
   "192.168.5.0/24",结果用 0/24 当 IP 调 adb connect 必然失败。
   改成显式从 "src <ip>" 取,并优先 wlan 接口;加 ip addr show / ifconfig 兜底。

2) auto_connect_wifi_adb 顺序错误
   原代码先 tcpip 5555(让设备 adbd 重启、USB 链路断开)再 get_device_ip(需要 USB),
   USB 已断必然取不到 IP。改成先 get_device_ip 再 enable_wifi_adb 再 connect。

3) connect_wifi_adb 把"未授权 / 连接被拒"当成功
   adb connect 在 unauthorized / cannot connect / failed to authenticate 等场景下
   returncode 也是 0;以前只看 returncode + "connected" 子串,未授权也判成功。
   改成显式列出失败关键词,并对未授权给清晰的中文提示。

新增 20 个 wifi_adb 单元测试覆盖 3 处回归场景。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 19:32:04 +08:00
CodexandClaude Opus 4.7 ef6ca4a650 拆分 gui_core (1594 → 4 子模块 + 1207 行原文件保留 Runner)
把 gui/gui_core.py 中 12 个独立顶层函数 + RunParams dataclass 拆出到
gui/gui_core_pkg/ 子包;Runner 巨型类(1164 行 / 13 实例方法 / 用 self
状态)原文件保留,仅做 import re-export。

新建子包:
- adb (79)         find_adb_executable / list_adb_devices / resolve_adb_device
- wifi_adb (323)   7 个 WiFi-ADB 函数
- config (46)      CONFIG_PATH / read_config / write_config
- run_params (45)  RunParams dataclass

策略:Runner 类内部用了 find_adb_executable 等顶层函数,所以原文件
``gui/gui_core.py`` 通过 ``from gui.gui_core_pkg import *`` re-export
14 个公共符号供 Runner 内部和外部代码继续使用。

外部 import 路径全部不变:
``from gui.gui_core import find_adb_executable / RunParams / Runner`` 等
所有 14 个公共符号都保留。
- find_adb_executable 20 处外部引用 / read_config 17 处 / list_adb_devices
  16 处 / 其他 1-7 处,全部不需修改

回归:
- 5 个新文件 + 改写后 gui_core.py compileall 通过
- pytest 353 passed / 1 skipped
- find_adb_executable() 调用正常返回 adb.EXE 绝对路径
- read_config() 读到 126 个 config keys
- RunParams.is_dataclass = True,28 个字段
- Runner 类正确暴露

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 18:49:05 +08:00