From 63a545b29362b702acb2cf14ee8c896df95f4b65 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Fri, 1 Nov 2024 20:05:10 +0100 Subject: [PATCH] Fix "Date" condition returning true unexpectedly This could happen if the plugin was stopped on the General tab and restarted or the first time the plugin was started. --- lib/macro/macro-helpers.cpp | 8 ++++---- plugins/base/macro-condition-date.cpp | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/macro/macro-helpers.cpp b/lib/macro/macro-helpers.cpp index 718dfc90..eba31b9a 100644 --- a/lib/macro/macro-helpers.cpp +++ b/lib/macro/macro-helpers.cpp @@ -111,10 +111,10 @@ bool MacroWasPausedSince( bool MacroWasCheckedSinceLastStart(Macro *macro) { - return macro ? macro->LastConditionCheckTime() - .time_since_epoch() - .count() != 0 - : false; + if (!macro) { + return false; + } + return macro->LastConditionCheckTime().time_since_epoch().count() != 0; } void AddMacroHelperThread(Macro *macro, std::thread &&newThread) diff --git a/plugins/base/macro-condition-date.cpp b/plugins/base/macro-condition-date.cpp index e1e45698..389791c9 100644 --- a/plugins/base/macro-condition-date.cpp +++ b/plugins/base/macro-condition-date.cpp @@ -176,15 +176,21 @@ bool MacroConditionDate::CheckRegularDate(int64_t msSinceLastCheck) bool MacroConditionDate::CheckCondition() { - auto m = GetMacro(); - if (!m) { + auto macro = GetMacro(); + if (!macro) { return false; } - const auto timePassed = std::chrono::high_resolution_clock::now() - - LastMacroConditionCheckTime(m); + + const auto now = std::chrono::high_resolution_clock::now(); + const auto lastCheck = LastMacroConditionCheckTime(macro); + + const auto timePassed = now - lastCheck; + const auto msSinceLastCheck = - std::chrono::duration_cast( - timePassed); + MacroWasCheckedSinceLastStart(macro) + ? std::chrono::duration_cast( + timePassed) + : std::chrono::milliseconds(0); if (_dayOfWeekCheck) { return CheckDayOfWeek(msSinceLastCheck.count());