Enable plugin callbacks to be peformed after condition checks completed

Also run these callbacks before restarting the plugin.
This should ensure that no outdated signals received while the plugin
was stopped will trigger unexpected actions. (E.g. websocket messages
that were received while the plugin was stopped)
This commit is contained in:
WarmUpTill
2023-04-10 02:10:15 +02:00
committed by WarmUpTill
parent ffca124762
commit b7479e8342
3 changed files with 32 additions and 10 deletions

View File

@@ -255,7 +255,7 @@ void SwitcherData::Thread()
}
}
ClearWebsocketMessages();
resetForNextInterval();
if (match) {
if (macroMatch) {
@@ -308,6 +308,16 @@ void SwitcherData::setPreconditions()
lastCursorPos = getCursorPos();
}
void SwitcherData::resetForNextInterval()
{
// Core reset functions
ClearWebsocketMessages();
// Plugin reset functions
for (const auto &func : resetForNextIntervalFuncs) {
func();
}
}
bool SwitcherData::checkForMatch(OBSWeakSource &scene,
OBSWeakSource &transition, int &linger,
bool &setPrevSceneAfterLinger,
@@ -414,9 +424,20 @@ void switchPreviewScene(const OBSWeakSource &ws)
obs_source_release(source);
}
static void ResetMacros()
{
for (auto &m : switcher->macros) {
m->ResetRunCount();
m->ResetTimers();
}
}
void SwitcherData::Start()
{
if (!(th && th->isRunning())) {
resetForNextInterval();
ResetMacros();
stop = false;
th = new SwitcherThread();
th->start((QThread::Priority)threadPriority);
@@ -441,14 +462,6 @@ void SwitcherData::Start()
}
}
void ResetMacros()
{
for (auto &m : switcher->macros) {
m->ResetRunCount();
m->ResetTimers();
}
}
void SwitcherData::Stop()
{
if (th && th->isRunning()) {
@@ -462,7 +475,6 @@ void SwitcherData::Stop()
th = nullptr;
writeToStatusFile("Advanced Scene Switcher stopped");
ResetMacros();
}
server.stop();

View File

@@ -133,3 +133,10 @@ void SwitcherData::saveVersion(obs_data_t *obj,
{
obs_data_set_string(obj, "version", currentVersion.c_str());
}
void SwitcherData::addResetForNextIntervalFunction(
std::function<void()> function)
{
std::lock_guard<std::mutex> lock(switcher->m);
resetForNextIntervalFuncs.emplace_back(function);
}

View File

@@ -271,6 +271,9 @@ struct SwitcherData {
void writeToStatusFile(const QString &msg);
void setPreconditions();
void resetForNextInterval();
void addResetForNextIntervalFunction(std::function<void()>);
std::vector<std::function<void()>> resetForNextIntervalFuncs;
bool checkForMatch(OBSWeakSource &scene, OBSWeakSource &transition,
int &linger, bool &setPreviousSceneAsMatch,
bool &macroMatch);