feat: auto retry start on app startup crash (#8966)

This commit is contained in:
Constrat
2024-05-06 22:04:26 +02:00
committed by GitHub
parent b051a46241
commit fef2f56d39
11 changed files with 394 additions and 195 deletions

View File

@@ -8,9 +8,13 @@
using asio::ip::tcp;
namespace socket_ops = asio::detail::socket_ops;
asst::PlayToolsController::PlayToolsController(const AsstCallback& callback, Assistant* inst,
PlatformType type [[maybe_unused]])
: InstHelper(inst), m_callback(callback), m_socket(m_context)
asst::PlayToolsController::PlayToolsController(
const AsstCallback& callback,
Assistant* inst,
PlatformType type [[maybe_unused]])
: InstHelper(inst)
, m_callback(callback)
, m_socket(m_context)
{
LogTraceFunction;
}
@@ -20,8 +24,10 @@ asst::PlayToolsController::~PlayToolsController()
close();
}
bool asst::PlayToolsController::connect(const std::string& adb_path [[maybe_unused]], const std::string& address,
const std::string& config [[maybe_unused]])
bool asst::PlayToolsController::connect(
const std::string& adb_path [[maybe_unused]],
const std::string& address,
const std::string& config [[maybe_unused]])
{
if (m_address != address) {
close();
@@ -42,7 +48,19 @@ const std::string& asst::PlayToolsController::get_uuid() const
return uuid;
}
bool asst::PlayToolsController::screencap(cv::Mat& image_payload, bool allow_reconnect [[maybe_unused]])
size_t asst::PlayToolsController::get_pipe_data_size() const noexcept
{
return size_t();
}
size_t asst::PlayToolsController::get_version() const noexcept
{
return size_t();
}
bool asst::PlayToolsController::screencap(
cv::Mat& image_payload,
bool allow_reconnect [[maybe_unused]])
{
LogTraceFunction;
@@ -103,8 +121,14 @@ bool asst::PlayToolsController::click(const Point& p)
return toucher_down(p) && toucher_up(p);
}
bool asst::PlayToolsController::swipe(const Point& p1, const Point& p2, int duration, bool extra_swipe, double slope_in,
double slope_out, bool with_pause [[maybe_unused]])
bool asst::PlayToolsController::swipe(
const Point& p1,
const Point& p2,
int duration,
bool extra_swipe,
double slope_in,
double slope_out,
bool with_pause [[maybe_unused]])
{
int x1 = p1.x, y1 = p1.y;
int x2 = p2.x, y2 = p2.y;
@@ -129,8 +153,10 @@ bool asst::PlayToolsController::swipe(const Point& p1, const Point& p2, int dura
}; // TODO: move this to math.hpp
const auto progressive_move = [&](int _x1, int _y1, int _x2, int _y2, int _duration) {
for (int cur_time = DefaultSwipeDelay; cur_time < _duration; cur_time += DefaultSwipeDelay) {
double progress = cubic_spline(slope_in, slope_out, static_cast<double>(cur_time) / duration);
for (int cur_time = DefaultSwipeDelay; cur_time < _duration;
cur_time += DefaultSwipeDelay) {
double progress =
cubic_spline(slope_in, slope_out, static_cast<double>(cur_time) / duration);
int cur_x = static_cast<int>(std::lerp(_x1, _x2, progress));
int cur_y = static_cast<int>(std::lerp(_y1, _y2, progress));
if (cur_x < 0 || cur_x > width || cur_y < 0 || cur_y > height) {
@@ -149,7 +175,12 @@ bool asst::PlayToolsController::swipe(const Point& p1, const Point& p2, int dura
if (extra_swipe && opt.minitouch_extra_swipe_duration > 0) {
toucher_wait(opt.minitouch_swipe_extra_end_delay); // 停留终点
progressive_move(x2, y2, x2, y2 - opt.minitouch_extra_swipe_dist, opt.minitouch_extra_swipe_duration);
progressive_move(
x2,
y2,
x2,
y2 - opt.minitouch_extra_swipe_dist,
opt.minitouch_extra_swipe_duration);
}
return toucher_up(p2);
@@ -290,7 +321,10 @@ bool asst::PlayToolsController::fetch_screen_res()
return true;
}
bool asst::PlayToolsController::toucher_commit(const TouchPhase phase, const Point& p, const int delay)
bool asst::PlayToolsController::toucher_commit(
const TouchPhase phase,
const Point& p,
const int delay)
{
open();
uint16_t x = socket_ops::host_to_network_short(static_cast<uint16_t>(p.x));