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.
This commit is contained in:
WarmUpTill 2024-11-01 20:05:10 +01:00 committed by WarmUpTill
parent bc0497d2c9
commit 63a545b293
2 changed files with 16 additions and 10 deletions

View File

@ -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)

View File

@ -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<std::chrono::milliseconds>(
timePassed);
MacroWasCheckedSinceLastStart(macro)
? std::chrono::duration_cast<std::chrono::milliseconds>(
timePassed)
: std::chrono::milliseconds(0);
if (_dayOfWeekCheck) {
return CheckDayOfWeek(msSinceLastCheck.count());