Compare commits

..

1 Commits

Author SHA1 Message Date
uye
207a04a11c chore: 优化被注入提示描述 (#17272) 2026-07-05 13:06:04 +08:00
7 changed files with 48 additions and 71 deletions

View File

@@ -49,10 +49,6 @@ asst::AdbController::~AdbController()
LogTraceFunction;
m_inited = false;
// 等待异步帧率检测结束,避免线程访问已析构的 this
if (m_fps_future.valid()) {
m_fps_future.wait();
}
release();
}
@@ -393,10 +389,6 @@ std::optional<unsigned short> asst::AdbController::init_socket(const std::string
void asst::AdbController::clear_info() noexcept
{
m_inited = false;
// 等待可能仍在执行的异步帧率检测
if (m_fps_future.valid()) {
m_fps_future.wait();
}
m_adb = decltype(m_adb)();
m_uuid.clear();
m_width = 0;
@@ -1277,12 +1269,6 @@ void asst::AdbController::check_fps()
return;
}
// 上一次异步检测尚未完成,跳过(避免堆积)
if (m_fps_future.valid() &&
m_fps_future.wait_for(std::chrono::seconds(0)) != std::future_status::ready) {
return;
}
// 每 1 分钟检测一次
constexpr auto FpsCheckInterval = std::chrono::minutes(1);
auto now = std::chrono::steady_clock::now();
@@ -1291,63 +1277,56 @@ void asst::AdbController::check_fps()
}
m_last_fps_check_time = now;
// 异步执行,避免 adb 延迟阻塞截图返回
// 值捕获易变数据m_uuid / m_adb.fps防止 clear_info() 清空后异步线程读到悬空数据;
// call_command / callback 依赖的 mutex、platform_io、callback 等均为构造后不变,
// 生命周期由 ~AdbController 和 clear_info() 中的 m_fps_future.wait() 保证安全
m_fps_future = std::async(std::launch::async, [this, cmd = m_adb.fps, uuid = m_uuid]() {
if (need_exit()) {
return;
}
auto ret = call_command(m_adb.fps, 100, false /* 帧率检测不触发重连,避免拖慢截图流程 */);
if (!ret || ret.value().empty()) {
Log.warn("fps command failed or empty");
return;
}
// 放宽到 5 秒:异步执行后不再阻塞截图,可给 adb 足够时间
auto ret = call_command(cmd, 5000, false);
if (!ret || ret.value().empty()) {
Log.warn("fps command failed or empty");
return;
}
// SurfaceFlinger --latency 第一行是每帧刷新周期(纳秒),例如 16666666 表示 60 FPS
// 注意:这里检测的是模拟器/系统的设置刷新率,而非游戏实际运行帧率。
// 游戏原生帧率上限为 60 FPS高于 60 通常为模拟器插帧,不作为异常处理。
auto& output = ret.value();
convert_lf(output);
auto newline_pos = output.find('\n');
std::string first_line = newline_pos == std::string::npos ? output : output.substr(0, newline_pos);
// SurfaceFlinger --latency 第一行是每帧刷新周期(纳秒),例如 16666666 表示 60 FPS
// 注意:这里检测的是模拟器/系统的设置刷新率,而非游戏实际运行帧率。
auto output = std::move(ret.value());
convert_lf(output);
auto newline_pos = output.find('\n');
std::string first_line = newline_pos == std::string::npos ? output : output.substr(0, newline_pos);
// 去掉空白和非数字字符
std::erase_if(first_line, [](char c) { return !std::isdigit(static_cast<unsigned char>(c)); });
// 去掉空白和非数字字符
std::erase_if(first_line, [](char c) { return !std::isdigit(static_cast<unsigned char>(c)); });
if (first_line.empty()) {
Log.warn("fps output is empty after sanitize");
return;
}
if (first_line.empty()) {
Log.warn("fps output is empty after sanitize");
return;
}
long long refresh_period_ns = 0;
try {
refresh_period_ns = std::stoll(first_line);
}
catch (...) {
Log.warn("fps output parse failed:", first_line);
return;
}
long long refresh_period_ns = 0;
if (!utils::chars_to_number<long long, true>(first_line, refresh_period_ns)) {
Log.warn("fps output parse failed:", first_line);
return;
}
if (refresh_period_ns <= 0) {
Log.warn("invalid refresh period:", refresh_period_ns);
return;
}
if (refresh_period_ns <= 0) {
Log.warn("invalid refresh period:", refresh_period_ns);
return;
}
// ns -> FPS
double fps = 1000000000.0 / static_cast<double>(refresh_period_ns);
int fps_int = static_cast<int>(std::round(fps));
// ns -> FPS
double fps = 1000000000.0 / static_cast<double>(refresh_period_ns);
int fps_int = static_cast<int>(std::round(fps));
json::value info = json::object {
{ "uuid", uuid },
{ "what", "EmulatorFPS" },
{ "details",
json::object {
{ "fps", fps_int },
{ "refresh_period_ns", refresh_period_ns },
} },
};
callback(AsstMsg::ConnectionInfo, info);
});
json::value info = json::object {
{ "uuid", m_uuid },
{ "what", "EmulatorFPS" },
{ "details",
json::object {
{ "fps", fps_int },
{ "refresh_period_ns", refresh_period_ns },
} },
};
callback(AsstMsg::ConnectionInfo, info);
}
void asst::AdbController::back_to_home() noexcept

