mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-19 16:47:22 -05:00
Rework WasExecutedRecenty()
Added ExecutedSince() instead as WasExecutedRecenty() did not support checking if a macro was executed recently when using it multiple times in quick succession. This could be the case if the MacroTree and a MacroDock would both attempt to use this function at the same time.
This commit is contained in:
parent
101a85b063
commit
55c7ac8a32
|
|
@ -96,15 +96,15 @@ void MacroTreeItem::UpdatePaused()
|
|||
|
||||
void MacroTreeItem::HighlightIfExecuted()
|
||||
{
|
||||
if (!_highlight) {
|
||||
// Run check regardless to reset "_wasExecutedRecently"
|
||||
(void)_macro->WasExecutedRecently();
|
||||
if (!_highlight || !_macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_macro && _macro->WasExecutedRecently()) {
|
||||
if (_lastHighlightCheckTime.time_since_epoch().count() != 0 &&
|
||||
_macro->ExecutedSince(_lastHighlightCheckTime)) {
|
||||
PulseWidget(this, Qt::green, QColor(0, 0, 0, 0), true);
|
||||
}
|
||||
_lastHighlightCheckTime = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void MacroTreeItem::MacroRenamed(const QString &oldName, const QString &newName)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <memory>
|
||||
#include <deque>
|
||||
#include <chrono>
|
||||
|
||||
class QLabel;
|
||||
class QSpacerItem;
|
||||
|
|
@ -61,6 +62,7 @@ private:
|
|||
QLabel *_label = nullptr;
|
||||
MacroTree *_tree;
|
||||
bool _highlight;
|
||||
std::chrono::high_resolution_clock::time_point _lastHighlightCheckTime{};
|
||||
QTimer _timer;
|
||||
std::shared_ptr<Macro> _macro;
|
||||
|
||||
|
|
|
|||
|
|
@ -213,14 +213,20 @@ bool Macro::PerformActions(bool forceParallel, bool ignorePause)
|
|||
} else {
|
||||
RunActions(ret, ignorePause);
|
||||
}
|
||||
_wasExecutedRecently = true;
|
||||
_lastExecutionTime = std::chrono::high_resolution_clock::now();
|
||||
auto group = _parent.lock();
|
||||
if (group) {
|
||||
group->_wasExecutedRecently = true;
|
||||
group->_lastExecutionTime = _lastExecutionTime;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Macro::ExecutedSince(
|
||||
const std::chrono::high_resolution_clock::time_point &time)
|
||||
{
|
||||
return _lastExecutionTime > time;
|
||||
}
|
||||
|
||||
int64_t Macro::MsSinceLastCheck() const
|
||||
{
|
||||
if (_lastCheckTime.time_since_epoch().count() == 0) {
|
||||
|
|
@ -246,6 +252,7 @@ void Macro::ResetTimers()
|
|||
c->ResetDuration();
|
||||
}
|
||||
_lastCheckTime = {};
|
||||
_lastExecutionTime = {};
|
||||
}
|
||||
|
||||
void Macro::RunActions(bool &retVal, bool ignorePause)
|
||||
|
|
@ -548,15 +555,6 @@ bool Macro::SwitchesScene() const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Macro::WasExecutedRecently()
|
||||
{
|
||||
if (_wasExecutedRecently) {
|
||||
_wasExecutedRecently = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Macro::OnChangePreventedActionsRecently()
|
||||
{
|
||||
if (_onChangeTriggered) {
|
||||
|
|
|
|||
|
|
@ -77,7 +77,8 @@ public:
|
|||
bool SwitchesScene() const;
|
||||
|
||||
// UI helpers
|
||||
bool WasExecutedRecently();
|
||||
bool
|
||||
ExecutedSince(const std::chrono::high_resolution_clock::time_point &);
|
||||
bool OnChangePreventedActionsRecently();
|
||||
void ResetUIHelpers();
|
||||
|
||||
|
|
@ -121,6 +122,7 @@ private:
|
|||
bool _stop = false;
|
||||
bool _done = true;
|
||||
std::chrono::high_resolution_clock::time_point _lastCheckTime{};
|
||||
std::chrono::high_resolution_clock::time_point _lastExecutionTime{};
|
||||
std::thread _backgroundThread;
|
||||
std::vector<std::thread> _helperThreads;
|
||||
|
||||
|
|
@ -143,8 +145,6 @@ private:
|
|||
obs_hotkey_id _unpauseHotkey = OBS_INVALID_HOTKEY_ID;
|
||||
obs_hotkey_id _togglePauseHotkey = OBS_INVALID_HOTKEY_ID;
|
||||
|
||||
// UI helpers for the macro tab
|
||||
bool _wasExecutedRecently = false;
|
||||
bool _onChangeTriggered = false;
|
||||
|
||||
bool _registerDock = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user