diff --git a/src/switcher-data.cpp b/src/switcher-data.cpp index 26e0902c..4bab5f42 100644 --- a/src/switcher-data.cpp +++ b/src/switcher-data.cpp @@ -173,8 +173,13 @@ void SwitcherData::SaveVersion(obs_data_t *obj, obs_data_set_string(obj, "version", currentVersion.c_str()); } -void SwitcherData::AddIntervalResetStep(std::function function) +void SwitcherData::AddIntervalResetStep(std::function function, + bool tryLock) { + if (!tryLock) { + resetIntervalSteps.emplace_back(function); + return; + } std::lock_guard lock(switcher->m); resetIntervalSteps.emplace_back(function); } diff --git a/src/switcher-data.hpp b/src/switcher-data.hpp index fa93e2bc..266b0739 100644 --- a/src/switcher-data.hpp +++ b/src/switcher-data.hpp @@ -68,7 +68,7 @@ public: void AddSaveStep(std::function); void AddLoadStep(std::function); void AddPostLoadStep(std::function); - void AddIntervalResetStep(std::function); + void AddIntervalResetStep(std::function, bool lock = true); bool CheckForMatch(OBSWeakSource &scene, OBSWeakSource &transition, int &linger, bool &setPreviousSceneAsMatch, bool ¯oMatch); diff --git a/src/utils/plugin-state-helper.cpp b/src/utils/plugin-state-helper.cpp index 9bb8b2b3..2187a606 100644 --- a/src/utils/plugin-state-helper.cpp +++ b/src/utils/plugin-state-helper.cpp @@ -1,4 +1,4 @@ -#include "plugin-state-helper.hpp" +#include "plugin-state-helpers.hpp" #include "switcher-data.hpp" namespace advss { @@ -23,9 +23,9 @@ void AddPostLoadStep(std::function step) GetSwitcher()->AddPostLoadStep(step); } -void AddIntervalResetStep(std::function step) +void AddIntervalResetStep(std::function step, bool lock) { - GetSwitcher()->AddIntervalResetStep(step); + GetSwitcher()->AddIntervalResetStep(step, lock); } void StopPlugin() @@ -38,24 +38,70 @@ void StartPlugin() GetSwitcher()->Start(); } +bool PluginIsRunning() +{ + return GetSwitcher() && GetSwitcher()->th && + GetSwitcher()->th->isRunning(); +} + +int GetIntervalValue() +{ + return GetSwitcher()->interval; +} + void SetPluginNoMatchBehavior(NoMatchBehavior behavior) { GetSwitcher()->switchIfNotMatching = behavior; } -void SetNoMatchScene(const OBSWeakSource &scene) -{ - GetSwitcher()->nonMatchingScene = scene; -} - NoMatchBehavior GetPluginNoMatchBehavior() { return GetSwitcher()->switchIfNotMatching; } +void SetNoMatchScene(const OBSWeakSource &scene) +{ + GetSwitcher()->nonMatchingScene = scene; +} + +std::string ForegroundWindowTitle() +{ + return GetSwitcher()->currentTitle; +} + +std::string PreviousForegroundWindowTitle() +{ + return GetSwitcher()->lastTitle; +} + bool SettingsWindowIsOpened() { return GetSwitcher()->settingsWindowOpened; } +bool HighlightUIElementsEnabled() +{ + return GetSwitcher() && !GetSwitcher()->disableHints; +} + +bool OBSIsShuttingDown() +{ + return GetSwitcher()->obsIsShuttingDown; +} + +bool InitialLoadIsComplete() +{ + return GetSwitcher()->startupLoadDone; +} + +bool IsFirstInterval() +{ + return GetSwitcher()->firstInterval; +} + +bool IsFirstIntervalAfterStop() +{ + return GetSwitcher()->firstIntervalAfterStop; +} + } // namespace advss diff --git a/src/utils/plugin-state-helper.hpp b/src/utils/plugin-state-helper.hpp index 8e2148ab..ad7627a6 100644 --- a/src/utils/plugin-state-helper.hpp +++ b/src/utils/plugin-state-helper.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace advss { @@ -9,16 +10,27 @@ void LoadPluginSettings(obs_data_t *); void AddSaveStep(std::function); void AddLoadStep(std::function); void AddPostLoadStep(std::function); -void AddIntervalResetStep(std::function); +void AddIntervalResetStep(std::function, bool lock = true); void StopPlugin(); void StartPlugin(); +bool PluginIsRunning(); +int GetIntervalValue(); enum class NoMatchBehavior { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 }; void SetPluginNoMatchBehavior(NoMatchBehavior); NoMatchBehavior GetPluginNoMatchBehavior(); void SetNoMatchScene(const OBSWeakSource &); +std::string ForegroundWindowTitle(); +std::string PreviousForegroundWindowTitle(); + bool SettingsWindowIsOpened(); +bool HighlightUIElementsEnabled(); + +bool OBSIsShuttingDown(); +bool InitialLoadIsComplete(); +bool IsFirstInterval(); +bool IsFirstIntervalAfterStop(); } // namespace advss