#include "plugin-state-helpers.hpp" #include "macro-settings.hpp" #include "macro-signals.hpp" #include "switcher-data.hpp" #include "obs-frontend-api.h" namespace advss { static std::mutex initMutex; static std::mutex postLoadMutex; static std::mutex finishLoadMutex; static std::mutex mutex; static bool setup(); static bool setupDonw = setup(); bool loadingFinished = false; static std::vector> &getFinishLoadSteps(); static bool setup() { static auto handleEvent = [](enum obs_frontend_event event, void *) { switch (event) { case OBS_FRONTEND_EVENT_FINISHED_LOADING: { std::lock_guard lock(finishLoadMutex); for (const auto &step : getFinishLoadSteps()) { step(); } getFinishLoadSteps().clear(); loadingFinished = true; break; } default: break; }; }; obs_frontend_add_event_callback(handleEvent, nullptr); return true; } static std::vector> &getPluginInitSteps() { static std::vector> steps; return steps; } static std::vector> &getPluginPostLoadSteps() { static std::vector> steps; return steps; } static std::vector> &getPluginCleanupSteps() { static std::vector> steps; return steps; } static std::vector> &getResetIntervalSteps() { static std::vector> steps; return steps; } static std::vector> &getStartSteps() { static std::vector> steps; return steps; } static std::vector> &getStopSteps() { static std::vector> steps; return steps; } static std::vector> &getSaveSteps() { static std::vector> steps; return steps; } static std::vector> &getLoadSteps() { static std::vector> steps; return steps; } static std::vector> &getPostLoadSteps() { static std::vector> steps; return steps; } static std::vector> &getFinishLoadSteps() { static std::vector> steps; return steps; } void SavePluginSettings(obs_data_t *obj) { GetSwitcher()->SaveSettings(obj); } void LoadPluginSettings(obs_data_t *obj) { GetSwitcher()->LoadSettings(obj); } void AddSaveStep(std::function step) { std::lock_guard lock(mutex); getSaveSteps().emplace_back(step); } void AddLoadStep(std::function step) { std::lock_guard lock(mutex); getLoadSteps().emplace_back(step); } void AddPostLoadStep(std::function step) { std::lock_guard lock(postLoadMutex); getPostLoadSteps().emplace_back(step); } void AddIntervalResetStep(std::function step) { std::lock_guard lock(mutex); getResetIntervalSteps().emplace_back(step); } void RunSaveSteps(obs_data_t *obj) { std::lock_guard lock(mutex); for (const auto &func : getSaveSteps()) { func(obj); } } void RunLoadSteps(obs_data_t *obj) { std::lock_guard lock(mutex); for (const auto &func : getLoadSteps()) { func(obj); } } void RunAndClearPostLoadSteps() { std::lock_guard lock(postLoadMutex); for (const auto &func : getPostLoadSteps()) { func(); } getPostLoadSteps().clear(); } void ClearPostLoadSteps() { std::lock_guard lock(postLoadMutex); getPostLoadSteps().clear(); } void AddPluginInitStep(std::function step) { std::lock_guard lock(initMutex); getPluginInitSteps().emplace_back(step); } void AddPluginPostLoadStep(std::function step) { std::lock_guard lock(mutex); getPluginPostLoadSteps().emplace_back(step); } void AddPluginCleanupStep(std::function step) { std::lock_guard lock(mutex); getPluginCleanupSteps().emplace_back(step); } void RunPluginInitSteps() { std::lock_guard lock(initMutex); for (const auto &step : getPluginInitSteps()) { step(); } } void RunPluginPostLoadSteps() { std::lock_guard lock(mutex); for (const auto &step : getPluginPostLoadSteps()) { step(); } } void RunPluginCleanupSteps() { std::lock_guard lock(mutex); for (const auto &step : getPluginCleanupSteps()) { step(); } } void RunIntervalResetSteps() { std::lock_guard lock(mutex); for (const auto &step : getResetIntervalSteps()) { step(); } } void AddFinishedLoadingStep(std::function step) { std::lock_guard lock(finishLoadMutex); if (loadingFinished) { return; } getFinishLoadSteps().emplace_back(step); } void AddStartStep(std::function step) { std::lock_guard lock(mutex); getStartSteps().emplace_back(step); } void AddStopStep(std::function step) { std::lock_guard lock(mutex); getStopSteps().emplace_back(step); } void RunStartSteps() { std::lock_guard lock(mutex); for (const auto &step : getStartSteps()) { step(); } } void RunStopSteps() { std::lock_guard lock(mutex); for (const auto &step : getStopSteps()) { step(); } } void StopPlugin() { GetSwitcher()->Stop(); } 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; } NoMatchBehavior GetPluginNoMatchBehavior() { return GetSwitcher()->switchIfNotMatching; } void SetNoMatchScene(const OBSWeakSource &scene) { GetSwitcher()->nonMatchingScene.SetScene(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() && GetSwitcher()->obsIsShuttingDown; } bool InitialLoadIsComplete() { return GetSwitcher()->startupLoadDone; } bool IsFirstInterval() { return GetSwitcher()->firstInterval; } bool IsFirstIntervalAfterStop() { return GetSwitcher()->firstIntervalAfterStop; } void SetMacroHighlightingEnabled(bool enable) { auto &settings = GetGlobalMacroSettings(); settings._highlightActions = enable; settings._highlightConditions = enable; settings._highlightExecuted = enable; obs_queue_task( OBS_TASK_UI, [](void *) { if (!SettingsWindowIsOpened()) { return; } MacroSignalManager::Instance()->HighlightChanged( GetGlobalMacroSettings()._highlightExecuted); }, nullptr, false); } bool IsMacroHighlightingEnabled() { const auto &settings = GetGlobalMacroSettings(); return settings._highlightActions || settings._highlightConditions || settings._highlightExecuted; } } // namespace advss