View File

@@ -4,7 +4,6 @@
#include <chrono>
#include <deque>
#include <future>
#include <optional>
#include <random>
@@ -225,7 +224,6 @@ protected:
std::deque<long long> m_screencap_cost; // 截图用时
int m_screencap_times = 0; // 截图次数
std::chrono::steady_clock::time_point m_last_fps_check_time; // 上次帧率检测时间
std::future<void> m_fps_future; // 异步帧率检测任务
#if ASST_WITH_EMULATOR_EXTRAS
MumuExtras m_mumu_extras;

View File

@@ -2111,7 +2111,7 @@ These locations are too high-level and can lead to file overwrites, config write
<!-- BadModules -->
<system:String x:Key="BadModules.Warning.Heading">Compatibility Warning</system:String>
<system:String x:Key="BadModules.Warning.Prolog">The following DLL(s) injected into MAA may crash MAA or corrupt MAA user interface:</system:String>
<system:String x:Key="BadModules.Warning.Prolog">The following third-party software has injected DLL(s) into MAA, which will interfere with WPF rendering and ONNX/DML inference, causing MAA to crash, display rendering anomalies, or OCR recognition failures:</system:String>
<system:String x:Key="BadModules.Warning.Epilog">If you encounter such issues with MAA, please try adding MAA to the exclusion list of the relevant software, or uninstall the related software and check if the problem persists.</system:String>
<system:String x:Key="BadModules.Warning.DoNotShowAgain">Do not show this warning again</system:String>
<system:String x:Key="BadModules.Confirmation.Heading">Warning: Performance Impact</system:String>

View File

@@ -2112,7 +2112,7 @@ MAA を複数開くには、新しい MAA を他のフォルダにコピーし
<!-- BadModules -->
<system:String x:Key="BadModules.Warning.Heading">悲報</system:String>
<system:String x:Key="BadModules.Warning.Prolog">以下の DLL を MAA に注入すると、MAA クラッシュしたり、インターフェースのレンダリング異常が発生する可能性があります:</system:String>
<system:String x:Key="BadModules.Warning.Prolog">以下のサードパーティ製ソフトウェアが MAA に DLL を注入しています。これにより WPF レンダリングと ONNX/DML 推論が破壊され、MAA クラッシュ、インターフェースのレンダリング異常、または OCR 認識失敗が発生する可能性があります:</system:String>
<system:String x:Key="BadModules.Warning.Epilog">MAA に関連する問題がある場合は、関連ソフトウェアの除外リストに MAA を追加するか、関連ソフトウェアをアンインストールした後、問題がまだ存在するかどうかを確認してください。</system:String>
<system:String x:Key="BadModules.Warning.DoNotShowAgain">この警告を再表示しない</system:String>
<system:String x:Key="BadModules.Confirmation.Heading">警告:パフォーマンスへの影響</system:String>

