From 666c52556e241357554b56a8d33eed78d483f426 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 5 Aug 2023 14:46:11 +0200 Subject: [PATCH] Fix plugin state condition not functioning on OBS shutdown Also added note indicating the limitations of running macros on OBS shutdown --- data/locale/en-US.ini | 1 + src/advanced-scene-switcher.cpp | 22 +++++++++++--- .../macro-condition-plugin-state.cpp | 29 ++++++++++++++----- .../macro-condition-plugin-state.hpp | 3 ++ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index bf9130ad..a72697b8 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -299,6 +299,7 @@ AdvSceneSwitcher.condition.pluginState.state.start="Plugin started" AdvSceneSwitcher.condition.pluginState.state.restart="Plugin restarted" AdvSceneSwitcher.condition.pluginState.state.running="Plugin is running" AdvSceneSwitcher.condition.pluginState.state.shutdown="OBS is shutting down" +AdvSceneSwitcher.condition.pluginState.state.shutdown.limitation="Note that while actions performing OBS specific changes will still be executed on shutdown those changes will not be saved as OBS is already shutting down!" AdvSceneSwitcher.condition.pluginState.state.sceneCollection="Scene collection loaded" AdvSceneSwitcher.condition.pluginState.state.sceneSwitched="Scene changed by previous macro" AdvSceneSwitcher.condition.pluginState.entry="{{condition}}" diff --git a/src/advanced-scene-switcher.cpp b/src/advanced-scene-switcher.cpp index 3d603db1..2cd54b02 100644 --- a/src/advanced-scene-switcher.cpp +++ b/src/advanced-scene-switcher.cpp @@ -123,6 +123,10 @@ static void AskForBackup(obs_data_t *obj); static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *) { + if (!switcher) { + return; + } + if (saving) { std::lock_guard lock(switcher->m); switcher->Prune(); @@ -614,7 +618,7 @@ static void setStreamStopping() std::chrono::high_resolution_clock::now(); } -static void handleExit() +static void handleShutdown() { if (!switcher) { return; @@ -624,8 +628,14 @@ static void handleExit() switcher->Stop(); switcher->CheckMacros(); switcher->RunMacros(); + + // Unfortunately this will not work as OBS will now allow saving + // the scene collection data at this point, So any OBS specific + // changes done during shutdown will be lost + // + // TODO: Look for a way to possibly resolve this + obs_frontend_save(); } - FreeSceneSwitcher(); } static void handleSceneCollectionChanging() @@ -649,8 +659,12 @@ static void OBSEvent(enum obs_frontend_event event, void *switcher) } switch (event) { - case OBS_FRONTEND_EVENT_EXIT: - handleExit(); + case OBS_FRONTEND_EVENT_SCRIPTING_SHUTDOWN: + // Note: We are intentionally not listening for + // OBS_FRONTEND_EVENT_EXIT here as at that point all scene + // collection data will already have been cleared and thus all + // macros will have already been cleared + handleShutdown(); break; case OBS_FRONTEND_EVENT_SCENE_CHANGED: handleSceneChange(); diff --git a/src/macro-core/macro-condition-plugin-state.cpp b/src/macro-core/macro-condition-plugin-state.cpp index 5a8e53b0..35f500b3 100644 --- a/src/macro-core/macro-condition-plugin-state.cpp +++ b/src/macro-core/macro-condition-plugin-state.cpp @@ -112,24 +112,28 @@ static inline void populateConditionSelection(QComboBox *list) MacroConditionPluginStateEdit::MacroConditionPluginStateEdit( QWidget *parent, std::shared_ptr entryData) - : QWidget(parent) + : QWidget(parent), + _condition(new QComboBox()), + _shutdownLimitation(new QLabel(obs_module_text( + "AdvSceneSwitcher.condition.pluginState.state.shutdown.limitation"))) { - _condition = new QComboBox(); - + _shutdownLimitation->setWordWrap(true); QWidget::connect(_condition, SIGNAL(currentIndexChanged(int)), this, SLOT(ConditionChanged(int))); populateConditionSelection(_condition); - QHBoxLayout *switchLayout = new QHBoxLayout; + auto entryLayout = new QHBoxLayout; std::unordered_map widgetPlaceholders = { {"{{condition}}", _condition}, }; PlaceWidgets( obs_module_text("AdvSceneSwitcher.condition.pluginState.entry"), - switchLayout, widgetPlaceholders); + entryLayout, widgetPlaceholders); + entryLayout->setContentsMargins(0, 0, 0, 0); - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout(switchLayout); + auto mainLayout = new QVBoxLayout; + mainLayout->addLayout(entryLayout); + mainLayout->addWidget(_shutdownLimitation); setLayout(mainLayout); _entryData = entryData; @@ -155,6 +159,7 @@ void MacroConditionPluginStateEdit::ConditionChanged(int idx) MacroConditionPluginState::Condition::OBS_SHUTDOWN) { switcher->shutdownConditionCount++; } + SetWidgetVisibility(); } void MacroConditionPluginStateEdit::UpdateEntryData() @@ -165,6 +170,16 @@ void MacroConditionPluginStateEdit::UpdateEntryData() _condition->setCurrentIndex( _condition->findData(static_cast(_entryData->_condition))); + SetWidgetVisibility(); +} + +void MacroConditionPluginStateEdit::SetWidgetVisibility() +{ + _shutdownLimitation->setVisible( + _entryData->_condition == + MacroConditionPluginState::Condition::OBS_SHUTDOWN); + adjustSize(); + updateGeometry(); } } // namespace advss diff --git a/src/macro-core/macro-condition-plugin-state.hpp b/src/macro-core/macro-condition-plugin-state.hpp index e8173888..99889182 100644 --- a/src/macro-core/macro-condition-plugin-state.hpp +++ b/src/macro-core/macro-condition-plugin-state.hpp @@ -58,7 +58,10 @@ private slots: void ConditionChanged(int idx); protected: + void SetWidgetVisibility(); + QComboBox *_condition; + QLabel *_shutdownLimitation; std::shared_ptr _entryData; private: