feat: 减少重复截图 (#7945)

* feat: 减少重复截图

* feat: 截图间隔阈值改为 2min

* style: 更新注释
This commit is contained in:
zzyyyl
2024-01-09 13:28:03 +08:00
committed by GitHub
parent 8c6db4c514
commit 81c1958992
2 changed files with 12 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -20,5 +20,7 @@ namespace asst
static const constexpr std::string_view debug_config_name = "ScreenshotTaskPlugin-Config-Debug";
std::vector<std::string> m_screenshot_tasks;
mutable std::string m_last_triggered_task; // 上次触发的任务这次不再触发
mutable std::chrono::steady_clock::time_point m_last_triggered_time; // 触发的时间
};
}