Do not check conditions of paused macros

This commit is contained in:
WarmUpTill
2021-11-09 19:45:36 +01:00
committed by WarmUpTill
parent 5af206da60
commit 2155a942f3
2 changed files with 22 additions and 13 deletions

View File

@@ -36,6 +36,11 @@ bool Macro::CeckMatch()
{
_matched = false;
for (auto &c : _conditions) {
if (_paused) {
vblog(LOG_INFO, "Macro %s is paused", _name.c_str());
return false;
}
auto startTime = std::chrono::high_resolution_clock::now();
bool cond = c->CheckCondition();
auto endTime = std::chrono::high_resolution_clock::now();
@@ -88,18 +93,6 @@ bool Macro::CeckMatch()
}
vblog(LOG_INFO, "Macro %s returned %d", _name.c_str(), _matched);
// Condition checks shall still be run even if macro is paused.
// Otherwise conditions might behave in unexpected ways when resuming.
//
// For example, audio could immediately match after unpause, when it
// matched before it was paused due to timers not being updated.
if (_paused) {
vblog(LOG_INFO, "Macro %s is paused", _name.c_str());
_matched = false;
return false;
}
return _matched;
}
@@ -125,6 +118,21 @@ void Macro::SetName(const std::string &name)
SetHotkeysDesc();
}
void Macro::ResetTimers()
{
for (auto &c : _conditions) {
c->ResetDuration();
}
}
void Macro::SetPaused(bool pause)
{
if (_paused && !pause) {
ResetTimers();
}
_paused = pause;
}
void Macro::UpdateActionIndices()
{
int idx = 0;