mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-18 16:17:23 -05:00
Add option to check for OBS shutdown to MacroConditionPluginState
This commit is contained in:
parent
34167366db
commit
b48276bd5c
|
|
@ -176,6 +176,7 @@ AdvSceneSwitcher.condition.idle.entry="No keyboard or mouse inputs for {{duratio
|
|||
AdvSceneSwitcher.condition.pluginState="Plugin state"
|
||||
AdvSceneSwitcher.condition.pluginState.state.sceneSwitched="Automated scene change was triggered in this interval"
|
||||
AdvSceneSwitcher.condition.pluginState.state.running="Advanced scene switcher is running"
|
||||
AdvSceneSwitcher.condition.pluginState.state.shutdown="OBS is shutting down"
|
||||
AdvSceneSwitcher.condition.pluginState.entry="{{condition}}"
|
||||
AdvSceneSwitcher.condition.timer="Timer"
|
||||
AdvSceneSwitcher.condition.timer.type.fixed="Fixed"
|
||||
|
|
|
|||
|
|
@ -576,6 +576,18 @@ void setStreamStopping()
|
|||
std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void handleExit()
|
||||
{
|
||||
switcher->obsIsShuttingDown = true;
|
||||
if (switcher && switcher->obsIsShuttingDown &&
|
||||
switcher->shutdownConditionCount) {
|
||||
switcher->Stop();
|
||||
switcher->checkMacros();
|
||||
switcher->runMacros();
|
||||
}
|
||||
FreeSceneSwitcher();
|
||||
}
|
||||
|
||||
// Note to future self:
|
||||
// be careful using switcher->m here as there is potential for deadlocks when using
|
||||
// frontend functions such as obs_frontend_set_current_scene()
|
||||
|
|
@ -587,7 +599,7 @@ static void OBSEvent(enum obs_frontend_event event, void *switcher)
|
|||
|
||||
switch (event) {
|
||||
case OBS_FRONTEND_EVENT_EXIT:
|
||||
FreeSceneSwitcher();
|
||||
handleExit();
|
||||
break;
|
||||
case OBS_FRONTEND_EVENT_SCENE_CHANGED:
|
||||
handleSceneChange();
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@
|
|||
#include <QComboBox>
|
||||
|
||||
enum class PluginStateCondition {
|
||||
SCENESWITCHED,
|
||||
SCENE_SWITCHED,
|
||||
RUNNING,
|
||||
SHUTDOWN,
|
||||
};
|
||||
|
||||
class MacroConditionPluginState : public MacroCondition {
|
||||
public:
|
||||
MacroConditionPluginState(Macro *m) : MacroCondition(m) {}
|
||||
~MacroConditionPluginState();
|
||||
bool CheckCondition();
|
||||
bool Save(obs_data_t *obj);
|
||||
bool Load(obs_data_t *obj);
|
||||
|
|
@ -20,7 +22,7 @@ public:
|
|||
return std::make_shared<MacroConditionPluginState>(m);
|
||||
}
|
||||
|
||||
PluginStateCondition _condition = PluginStateCondition::SCENESWITCHED;
|
||||
PluginStateCondition _condition = PluginStateCondition::SCENE_SWITCHED;
|
||||
|
||||
private:
|
||||
static bool _registered;
|
||||
|
|
|
|||
|
|
@ -125,6 +125,8 @@ struct SwitcherData {
|
|||
std::condition_variable macroTransitionCv;
|
||||
bool macroSceneSwitched = false;
|
||||
bool replayBufferSaved = false;
|
||||
bool obsIsShuttingDown = false;
|
||||
int shutdownConditionCount = 0;
|
||||
|
||||
std::deque<WindowSwitch> windowSwitches;
|
||||
std::vector<std::string> ignoreIdleWindows;
|
||||
|
|
|
|||
|
|
@ -12,19 +12,30 @@ bool MacroConditionPluginState::_registered = MacroConditionFactory::Register(
|
|||
"AdvSceneSwitcher.condition.pluginState"});
|
||||
|
||||
static std::map<PluginStateCondition, std::string> pluginStateConditionTypes = {
|
||||
{PluginStateCondition::SCENESWITCHED,
|
||||
{PluginStateCondition::SCENE_SWITCHED,
|
||||
"AdvSceneSwitcher.condition.pluginState.state.sceneSwitched"},
|
||||
{PluginStateCondition::RUNNING,
|
||||
"AdvSceneSwitcher.condition.pluginState.state.running"},
|
||||
{PluginStateCondition::SHUTDOWN,
|
||||
"AdvSceneSwitcher.condition.pluginState.state.shutdown"},
|
||||
};
|
||||
|
||||
MacroConditionPluginState::~MacroConditionPluginState()
|
||||
{
|
||||
if (_condition == PluginStateCondition::SHUTDOWN) {
|
||||
switcher->shutdownConditionCount--;
|
||||
}
|
||||
}
|
||||
|
||||
bool MacroConditionPluginState::CheckCondition()
|
||||
{
|
||||
switch (_condition) {
|
||||
case PluginStateCondition::SCENESWITCHED:
|
||||
case PluginStateCondition::SCENE_SWITCHED:
|
||||
return switcher->macroSceneSwitched;
|
||||
case PluginStateCondition::RUNNING:
|
||||
return true;
|
||||
case PluginStateCondition::SHUTDOWN:
|
||||
return switcher->obsIsShuttingDown;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -43,6 +54,9 @@ bool MacroConditionPluginState::Load(obs_data_t *obj)
|
|||
MacroCondition::Load(obj);
|
||||
_condition = static_cast<PluginStateCondition>(
|
||||
obs_data_get_int(obj, "condition"));
|
||||
if (_condition == PluginStateCondition::SHUTDOWN) {
|
||||
switcher->shutdownConditionCount++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +103,13 @@ void MacroConditionPluginStateEdit::ConditionChanged(int cond)
|
|||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
if (_entryData->_condition == PluginStateCondition::SHUTDOWN) {
|
||||
switcher->shutdownConditionCount--;
|
||||
}
|
||||
_entryData->_condition = static_cast<PluginStateCondition>(cond);
|
||||
if (_entryData->_condition == PluginStateCondition::SHUTDOWN) {
|
||||
switcher->shutdownConditionCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void MacroConditionPluginStateEdit::UpdateEntryData()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user