Skip to content

Commit 666c525

Browse files
committed
Fix plugin state condition not functioning on OBS shutdown
Also added note indicating the limitations of running macros on OBS shutdown
1 parent 1c0734d commit 666c525

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

data/locale/en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ AdvSceneSwitcher.condition.pluginState.state.start="Plugin started"
299299
AdvSceneSwitcher.condition.pluginState.state.restart="Plugin restarted"
300300
AdvSceneSwitcher.condition.pluginState.state.running="Plugin is running"
301301
AdvSceneSwitcher.condition.pluginState.state.shutdown="OBS is shutting down"
302+
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!"
302303
AdvSceneSwitcher.condition.pluginState.state.sceneCollection="Scene collection loaded"
303304
AdvSceneSwitcher.condition.pluginState.state.sceneSwitched="Scene changed by previous macro"
304305
AdvSceneSwitcher.condition.pluginState.entry="{{condition}}"

src/advanced-scene-switcher.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ static void AskForBackup(obs_data_t *obj);
123123

124124
static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
125125
{
126+
if (!switcher) {
127+
return;
128+
}
129+
126130
if (saving) {
127131
std::lock_guard<std::mutex> lock(switcher->m);
128132
switcher->Prune();
@@ -614,7 +618,7 @@ static void setStreamStopping()
614618
std::chrono::high_resolution_clock::now();
615619
}
616620

617-
static void handleExit()
621+
static void handleShutdown()
618622
{
619623
if (!switcher) {
620624
return;
@@ -624,8 +628,14 @@ static void handleExit()
624628
switcher->Stop();
625629
switcher->CheckMacros();
626630
switcher->RunMacros();
631+
632+
// Unfortunately this will not work as OBS will now allow saving
633+
// the scene collection data at this point, So any OBS specific
634+
// changes done during shutdown will be lost
635+
//
636+
// TODO: Look for a way to possibly resolve this
637+
obs_frontend_save();
627638
}
628-
FreeSceneSwitcher();
629639
}
630640

631641
static void handleSceneCollectionChanging()
@@ -649,8 +659,12 @@ static void OBSEvent(enum obs_frontend_event event, void *switcher)
649659
}
650660

651661
switch (event) {
652-
case OBS_FRONTEND_EVENT_EXIT:
653-
handleExit();
662+
case OBS_FRONTEND_EVENT_SCRIPTING_SHUTDOWN:
663+
// Note: We are intentionally not listening for
664+
// OBS_FRONTEND_EVENT_EXIT here as at that point all scene
665+
// collection data will already have been cleared and thus all
666+
// macros will have already been cleared
667+
handleShutdown();
654668
break;
655669
case OBS_FRONTEND_EVENT_SCENE_CHANGED:
656670
handleSceneChange();

src/macro-core/macro-condition-plugin-state.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,28 @@ static inline void populateConditionSelection(QComboBox *list)
112112

113113
MacroConditionPluginStateEdit::MacroConditionPluginStateEdit(
114114
QWidget *parent, std::shared_ptr<MacroConditionPluginState> entryData)
115-
: QWidget(parent)
115+
: QWidget(parent),
116+
_condition(new QComboBox()),
117+
_shutdownLimitation(new QLabel(obs_module_text(
118+
"AdvSceneSwitcher.condition.pluginState.state.shutdown.limitation")))
116119
{
117-
_condition = new QComboBox();
118-
120+
_shutdownLimitation->setWordWrap(true);
119121
QWidget::connect(_condition, SIGNAL(currentIndexChanged(int)), this,
120122
SLOT(ConditionChanged(int)));
121123
populateConditionSelection(_condition);
122124

123-
QHBoxLayout *switchLayout = new QHBoxLayout;
125+
auto entryLayout = new QHBoxLayout;
124126
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
125127
{"{{condition}}", _condition},
126128
};
127129
PlaceWidgets(
128130
obs_module_text("AdvSceneSwitcher.condition.pluginState.entry"),
129-
switchLayout, widgetPlaceholders);
131+
entryLayout, widgetPlaceholders);
132+
entryLayout->setContentsMargins(0, 0, 0, 0);
130133

131-
QVBoxLayout *mainLayout = new QVBoxLayout;
132-
mainLayout->addLayout(switchLayout);
134+
auto mainLayout = new QVBoxLayout;
135+
mainLayout->addLayout(entryLayout);
136+
mainLayout->addWidget(_shutdownLimitation);
133137
setLayout(mainLayout);
134138

135139
_entryData = entryData;
@@ -155,6 +159,7 @@ void MacroConditionPluginStateEdit::ConditionChanged(int idx)
155159
MacroConditionPluginState::Condition::OBS_SHUTDOWN) {
156160
switcher->shutdownConditionCount++;
157161
}
162+
SetWidgetVisibility();
158163
}
159164

160165
void MacroConditionPluginStateEdit::UpdateEntryData()
@@ -165,6 +170,16 @@ void MacroConditionPluginStateEdit::UpdateEntryData()
165170

166171
_condition->setCurrentIndex(
167172
_condition->findData(static_cast<int>(_entryData->_condition)));
173+
SetWidgetVisibility();
174+
}
175+
176+
void MacroConditionPluginStateEdit::SetWidgetVisibility()
177+
{
178+
_shutdownLimitation->setVisible(
179+
_entryData->_condition ==
180+
MacroConditionPluginState::Condition::OBS_SHUTDOWN);
181+
adjustSize();
182+
updateGeometry();
168183
}
169184

170185
} // namespace advss

src/macro-core/macro-condition-plugin-state.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ private slots:
5858
void ConditionChanged(int idx);
5959

6060
protected:
61+
void SetWidgetVisibility();
62+
6163
QComboBox *_condition;
64+
QLabel *_shutdownLimitation;
6265
std::shared_ptr<MacroConditionPluginState> _entryData;
6366

6467
private:

0 commit comments

Comments
 (0)