From 0c97b3be4a5fc1624d500ec90a10e0eb6f026c62 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Wed, 24 Jan 2024 17:38:20 +0100 Subject: [PATCH] Add MacroWasPausedSince() It will allow you to query if the macro was paused since a given time point. It checks this by comparing the time point against the time point at which the macro was last paused. --- lib/macro/macro-helpers.cpp | 7 +++++++ lib/macro/macro-helpers.hpp | 3 +++ lib/macro/macro.cpp | 7 +++++++ lib/macro/macro.hpp | 3 +++ 4 files changed, 20 insertions(+) diff --git a/lib/macro/macro-helpers.cpp b/lib/macro/macro-helpers.cpp index e8e0760f..50f4319e 100644 --- a/lib/macro/macro-helpers.cpp +++ b/lib/macro/macro-helpers.cpp @@ -100,6 +100,13 @@ bool MacroIsPaused(Macro *macro) return macro ? macro->Paused() : true; } +bool MacroWasPausedSince( + Macro *macro, + const std::chrono::high_resolution_clock::time_point &time) +{ + return macro ? macro->WasPausedSince(time) : false; +} + void AddMacroHelperThread(Macro *macro, std::thread &&newThread) { if (!macro) { diff --git a/lib/macro/macro-helpers.hpp b/lib/macro/macro-helpers.hpp index bb1c692d..642febf6 100644 --- a/lib/macro/macro-helpers.hpp +++ b/lib/macro/macro-helpers.hpp @@ -2,6 +2,7 @@ #include "export-symbol-helper.hpp" #include +#include #include #include #include @@ -46,6 +47,8 @@ EXPORT int64_t MillisecondsSinceMacroConditionCheck(Macro *); EXPORT bool MacroIsStopped(Macro *); EXPORT bool MacroIsPaused(Macro *); +EXPORT bool +MacroWasPausedSince(Macro *, const std::chrono::high_resolution_clock::time_point &); EXPORT void AddMacroHelperThread(Macro *, std::thread &&); diff --git a/lib/macro/macro.cpp b/lib/macro/macro.cpp index 70b97bf4..f812a83b 100644 --- a/lib/macro/macro.cpp +++ b/lib/macro/macro.cpp @@ -327,6 +327,12 @@ bool Macro::DockIsVisible() const return _dock && _dockAction && _dock->isVisible(); } +bool Macro::WasPausedSince( + const std::chrono::high_resolution_clock::time_point &time) const +{ + return _lastUnpauseTime > time; +} + void Macro::SetMatchOnChange(bool onChange) { _performActionsOnChange = onChange; @@ -335,6 +341,7 @@ void Macro::SetMatchOnChange(bool onChange) void Macro::SetPaused(bool pause) { if (_paused && !pause) { + _lastUnpauseTime = std::chrono::high_resolution_clock::now(); ResetTimers(); } _paused = pause; diff --git a/lib/macro/macro.hpp b/lib/macro/macro.hpp index cc699468..a273e621 100644 --- a/lib/macro/macro.hpp +++ b/lib/macro/macro.hpp @@ -36,6 +36,8 @@ public: bool RunInParallel() const { return _runInParallel; } void SetPaused(bool pause = true); bool Paused() const { return _paused; } + bool WasPausedSince( + const std::chrono::high_resolution_clock::time_point &) const; void SetMatchOnChange(bool onChange); bool MatchOnChange() const { return _performActionsOnChange; } void SetSkipExecOnStart(bool skip) { _skipExecOnStart = skip; } @@ -146,6 +148,7 @@ private: bool _stop = false; bool _done = true; std::chrono::high_resolution_clock::time_point _lastCheckTime{}; + std::chrono::high_resolution_clock::time_point _lastUnpauseTime{}; std::chrono::high_resolution_clock::time_point _lastExecutionTime{}; std::thread _backgroundThread; std::vector _helperThreads;