添加无线 ADB 连接支持

- 扩展配置:添加 adb_wireless_host/port/auto_connect 字段
- AdbManager: 新增无线连接方法 (connect_wireless, disconnect_wireless)
- AdbManager: 实现自动重连机制 (ensure_wireless_connection)
- AdbManager: USB 优先策略,无线作为备选
- IPC: 新增 connect_wireless/disconnect_wireless 命令
- TUI: 新增无线连接对话框 (W 键)
- TUI: 设备列表显示连接类型 (USB/WiFi)
This commit is contained in:
2026-07-10 09:39:45 +08:00
parent fa0a315ba2
commit 1cde7a5d81
2 changed files with 243 additions and 13 deletions
+63 -3
View File
@@ -197,6 +197,9 @@ class TuiApp:
elif key == ord("s") or key == ord("S"):
self._dlg_select_device()
elif key == ord("w") or key == ord("W"):
self._dlg_connect_wireless()
elif key == ord("h") or key == ord("H"):
self._show_help()
@@ -309,23 +312,39 @@ class TuiApp:
if self.status:
dev = self.status.get("device") or "未选择"
conn_type = self.status.get("connection_type", "none")
conn_icon = "USB" if conn_type == "usb" else "WiFi" if conn_type == "wireless" else "---"
self._clear_line(y)
try:
self.stdscr.addstr(y, 4, f"当前设备: {dev}")
self.stdscr.addstr(f" [{conn_icon}]")
except curses.error:
pass
y += 1
# 显示无线连接配置
wireless_host = self.status.get("wireless_host", "")
wireless_port = self.status.get("wireless_port", 5555)
if wireless_host:
self._clear_line(y)
try:
self.stdscr.addstr(y, 4, f"无线配置: {wireless_host}:{wireless_port}", curses.A_DIM)
except curses.error:
pass
y += 1
if self.devices:
for d in self.devices:
if y >= h:
break
self._clear_line(y)
icon = "" if d["status"] == "device" else ""
conn_type = d.get("connection_type", "usb")
conn_icon = "USB" if conn_type == "usb" else "WiFi"
pair = 3 if d["status"] == "device" else 2
try:
self.stdscr.addstr(y, 4, f"{icon} {d['serial']}", curses.color_pair(pair))
self.stdscr.addstr(f" ({d['status']})")
self.stdscr.addstr(f" [{conn_icon}]")
except curses.error:
pass
y += 1
@@ -341,7 +360,7 @@ class TuiApp:
if y < h:
self._clear_line(y)
try:
self.stdscr.addstr(y, 4, "[S]选择设备 [R]刷新", curses.A_DIM)
self.stdscr.addstr(y, 4, "[S]选择设备 [W]无线连接 [R]刷新", curses.A_DIM)
except curses.error:
pass
return y + 1
@@ -385,6 +404,9 @@ class TuiApp:
try:
self.stdscr.addstr(y, 4, "ADB: ")
self.stdscr.addstr(f"{ar}", curses.color_pair(ar_color) | curses.A_BOLD)
conn_type = s.get("connection_type", "none")
if conn_type != "none":
self.stdscr.addstr(f" ({conn_type})")
except curses.error:
pass
y += 1
@@ -423,7 +445,7 @@ class TuiApp:
pass # show message below separator
else:
if self.connected:
msg = "已连接 | ↑↓/jk 选择 A新增 E编辑 D删除 S选设备 H帮助"
msg = "已连接 | ↑↓/jk 选择 A新增 E编辑 D删除 S选设备 W无线 H帮助"
else:
msg = "未检测到守护进程 | T 尝试连接"
try:
@@ -603,6 +625,43 @@ class TuiApp:
else:
self.msg(f"选择失败: {r.get('error', '')}")
def _dlg_connect_wireless(self):
"""无线连接对话框。"""
# 获取当前无线配置作为默认值
wireless_host = ""
wireless_port = "5555"
if self.status:
wireless_host = self.status.get("wireless_host", "")
wireless_port = str(self.status.get("wireless_port", 5555))
# 输入 IP 地址
host = self._dlg_input("无线设备 IP 地址:", wireless_host)
if not host:
return
# 输入端口
port_str = self._dlg_input("端口号:", wireless_port)
if not port_str:
return
try:
port = int(port_str)
if not (1 <= port <= 65535):
self.msg("端口范围错误 (1-65535)")
return
except ValueError:
self.msg("端口格式错误")
return
# 发送连接请求
self.msg(f"正在连接 {host}:{port} ...")
r = self.client.send("connect_wireless", host=host, port=port)
if r.get("ok"):
self.msg(f"无线设备已连接: {host}:{port}")
self.refresh()
else:
self.msg(f"连接失败: {r.get('error', '未知错误')}")
@staticmethod
def _validate_time(tstr: str) -> bool:
try:
@@ -631,6 +690,7 @@ class TuiApp:
" E 编辑选中时间段",
" D 删除选中时间段",
" S 选择 ADB 设备",
" W 无线连接设备",
" R 刷新状态",
" L 重载守护进程配置",
" F 强制息屏",