From 01bff8d972dda2bb4e809701904c8ef45dc1c8e1 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sat, 19 Nov 2022 22:28:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=96=AD=E5=BC=80=E9=87=8D=E8=BF=9E=E5=90=8Eminitouch=E4=B8=8D?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistant/Controller.cpp | 24 +++++++++++++++++------- src/MeoAssistant/Controller.h | 5 +++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/MeoAssistant/Controller.cpp b/src/MeoAssistant/Controller.cpp index c740cfd02e..9f51ee28a0 100644 --- a/src/MeoAssistant/Controller.cpp +++ b/src/MeoAssistant/Controller.cpp @@ -412,6 +412,7 @@ std::optional asst::Controller::call_command(const std::string& cmd is_reconnect_success = reconnect_str.find("error") == std::string::npos; } if (is_reconnect_success) { + call_and_hup_minitouch(m_adb.call_minitouch); auto recall_ret = call_command(cmd, timeout, false /* 禁止重连避免无限递归 */, recv_by_socket); if (recall_ret) { // 重连并成功执行了 @@ -447,6 +448,8 @@ void asst::Controller::callback(AsstMsg msg, const json::value& details) bool asst::Controller::call_and_hup_minitouch(const std::string& cmd) { LogTraceFunction; + release_minitouch(true); + Log.info(cmd); m_minitouch_avaiable = false; @@ -560,9 +563,15 @@ bool asst::Controller::call_and_hup_minitouch(const std::string& cmd) bool asst::Controller::input_to_minitouch(const std::string& cmd) { +#ifdef ASST_DEBUG Log.info("Input to minitouch", Logger::separator::newline, cmd); +#endif #ifdef _WIN32 + if (m_minitouch_parent_write == INVALID_HANDLE_VALUE) { + Log.error("minitouch write handle invalid", m_minitouch_parent_write); + return false; + } DWORD written = 0; if (!WriteFile(m_minitouch_parent_write, cmd.c_str(), static_cast(cmd.size() * sizeof(std::string::value_type)), &written, NULL)) { @@ -588,17 +597,17 @@ void asst::Controller::release_minitouch(bool force) #ifdef _WIN32 - if (m_minitouch_process_info.hProcess) { + if (m_minitouch_process_info.hProcess != INVALID_HANDLE_VALUE) { CloseHandle(m_minitouch_process_info.hProcess); - m_minitouch_process_info.hProcess = nullptr; + m_minitouch_process_info.hProcess = INVALID_HANDLE_VALUE; } - if (m_minitouch_process_info.hThread) { + if (m_minitouch_process_info.hThread != INVALID_HANDLE_VALUE) { CloseHandle(m_minitouch_process_info.hThread); - m_minitouch_process_info.hThread = nullptr; + m_minitouch_process_info.hThread = INVALID_HANDLE_VALUE; } - if (m_minitouch_parent_write) { + if (m_minitouch_parent_write != INVALID_HANDLE_VALUE) { CloseHandle(m_minitouch_parent_write); - m_minitouch_parent_write = nullptr; + m_minitouch_parent_write = INVALID_HANDLE_VALUE; } #endif // _WIN32 @@ -1425,7 +1434,8 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a call_command(minitouch_cmd_rep(adb_cfg.push_minitouch)); call_command(minitouch_cmd_rep(adb_cfg.chmod_minitouch)); - call_and_hup_minitouch(minitouch_cmd_rep(adb_cfg.call_minitouch)); + m_adb.call_minitouch = minitouch_cmd_rep(adb_cfg.call_minitouch); + call_and_hup_minitouch(m_adb.call_minitouch); std::string orientation_str = call_command(cmd_replace(adb_cfg.orientation)).value_or("0"); auto [beg, end] = ranges::remove_if(orientation_str, [](char ch) -> bool { return !std::isdigit(ch); }); diff --git a/src/MeoAssistant/Controller.h b/src/MeoAssistant/Controller.h index c4bdc4b88e..89eeefee7a 100644 --- a/src/MeoAssistant/Controller.h +++ b/src/MeoAssistant/Controller.h @@ -134,6 +134,7 @@ namespace asst { /* command */ std::string connect; + std::string call_minitouch; std::string click; std::string swipe; @@ -168,9 +169,9 @@ namespace asst bool m_minitouch_avaiable = false; // 状态 #ifdef _WIN32 - HANDLE m_minitouch_parent_write = nullptr; + HANDLE m_minitouch_parent_write = INVALID_HANDLE_VALUE; ASST_AUTO_DEDUCED_ZERO_INIT_START - PROCESS_INFORMATION m_minitouch_process_info = { nullptr }; + PROCESS_INFORMATION m_minitouch_process_info = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, 0, 0 }; ASST_AUTO_DEDUCED_ZERO_INIT_END #else // TODO