diff --git a/src/MaaCore/Controller/AdbController.cpp b/src/MaaCore/Controller/AdbController.cpp index db432bfe8b..6e3745ee14 100644 --- a/src/MaaCore/Controller/AdbController.cpp +++ b/src/MaaCore/Controller/AdbController.cpp @@ -912,38 +912,41 @@ bool asst::AdbController::connect(const std::string& adb_path, const std::string } } - // 如果不包含 `:` 且需要连接,connect 命令也不会成功 - if (address.find(':') == std::string::npos && need_connect) { - json::value info = get_info_json() | json::object { - { "what", "ConnectFailed" }, - { "why", "Address does not contain ':' and no devices found" }, - }; - callback(AsstMsg::ConnectionInfo, info); - return false; - } - - // TODO: adb lite server 尚未实现,第一次连接需要执行一次 adb.exe 启动 daemon + // 设置配置 connect、release 命令,即使这里不连接,后续也会需要用到 m_adb.connect = m_conn_ctx.replace_cmd(adb_cfg.connect); m_adb.release = m_conn_ctx.replace_cmd(adb_cfg.release); - auto connect_ret = call_command(m_adb.connect, 60LL * 1000, false /* adb 连接时不允许重试 */); - bool is_connect_success = false; - if (connect_ret) { - auto& connect_str = connect_ret.value(); - // 检查连接字符串是否包含 "connected" - is_connect_success = connect_str.find("connected") != std::string::npos; - // NOTE:这玩意啥都没干,有什么用吗? - if (connect_str.find("daemon started successfully") != std::string::npos && - connect_str.find("daemon still not running") == std::string::npos) { + if (need_connect) { + // 如果不包含 `:` 且需要连接,connect 命令也不会成功 + if (address.find(':') == std::string::npos) { + json::value info = get_info_json() | json::object { + { "what", "ConnectFailed" }, + { "why", "Cannot connect: address appears to be serial number but device not found" }, + }; + callback(AsstMsg::ConnectionInfo, info); + return false; } - } - if (!is_connect_success && need_connect) { - json::value info = get_info_json() | json::object { - { "what", "ConnectFailed" }, - { "why", "Connection command failed to exec" }, - }; - callback(AsstMsg::ConnectionInfo, info); - return false; + auto connect_ret = call_command(m_adb.connect, 60LL * 1000, false /* adb 连接时不允许重试 */); + if (connect_ret) { + auto& connect_str = connect_ret.value(); + // 检查连接字符串是否包含 "connected" + if (connect_str.find("connected") == std::string::npos) { + json::value info = get_info_json() | json::object { + { "what", "ConnectFailed" }, + { "why", "Connection command did not report \"connected\"" }, + }; + callback(AsstMsg::ConnectionInfo, info); + return false; + } + } + else { + json::value info = get_info_json() | json::object { + { "what", "ConnectFailed" }, + { "why", "Connection command failed to exec" }, + }; + callback(AsstMsg::ConnectionInfo, info); + return false; + } } }