From 20e438ee13ebf6ad2fb58f1a113827ef3abc24b3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 23 Jun 2026 00:29:34 +0800 Subject: [PATCH] Clarify WiFi ADB scan failure hint --- gui/components/wifi_adb_one_click_scan.py | 8 +++-- tests/test_wifi_adb_one_click_scan.py | 37 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/test_wifi_adb_one_click_scan.py diff --git a/gui/components/wifi_adb_one_click_scan.py b/gui/components/wifi_adb_one_click_scan.py index 03f73d8..87321de 100644 --- a/gui/components/wifi_adb_one_click_scan.py +++ b/gui/components/wifi_adb_one_click_scan.py @@ -59,12 +59,16 @@ def _handle_scan_result( if len(connected) == 0 and len(unauthorized) == 0 and failed: # 端口开放但 adb connect 失败:通常是 adb 服务异常 / 设备处于诡异状态。 # 把 adb 真实返回拼出来,让用户看到根因,而不是误导地说"请授权"。 + failed_targets = [] for d in failed: msg = (d.message or "").strip().replace("\n", " | ") + failed_targets.append(str(d.target or "").strip()) on_line(f"[扫描] {d.target} 连接失败 (state=failed): {msg or '未知错误'}") + sample_target = next((t for t in failed_targets if t), "") on_line( - "[扫描] 提示:可在终端跑 `adb kill-server && adb connect ` 看真实输出," - "或检查是否多个 adb 进程冲突" + f"[扫描] 提示:多台 WiFi ADB 可同时在线;失败时先逐个执行 " + f"`adb connect {sample_target}` 和 `adb devices -l` 看真实状态," + "若 adb server 状态异常再执行 `adb kill-server` 后重试" ) return diff --git a/tests/test_wifi_adb_one_click_scan.py b/tests/test_wifi_adb_one_click_scan.py new file mode 100644 index 0000000..82704d5 --- /dev/null +++ b/tests/test_wifi_adb_one_click_scan.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +from types import SimpleNamespace + +from gui.components.wifi_adb_one_click_scan import _handle_scan_result + + +class _Var: + def __init__(self): + self.value = "" + + def set(self, value): + self.value = value + + +def test_failed_scan_hint_mentions_multi_target_connect_without_saying_multiple_adb_conflict(): + logs: list[str] = [] + devs = [ + SimpleNamespace( + target="192.168.10.105:44219", + adb_state="failed", + message="cannot connect", + ) + ] + + _handle_scan_result( + devs, + on_line=logs.append, + device_var=_Var(), + refresh_devices=lambda: None, + open_pick_dialog=lambda _devs: None, + ) + + hint = "\n".join(logs) + assert "adb connect 192.168.10.105:44219" in hint + assert "adb devices -l" in hint + assert "多个 adb 进程冲突" not in hint