View File

@@ -2112,7 +2112,7 @@ MAA를 독립된 새 폴더에 압축 해제하거나, MAA에 속하지 않는 D
<!-- BadModules -->
<system:String x:Key="BadModules.Warning.Heading">호환성 경고</system:String>
<system:String x:Key="BadModules.Warning.Prolog">다음 DLL이 MAA에 주입되면 MAA가 충돌하거나 UI 렌더링에 문제가 발생할 수 있습니다:</system:String>
<system:String x:Key="BadModules.Warning.Prolog">다음 타사 소프트웨어가 MAA에 DLL을 주입했습니다. 이는 WPF 렌더링과 ONNX/DML 추론을 방해하여 MAA가 충돌하거나 UI 렌더링에 문제가 발생하거나 OCR 인식이 실패할 수 있습니다:</system:String>
<system:String x:Key="BadModules.Warning.Epilog">MAA에서 관련 문제가 발생하는 경우, 관련 소프트웨어의 제외 목록에 MAA를 추가하거나 관련 소프트웨어를 제거한 후 문제가 계속 발생하는지 확인하세요.</system:String>
<system:String x:Key="BadModules.Warning.DoNotShowAgain">이 경고를 다시 표시하지 않음</system:String>
<system:String x:Key="BadModules.Confirmation.Heading">경고: 성능 영향</system:String>

View File

@@ -2113,7 +2113,7 @@ DEBUG 目录下保存的图片有数量限制,超出后会自动清理旧图
<!-- BadModules -->
<system:String x:Key="BadModules.Warning.Heading">悲报</system:String>
<system:String x:Key="BadModules.Warning.Prolog">以下注入到 MAA 的 DLL 可能会导致 MAA 闪退界面渲染异常:</system:String>
<system:String x:Key="BadModules.Warning.Prolog">检测到以下第三方软件向 MAA 注入了 DLL。这些注入的 DLL 会破坏 WPF 渲染和 ONNX/DML 推理,导致 MAA 闪退界面渲染异常或 OCR 识别失败</system:String>
<system:String x:Key="BadModules.Warning.Epilog">如果您注意到 MAA 存在相关问题,请尝试将 MAA 加入相关软件的排除名单,或卸载相关软件后检查问题是否仍然存在。</system:String>
<system:String x:Key="BadModules.Warning.DoNotShowAgain">不再显示此警告</system:String>
<system:String x:Key="BadModules.Confirmation.Heading">警告:性能影响</system:String>

View File

@@ -2112,7 +2112,7 @@ DEBUG 目錄下儲存的圖片有數量限制,超出後會自動清理舊圖
<!-- BadModules -->
<system:String x:Key="BadModules.Warning.Heading">悲報</system:String>
<system:String x:Key="BadModules.Warning.Prolog">以下注入到 MAA 的 DLL 可能會導致 MAA 閃退介面渲染異常</system:String>
<system:String x:Key="BadModules.Warning.Prolog">偵測到以下第三方軟體向 MAA 注入了 DLL。這些注入的 DLL 會破壞 WPF 算繪和 ONNX/DML 推論,導致 MAA 閃退介面算繪異常或 OCR 識別失敗</system:String>
<system:String x:Key="BadModules.Warning.Epilog">如果您發現 MAA 存在相關問題,請嘗試將 MAA 加入相關軟體的排除名單,或解除安裝相關軟體後檢查問題是否仍然存在。</system:String>
<system:String x:Key="BadModules.Warning.DoNotShowAgain">不再顯示此警告</system:String>
<system:String x:Key="BadModules.Confirmation.Heading">警告:效能影響</system:String>