From 81c1958992a715dad0251a0b98fe457e553fdb04 Mon Sep 17 00:00:00 2001 From: zzyyyl <74587068+zzyyyl@users.noreply.github.com> Date: Tue, 9 Jan 2024 13:28:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=87=8F=E5=B0=91=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=88=AA=E5=9B=BE=20(#7945)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 减少重复截图 * feat: 截图间隔阈值改为 2min * style: 更新注释 --- .../Task/Miscellaneous/ScreenshotTaskPlugin.cpp | 10 ++++++++++ src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.cpp b/src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.cpp index 5b0604dc8b..255fced19c 100644 --- a/src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.cpp +++ b/src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.cpp @@ -36,7 +36,17 @@ bool asst::ScreenshotTaskPlugin::verify(AsstMsg msg, const json::value& details) } const std::string& task = details.get("details", "task", ""); + using namespace std::chrono_literals; + auto now = std::chrono::steady_clock::now(); + if (task == m_last_triggered_task && now - m_last_triggered_time < 2min) { + // 2min 内同一个任务重复触发一般是卡在某个地方了,不再截图但更新时间 + Log.trace(__FUNCTION__, "| task", task, "triggered recently, skip"); + m_last_triggered_time = now; + return false; + } if (ranges::any_of(m_screenshot_tasks, [&task](std::string_view item) { return task.ends_with(item); })) { + m_last_triggered_task = task; + m_last_triggered_time = now; return true; } diff --git a/src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.h b/src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.h index 80bfea8811..202454a48f 100644 --- a/src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.h +++ b/src/MaaCore/Task/Miscellaneous/ScreenshotTaskPlugin.h @@ -20,5 +20,7 @@ namespace asst static const constexpr std::string_view debug_config_name = "ScreenshotTaskPlugin-Config-Debug"; std::vector m_screenshot_tasks; + mutable std::string m_last_triggered_task; // 上次触发的任务这次不再触发 + mutable std::chrono::steady_clock::time_point m_last_triggered_time; // 触发的时间 }; }