Compare commits

...

8 Commits

Author SHA1 Message Date
WarmUpTill
189fa5c314 toolbar 2026-01-20 20:10:21 +01:00
WarmUpTill
393d70be33 widget wrapper 2026-01-19 19:08:33 +01:00
WarmUpTill
422c1a39cb layout stuff 2026-01-18 12:30:07 +01:00
WarmUpTill
a8d483f5a7 Enable un-/pausing all macros in a group 2026-01-13 21:45:04 +01:00
WarmUpTill
dc786a5313 Cleanup 'find and replace' layout in variable action 2026-01-13 21:44:17 +01:00
WarmUpTill
628a4d896c Add option to stop plugin in case unclean shutdown is detected 2026-01-05 10:58:55 +01:00
WarmUpTill
74a9681c8e Fix deadlock when opening settings window 2026-01-05 10:58:55 +01:00
WarmUpTill
faf52c38bb Add temp var for window text 2026-01-05 10:58:55 +01:00
20 changed files with 469 additions and 170 deletions

View File

@@ -184,6 +184,8 @@ target_sources(
lib/utils/canvas-helpers.hpp
lib/utils/condition-logic.cpp
lib/utils/condition-logic.hpp
lib/utils/crash-handler.cpp
lib/utils/crash-handler.hpp
lib/utils/curl-helper.cpp
lib/utils/curl-helper.hpp
lib/utils/cursor-shape-changer.cpp

View File

@@ -157,13 +157,11 @@ AdvSceneSwitcher.mqttConnectionTab.removeMultipleConnectionsPopup.text="Are you
# Macro Tab
AdvSceneSwitcher.macroTab.title="Macro"
AdvSceneSwitcher.macroTab.macros="Macros"
AdvSceneSwitcher.macroTab.priorityWarning="Note: It is recommended to configure macros to be the highest priority functionality.\nThis setting can be changed on the General tab."
AdvSceneSwitcher.macroTab.help="Macros allow you to execute a string of actions depending on multiple conditions.\n\nClick on the highlighted plus symbol to add a new Macro."
AdvSceneSwitcher.macroTab.editConditionHelp="This section allows you to define macro conditions.\n\nSelect an existing or add a new macro on the left.\nThen click the plus button below to add a new condition."
AdvSceneSwitcher.macroTab.editActionHelp="This section allows you to define macro actions.\nThe actions in this section will be performed when the conditions are met.\n\nSelect an existing or add a new macro on the left.\nThen click the plus button below to add a new action."
AdvSceneSwitcher.macroTab.editElseActionHelp="This section allows you to define macro actions.\nThe actions in this section will be performed when the conditions are *not* met.\n\nSelect an existing or add a new macro on the left.\nThen click the plus button below to add a new action."
AdvSceneSwitcher.macroTab.edit="Edit macro"
AdvSceneSwitcher.macroTab.edit.logic="Logic type:"
AdvSceneSwitcher.macroTab.edit.condition="Condition type:"
AdvSceneSwitcher.macroTab.edit.action="Action type:"
@@ -1214,8 +1212,8 @@ AdvSceneSwitcher.action.variable.currentSegmentValue="Current value:"
AdvSceneSwitcher.action.variable.layout.other="{{actions}}{{variables}}{{variables2}}{{strValue}}{{numValue}}{{segmentIndex}}{{mathExpression}}{{envVariableName}}{{scenes}}{{tempVars}}{{tempVarsHelp}}{{sceneItemIndex}}{{direction}}{{stringLength}}{{paddingCharSelection}}{{caseType}}{{jsonQuery}}{{jsonQueryHelp}}{{jsonIndex}}"
AdvSceneSwitcher.action.variable.layout.pad="{{actions}}of{{variables}}to length{{stringLength}}by adding{{paddingCharSelection}}to the{{direction}}"
AdvSceneSwitcher.action.variable.layout.truncate="{{actions}}of{{variables}}to length{{stringLength}}by removing characters from the{{direction}}"
AdvSceneSwitcher.action.variable.layout.substringIndex="Substring start:{{subStringStart}}Substring size:{{subStringSize}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="Assign value of{{regexMatchIdx}}match using regular expression:"
AdvSceneSwitcher.action.variable.layout.substringIndex="Substring start:{{subStringStart}}Substring size:{{subStringSize}}{{subStringRegex}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="Assign value of{{regexMatchIdx}}match using regular expression:{{subStringRegex}}"
AdvSceneSwitcher.action.variable.layout.findAndReplace="{{findStr}}{{findRegex}}{{replaceStr}}"
AdvSceneSwitcher.action.variable.layout.userInput.customPrompt="{{useCustomPrompt}}Use custom prompt{{inputPrompt}}"
AdvSceneSwitcher.action.variable.layout.userInput.placeholder="{{useInputPlaceholder}}Fill with placeholder{{inputPlaceholder}}"
@@ -1390,6 +1388,8 @@ AdvSceneSwitcher.hotkey.macro.segment.remove="Remove selected macro segment"
AdvSceneSwitcher.askBackup="Detected a new version of the Advanced Scene Switcher.\nShould a backup of the old settings be created?"
AdvSceneSwitcher.askForMacro="Select macro{{macroSelection}}"
AdvSceneSwitcher.crashDetected="OBS did not shut down cleanly (for example, due to a crash or freeze).\n\nThe Advanced Scene Switcher plugin would normally start automatically.\nWould you like to keep it stopped for now?"
AdvSceneSwitcher.close="Close"
AdvSceneSwitcher.browse="Browse"
@@ -2149,6 +2149,8 @@ AdvSceneSwitcher.tempVar.window.window="Window title"
AdvSceneSwitcher.tempVar.window.window.description="The window title of the matching window."
AdvSceneSwitcher.tempVar.window.windowClass="Window class"
AdvSceneSwitcher.tempVar.window.windowClass.description="The window class of the matching window."
AdvSceneSwitcher.tempVar.window.windowText="Window text"
AdvSceneSwitcher.tempVar.window.windowText.description="Text contained within the window (won't work on all window types)."
AdvSceneSwitcher.tempVar.timer.seconds="Seconds"
AdvSceneSwitcher.tempVar.timer.minutes="Minutes"

View File

@@ -701,8 +701,8 @@ AdvSceneSwitcher.action.variable.invalidSelection="Sélection invalide !"
AdvSceneSwitcher.action.variable.actionNoVariableSupport="La récupération de valeurs de variables à partir d'actions %1 n'est pas prise en charge !"
AdvSceneSwitcher.action.variable.conditionNoVariableSupport="La récupération de valeurs de variables à partir de conditions %1 n'est pas prise en charge !"
AdvSceneSwitcher.action.variable.currentSegmentValue="Valeur actuelle :"
AdvSceneSwitcher.action.variable.layout.substringIndex="Début de la sous-chaîne :{{subStringStart}}Taille de la sous-chaîne :{{subStringSize}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="Attribuer la valeur du match{{regexMatchIdx}}en utilisant une expression régulière :"
AdvSceneSwitcher.action.variable.layout.substringIndex="Début de la sous-chaîne :{{subStringStart}}Taille de la sous-chaîne :{{subStringSize}}{{subStringRegex}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="Attribuer la valeur du match{{regexMatchIdx}}en utilisant une expression régulière:{{subStringRegex}}"
AdvSceneSwitcher.action.variable.layout.userInput.customPrompt="{{useCustomPrompt}}Utiliser un message personnalisé{{inputPrompt}}"
AdvSceneSwitcher.action.variable.layout.userInput.placeholder="{{useInputPlaceholder}}Remplir avec un indicateur de position{{inputPlaceholder}}"
AdvSceneSwitcher.action.projector="Projecteur"

View File

@@ -1149,8 +1149,8 @@ AdvSceneSwitcher.action.variable.currentSegmentValue="現在値:"
; AdvSceneSwitcher.action.variable.layout.other="{{actions}}{{variables}}{{variables2}}{{strValue}}{{numValue}}{{segmentIndex}}{{mathExpression}}{{envVariableName}}{{scenes}}{{tempVars}}{{tempVarsHelp}}{{sceneItemIndex}}{{direction}}{{stringLength}}{{paddingCharSelection}}"
AdvSceneSwitcher.action.variable.layout.pad="{{actions}}の{{variables}}の長さを{{stringLength}}にするには、{{paddingCharSelection}}を{{direction}}に追加します。"
AdvSceneSwitcher.action.variable.layout.truncate="{{actions}}の{{variables}}の長さを{{stringLength}}にするには、{{direction}}から文字を削除します。"
AdvSceneSwitcher.action.variable.layout.substringIndex="部分文字列の開始:{{subStringStart}}部分文字列のサイズ:{{subStringSize}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="正規表現を使用して{{regexMatchIdx}}一致の値を割り当てます:"
AdvSceneSwitcher.action.variable.layout.substringIndex="部分文字列の開始:{{subStringStart}}部分文字列のサイズ:{{subStringSize}}{{subStringRegex}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="正規表現を使用して{{regexMatchIdx}}一致の値を割り当てます:{{subStringRegex}}"
; AdvSceneSwitcher.action.variable.layout.findAndReplace="{{findStr}}{{findRegex}}{{replaceStr}}"
AdvSceneSwitcher.action.variable.layout.userInput.customPrompt="{{useCustomPrompt}}カスタム プロンプトを使用する{{inputPrompt}}"
AdvSceneSwitcher.action.variable.layout.userInput.placeholder="{{useInputPlaceholder}}プレースホルダーを入力{{inputPlaceholder}}"

View File

@@ -1030,8 +1030,8 @@ AdvSceneSwitcher.action.variable.conditionNoVariableSupport="Obter valores de va
AdvSceneSwitcher.action.variable.currentSegmentValue="Valor atual:"
AdvSceneSwitcher.action.variable.layout.pad="{{actions}}de{{variables}}para comprimento{{stringLength}}adicionando{{paddingCharSelection}}ao{{direction}}"
AdvSceneSwitcher.action.variable.layout.truncate="{{actions}}de{{variables}}para comprimento{{stringLength}}removendo caracteres da{{direction}}"
AdvSceneSwitcher.action.variable.layout.substringIndex="Início da substring:{{subStringStart}}Tamanho da substring:{{subStringSize}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="Atribuir valor do{{regexMatchIdx}}correspondência usando expressão regular:"
AdvSceneSwitcher.action.variable.layout.substringIndex="Início da substring:{{subStringStart}}Tamanho da substring:{{subStringSize}}{{subStringRegex}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="Atribuir valor do{{regexMatchIdx}}correspondência usando expressão regular:{{subStringRegex}}"
AdvSceneSwitcher.action.variable.layout.findAndReplace="{{findStr}}{{findRegex}}{{replaceStr}}"
AdvSceneSwitcher.action.variable.layout.userInput.customPrompt="{{useCustomPrompt}}Usar prompt personalizado{{inputPrompt}}"
AdvSceneSwitcher.action.variable.layout.userInput.placeholder="{{useInputPlaceholder}}Preencher com placeholder{{inputPlaceholder}}"

View File

@@ -1100,8 +1100,8 @@ AdvSceneSwitcher.action.variable.conditionNoVariableSupport="不支持从 %1 条
AdvSceneSwitcher.action.variable.currentSegmentValue="当前值:"
AdvSceneSwitcher.action.variable.layout.pad="{{actions}}于{{variables}}的{{direction}}起,内容为{{paddingCharSelection}}将其变量值长度增加至{{stringLength}}."
AdvSceneSwitcher.action.variable.layout.truncate="{{actions}}于{{variables}}的{{direction}}起,将变量长度缩减至{{stringLength}}"
AdvSceneSwitcher.action.variable.layout.substringIndex="截取字符串开始位置:{{subStringStart}} 截取字符串长度:{{subStringSize}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="使用正则表达式为 {{regexMatchIdx}} 匹配的值:"
AdvSceneSwitcher.action.variable.layout.substringIndex="截取字符串开始位置:{{subStringStart}} 截取字符串长度:{{subStringSize}}{{subStringRegex}}"
AdvSceneSwitcher.action.variable.layout.substringRegex="使用正则表达式为 {{regexMatchIdx}} 匹配的值:{{subStringRegex}}"
AdvSceneSwitcher.action.variable.layout.findAndReplace="{{findStr}}{{findRegex}}{{replaceStr}}"
AdvSceneSwitcher.action.variable.layout.userInput.customPrompt="{{useCustomPrompt}}使用自定义提示{{inputPrompt}}"
AdvSceneSwitcher.action.variable.layout.userInput.placeholder="{{useInputPlaceholder}}用占位符填充{{inputPlaceholder}}"

View File

@@ -68,10 +68,22 @@
<x>0</x>
<y>0</y>
<width>962</width>
<height>1160</height>
<height>1142</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_19">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="statusBox">
<property name="title">
@@ -590,11 +602,8 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>AdvSceneSwitcher.macroTab.macros</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_36">
<widget class="QWidget" name="wrapper">
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QLabel" name="macroPriorityWarning">
<property name="text">
@@ -677,66 +686,34 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="macroControlLayout">
<item>
<widget class="QToolButton" name="macroAdd">
<property name="toolTip">
<string>AdvSceneSwitcher.macroTab.tooltip.macroAddButton</string>
</property>
<property name="themeID" stdset="0">
<string notr="true">addIconSmall</string>
</property>
<property name="class" stdset="0">
<string notr="true">icon-plus</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="macroRemove">
<property name="toolTip">
<string>AdvSceneSwitcher.macroTab.tooltip.macroRemoveButton</string>
</property>
<property name="themeID" stdset="0">
<string notr="true">removeIconSmall</string>
</property>
<property name="class" stdset="0">
<string notr="true">icon-trash</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="macroUp">
<property name="toolTip">
<string>AdvSceneSwitcher.macroTab.tooltip.macroUpButton</string>
</property>
<property name="themeID" stdset="0">
<string notr="true">upArrowIconSmall</string>
</property>
<property name="class" stdset="0">
<string notr="true">icon-up</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="macroDown">
<property name="toolTip">
<string>AdvSceneSwitcher.macroTab.tooltip.macroDownButton</string>
</property>
<property name="themeID" stdset="0">
<string notr="true">downArrowIconSmall</string>
</property>
<property name="class" stdset="0">
<string notr="true">icon-down</string>
</property>
</widget>
</item>
</layout>
<widget class="QToolBar" name="macrosToolbar">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<addaction name="macroAdd"/>
<addaction name="macroRemove"/>
<addaction name="separator"/>
<addaction name="macroUp"/>
<addaction name="macroDown"/>
</widget>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="macroEditGroup">
<property name="title">
<string>AdvSceneSwitcher.macroTab.edit</string>
<string>AdvSceneSwitcher.macroTab.title</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_38">
<item>
@@ -4045,6 +4022,78 @@
</widget>
</item>
</layout>
<action name="macroAdd">
<property name="icon">
<iconset>
<normaloff>:/res/images/plus.svg</normaloff>:/res/images/plus.svg</iconset>
</property>
<property name="text">
<string>Add</string>
</property>
<property name="toolTip">
<string>AdvSceneSwitcher.macroTab.tooltip.macroAddButton</string>
</property>
<property name="class" stdset="0">
<string notr="true">icon-plus</string>
</property>
<property name="themeID" stdset="0">
<string notr="true">addIconSmall</string>
</property>
</action>
<action name="macroRemove">
<property name="icon">
<iconset>
<normaloff>:/res/images/minus.svg</normaloff>:/res/images/minus.svg</iconset>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="toolTip">
<string>AdvSceneSwitcher.macroTab.tooltip.macroRemoveButton</string>
</property>
<property name="shortcut">
<string>Del</string>
</property>
<property name="shortcutContext">
<enum>Qt::WidgetWithChildrenShortcut</enum>
</property>
<property name="iconVisibleInMenu">
<bool>false</bool>
</property>
<property name="class" stdset="0">
<string notr="true">icon-trash</string>
</property>
</action>
<action name="macroUp">
<property name="icon">
<iconset>
<normaloff>:/res/images/up.svg</normaloff>:/res/images/up.svg</iconset>
</property>
<property name="text">
<string>MoveUp</string>
</property>
<property name="toolTip">
<string>AdvSceneSwitcher.macroTab.tooltip.macroUpButton</string>
</property>
<property name="class" stdset="0">
<string notr="true">icon-up</string>
</property>
</action>
<action name="macroDown">
<property name="icon">
<iconset>
<normaloff>:/res/images/down.svg</normaloff>:/res/images/down.svg</iconset>
</property>
<property name="text">
<string>MoveDown</string>
</property>
<property name="toolTip">
<string>AdvSceneSwitcher.macroTab.tooltip.macroDownButton</string>
</property>
<property name="class" stdset="0">
<string notr="true">icon-down</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
@@ -4110,11 +4159,6 @@
<tabstop>priorityUp</tabstop>
<tabstop>priorityDown</tabstop>
<tabstop>threadPriority</tabstop>
<tabstop>macros</tabstop>
<tabstop>macroAdd</tabstop>
<tabstop>macroRemove</tabstop>
<tabstop>macroUp</tabstop>
<tabstop>macroDown</tabstop>
<tabstop>macroName</tabstop>
<tabstop>runMacro</tabstop>
<tabstop>runMacroInParallel</tabstop>

View File

@@ -1,5 +1,6 @@
#include "advanced-scene-switcher.hpp"
#include "backup.hpp"
#include "crash-handler.hpp"
#include "log-helper.hpp"
#include "macro-helpers.hpp"
#include "obs-module-helper.hpp"
@@ -207,9 +208,15 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
switcher->LoadSettings(data);
switcher->m.unlock();
if (!switcher->stop) {
switcher->Start();
if (switcher->stop) {
return;
}
if (ShouldSkipPluginStartOnUncleanShutdown()) {
return;
}
switcher->Start();
}
}

View File

@@ -101,10 +101,10 @@ public:
void HighlightMacroSettingsButton(bool enable = true);
public slots:
void on_macroAdd_clicked();
void on_macroRemove_clicked();
void on_macroUp_clicked() const;
void on_macroDown_clicked() const;
void on_macroAdd_triggered();
void on_macroRemove_triggered();
void on_macroUp_triggered() const;
void on_macroDown_triggered() const;
void on_macroName_editingFinished();
void on_runMacroInParallel_stateChanged(int value) const;
void on_runMacroOnChange_stateChanged(int value) const;

View File

@@ -801,11 +801,10 @@ MacroActionVariableEdit::MacroActionVariableEdit(
_segmentValueStatus(new QLabel()),
_segmentValue(new ResizingPlainTextEdit(this, 10, 1, 1)),
_substringLayout(new QVBoxLayout()),
_subStringIndexEntryLayout(new QHBoxLayout()),
_subStringRegexEntryLayout(new QHBoxLayout()),
_subStringControlsLayout(new QHBoxLayout()),
_subStringStart(new VariableSpinBox(this)),
_subStringSize(new VariableSpinBox(this)),
_substringRegex(new RegexConfigWidget(parent)),
_subStringRegex(new RegexConfigWidget(parent)),
_regexPattern(new ResizingPlainTextEdit(this, 10, 1, 1)),
_regexMatchIdx(new VariableSpinBox(this)),
_findReplaceLayout(new QHBoxLayout()),
@@ -901,7 +900,7 @@ MacroActionVariableEdit::MacroActionVariableEdit(
_subStringSize,
SIGNAL(NumberVariableChanged(const NumberVariable<int> &)),
this, SLOT(SubStringSizeChanged(const NumberVariable<int> &)));
QWidget::connect(_substringRegex,
QWidget::connect(_subStringRegex,
SIGNAL(RegexConfigChanged(const RegexConfig &)), this,
SLOT(SubStringRegexChanged(const RegexConfig &)));
QWidget::connect(_regexPattern, SIGNAL(textChanged()), this,
@@ -975,9 +974,6 @@ MacroActionVariableEdit::MacroActionVariableEdit(
{"{{strValue}}", _strValue},
{"{{numValue}}", _numValue},
{"{{segmentIndex}}", _segmentIdx},
{"{{subStringStart}}", _subStringStart},
{"{{subStringSize}}", _subStringSize},
{"{{regexMatchIdx}}", _regexMatchIdx},
{"{{findRegex}}", _findRegex},
{"{{findStr}}", _findStr},
{"{{replaceStr}}", _replaceStr},
@@ -1009,12 +1005,7 @@ MacroActionVariableEdit::MacroActionVariableEdit(
PlaceWidgets(
obs_module_text(
"AdvSceneSwitcher.action.variable.layout.substringIndex"),
_subStringIndexEntryLayout, widgetPlaceholders);
PlaceWidgets(
obs_module_text(
"AdvSceneSwitcher.action.variable.layout.substringRegex"),
_subStringRegexEntryLayout, widgetPlaceholders);
_subStringControlsLayout, widgetPlaceholders);
PlaceWidgets(
obs_module_text(
@@ -1039,11 +1030,10 @@ MacroActionVariableEdit::MacroActionVariableEdit(
_randomLayout->addWidget(_generateInteger);
auto regexConfigLayout = new QHBoxLayout;
regexConfigLayout->addWidget(_substringRegex);
regexConfigLayout->addWidget(_subStringRegex);
regexConfigLayout->addStretch();
_substringLayout->addLayout(_subStringIndexEntryLayout);
_substringLayout->addLayout(_subStringRegexEntryLayout);
_substringLayout->addLayout(_subStringControlsLayout);
_substringLayout->addWidget(_regexPattern);
_substringLayout->addLayout(regexConfigLayout);
@@ -1090,7 +1080,7 @@ void MacroActionVariableEdit::UpdateEntryData()
: MacroSegmentSelection::Type::ACTION);
_subStringStart->SetValue(_entryData->_subStringStart);
_subStringSize->SetValue(_entryData->_subStringSize);
_substringRegex->SetRegexConfig(_entryData->_subStringRegex);
_subStringRegex->SetRegexConfig(_entryData->_subStringRegex);
_findRegex->SetRegexConfig(_entryData->_findRegex);
_regexPattern->setPlainText(
QString::fromStdString(_entryData->_regexPattern));
@@ -1495,8 +1485,20 @@ void MacroActionVariableEdit::SetWidgetVisibility()
{"{{jsonQuery}}", _jsonQuery},
{"{{jsonQueryHelp}}", _jsonQueryHelp},
{"{{jsonIndex}}", _jsonIndex},
{"{{subStringRegex}}", _subStringRegex},
{"{{subStringStart}}", _subStringStart},
{"{{subStringSize}}", _subStringSize},
{"{{regexMatchIdx}}", _regexMatchIdx},
};
for (const auto &[_, widget] : widgetPlaceholders) {
_entryLayout->removeWidget(widget);
_subStringControlsLayout->removeWidget(widget);
}
ClearLayout(_entryLayout);
ClearLayout(_subStringControlsLayout);
const char *layoutString = "";
if (_entryData->_action == MacroActionVariable::Action::PAD) {
layoutString = obs_module_text(
@@ -1510,11 +1512,6 @@ void MacroActionVariableEdit::SetWidgetVisibility()
"AdvSceneSwitcher.action.variable.layout.other");
}
for (const auto &[_, widget] : widgetPlaceholders) {
_entryLayout->removeWidget(widget);
}
ClearLayout(_entryLayout);
PlaceWidgets(layoutString, _entryLayout, widgetPlaceholders);
if (_entryData->_action == MacroActionVariable::Action::SET_VALUE ||
@@ -1561,15 +1558,25 @@ void MacroActionVariableEdit::SetWidgetVisibility()
MacroActionVariable::Action::SET_ACTION_VALUE ||
_entryData->_action ==
MacroActionVariable::Action::SET_CONDITION_VALUE);
bool showRegex = _entryData->_subStringRegex.Enabled();
layoutString =
showRegex
? "AdvSceneSwitcher.action.variable.layout.substringRegex"
: "AdvSceneSwitcher.action.variable.layout.substringIndex";
PlaceWidgets(obs_module_text(layoutString), _subStringControlsLayout,
widgetPlaceholders);
_subStringStart->setVisible(!showRegex);
_subStringSize->setVisible(!showRegex);
_regexMatchIdx->setVisible(showRegex);
SetLayoutVisible(_substringLayout,
_entryData->_action ==
MacroActionVariable::Action::SUBSTRING);
if (_entryData->_action == MacroActionVariable::Action::SUBSTRING) {
bool showRegex = _entryData->_subStringRegex.Enabled();
SetLayoutVisible(_subStringIndexEntryLayout, !showRegex);
SetLayoutVisible(_subStringRegexEntryLayout, showRegex);
_regexPattern->setVisible(showRegex);
}
_regexPattern->setVisible(
showRegex &&
_entryData->_action == MacroActionVariable::Action::SUBSTRING);
SetLayoutVisible(_findReplaceLayout,
_entryData->_action ==
MacroActionVariable::Action::FIND_AND_REPLACE);

View File

@@ -194,11 +194,10 @@ private:
QLabel *_segmentValueStatus;
ResizingPlainTextEdit *_segmentValue;
QVBoxLayout *_substringLayout;
QHBoxLayout *_subStringIndexEntryLayout;
QHBoxLayout *_subStringRegexEntryLayout;
QHBoxLayout *_subStringControlsLayout;
VariableSpinBox *_subStringStart;
VariableSpinBox *_subStringSize;
RegexConfigWidget *_substringRegex;
RegexConfigWidget *_subStringRegex;
ResizingPlainTextEdit *_regexPattern;
VariableSpinBox *_regexMatchIdx;
QHBoxLayout *_findReplaceLayout;

View File

@@ -97,7 +97,7 @@ bool AdvSceneSwitcher::AddNewMacro(std::shared_ptr<Macro> &res,
return true;
}
void AdvSceneSwitcher::on_macroAdd_clicked()
void AdvSceneSwitcher::on_macroAdd_triggered()
{
// Hotkey to add new macro will also use this function.
// Since we don't want the hotkey to have an effect if the macro tab is
@@ -247,12 +247,12 @@ void AdvSceneSwitcher::RenameMacro(std::shared_ptr<Macro> &macro,
MacroSignalManager::Instance()->Rename(oldName, name);
}
void AdvSceneSwitcher::on_macroRemove_clicked()
void AdvSceneSwitcher::on_macroRemove_triggered()
{
RemoveSelectedMacros();
}
void AdvSceneSwitcher::on_macroUp_clicked() const
void AdvSceneSwitcher::on_macroUp_triggered() const
{
auto macro = GetSelectedMacro();
if (!macro) {
@@ -261,7 +261,7 @@ void AdvSceneSwitcher::on_macroUp_clicked() const
ui->macros->Up(macro);
}
void AdvSceneSwitcher::on_macroDown_clicked() const
void AdvSceneSwitcher::on_macroDown_triggered() const
{
auto macro = GetSelectedMacro();
if (!macro) {
@@ -632,13 +632,11 @@ void AdvSceneSwitcher::SetupMacroTab()
auto &macros = GetTopLevelMacros();
if (macros.size() == 0 && !switcher->disableHints) {
addPulse = HighlightWidget(ui->macroAdd, QColor(Qt::green));
addPulse = HighlightWidget(
ui->macrosToolbar->widgetForAction(ui->macroAdd),
QColor(Qt::green));
}
auto macroControls = setupToolBar({{ui->macroAdd, ui->macroRemove},
{ui->macroUp, ui->macroDown}});
ui->macroControlLayout->addWidget(macroControls);
ui->macros->Reset(macros, GetGlobalMacroSettings()._highlightExecuted);
connect(ui->macros, SIGNAL(MacroSelectionChanged()), this,
SLOT(MacroSelectionChanged()));
@@ -683,7 +681,7 @@ void AdvSceneSwitcher::ShowMacroContextMenu(const QPoint &pos)
menu.addAction(
obs_module_text("AdvSceneSwitcher.macroTab.contextMenuAdd"),
this, &AdvSceneSwitcher::on_macroAdd_clicked);
this, &AdvSceneSwitcher::on_macroAdd_triggered);
auto copy = menu.addAction(
obs_module_text("AdvSceneSwitcher.macroTab.copy"), this,
@@ -699,7 +697,7 @@ void AdvSceneSwitcher::ShowMacroContextMenu(const QPoint &pos)
auto remove = menu.addAction(
obs_module_text("AdvSceneSwitcher.macroTab.remove"), this,
&AdvSceneSwitcher::on_macroRemove_clicked);
&AdvSceneSwitcher::on_macroRemove_triggered);
remove->setDisabled(ui->macros->SelectionEmpty());
menu.addSeparator();

View File

@@ -62,12 +62,11 @@ MacroTreeItem::MacroTreeItem(MacroTree *tree, std::shared_ptr<Macro> macroItem,
_boxLayout = new QHBoxLayout();
_boxLayout->setContentsMargins(0, 0, 0, 0);
_boxLayout->addWidget(_running);
if (isGroup) {
_boxLayout->addWidget(_iconLabel);
_boxLayout->addSpacing(2);
_running->hide();
}
_boxLayout->addWidget(_running);
_boxLayout->addWidget(_label);
#ifdef __APPLE__
/* Hack: Fixes a bug where scrollbars would be above the lock icon */
@@ -77,17 +76,17 @@ MacroTreeItem::MacroTreeItem(MacroTree *tree, std::shared_ptr<Macro> macroItem,
Update(true);
setLayout(_boxLayout);
auto setRunning = [this](bool val) {
_macro->SetPaused(!val);
};
connect(_running, &QAbstractButton::clicked, setRunning);
connect(_running, SIGNAL(clicked(bool)), this,
SLOT(RunningClicked(bool)));
connect(MacroSignalManager::Instance(), SIGNAL(HighlightChanged(bool)),
this, SLOT(EnableHighlight(bool)));
connect(MacroSignalManager::Instance(),
SIGNAL(Rename(const QString &, const QString &)), this,
SLOT(MacroRenamed(const QString &, const QString &)));
connect(&_timer, SIGNAL(timeout()), this, SLOT(HighlightIfExecuted()));
connect(&_timer, SIGNAL(timeout()), this, SLOT(UpdatePaused()));
connect(&_timer, SIGNAL(timeout()), this, SLOT(UpdateRunning()));
UpdateRunning();
_timer.start(1500);
}
@@ -96,10 +95,90 @@ void MacroTreeItem::EnableHighlight(bool enable)
_highlight = enable;
}
void MacroTreeItem::UpdatePaused()
void MacroTreeItem::RunningClicked(bool running)
{
const auto updateWidget = [this](Macro *macro) {
if (!macro) {
return;
}
const auto &macros = GetTopLevelMacros();
bool found = false;
int idx = 0;
for (const auto &m : macros) {
if (m.get() == macro) {
found = true;
break;
}
idx++;
}
if (!found) {
return;
}
const auto widget = _tree->GetItemWidget(idx);
if (widget) {
widget->UpdateRunning();
}
};
if (!_macro->IsGroup()) {
_macro->SetPaused(!running);
if (!_macro->IsSubitem()) {
return;
}
const auto group = _macro->Parent();
updateWidget(group.get());
return;
}
const auto macros = GetGroupMacroEntries(_macro.get());
for (const auto &macro : macros) {
macro->SetPaused(!running);
}
// Update backend values before updating UI to prevent flickering in
// running state of the group
for (const auto &macro : macros) {
updateWidget(macro.get());
}
UpdateRunning();
}
void MacroTreeItem::UpdateRunning()
{
const QSignalBlocker blocker(_running);
_running->setChecked(!_macro->Paused());
if (!_macro->IsGroup()) {
_running->setChecked(!_macro->Paused());
return;
}
const auto macros = GetGroupMacroEntries(_macro.get());
bool allRunning = true;
bool allPaused = true;
for (const auto &macro : macros) {
if (macro->Paused()) {
allRunning = false;
} else {
allPaused = false;
}
}
if (allRunning) {
_running->setCheckState(Qt::Checked);
return;
}
if (allPaused) {
_running->setCheckState(Qt::Unchecked);
return;
}
_running->setCheckState(Qt::PartiallyChecked);
}
void MacroTreeItem::HighlightIfExecuted()
@@ -214,7 +293,6 @@ void MacroTreeModel::Reset(std::deque<std::shared_ptr<Macro>> &newItems)
_macros = newItems;
endResetModel();
UpdateGroupState(false);
_mt->ResetWidgets();
}
@@ -459,9 +537,6 @@ void MacroTreeModel::Remove(std::shared_ptr<Macro> item)
_mt->selectionModel()->clear();
if (isGroup) {
UpdateGroupState(true);
}
assert(IsInValidState());
}
@@ -550,7 +625,6 @@ MacroTreeModel::MacroTreeModel(MacroTree *st_,
_mt(st_),
_macros(macros)
{
UpdateGroupState(false);
}
int MacroTreeModel::rowCount(const QModelIndex &parent) const
@@ -704,7 +778,6 @@ void MacroTreeModel::GroupSelectedItems(QModelIndexList &indices)
offset++;
}
_hasGroups = true;
_mt->selectionModel()->clear();
Reset(_macros);
@@ -762,24 +835,6 @@ void MacroTreeModel::CollapseGroup(std::shared_ptr<Macro> item)
assert(IsInValidState());
}
void MacroTreeModel::UpdateGroupState(bool update)
{
bool nowHasGroups = false;
for (auto &item : _macros) {
if (item->IsGroup()) {
nowHasGroups = true;
break;
}
}
if (nowHasGroups != _hasGroups) {
_hasGroups = nowHasGroups;
if (update) {
_mt->UpdateWidgets(true);
}
}
}
void MacroTree::Reset(std::deque<std::shared_ptr<Macro>> &macros,
bool highlight)
{
@@ -842,7 +897,6 @@ MacroTree::MacroTree(QWidget *parent_) : QListView(parent_)
void MacroTree::ResetWidgets()
{
MacroTreeModel *mtm = GetModel();
mtm->UpdateGroupState(false);
int modelIdx = 0;
for (int i = 0; i < (int)mtm->_macros.size(); i++) {
QModelIndex index = mtm->createIndex(modelIdx, 0, nullptr);

View File

@@ -37,7 +37,8 @@ public:
private slots:
void ExpandClicked(bool checked);
void EnableHighlight(bool enable);
void UpdatePaused();
void RunningClicked(bool);
void UpdateRunning();
void HighlightIfExecuted();
void MacroRenamed(const QString &, const QString &);
@@ -106,7 +107,6 @@ private:
void UngroupSelectedGroups(QModelIndexList &indices);
void ExpandGroup(std::shared_ptr<Macro> item);
void CollapseGroup(std::shared_ptr<Macro> item);
void UpdateGroupState(bool update);
int GetItemMacroIndex(const std::shared_ptr<Macro> &item) const;
int GetItemModelIndex(const std::shared_ptr<Macro> &item) const;
bool IsLastItem(std::shared_ptr<Macro> item) const;
@@ -114,7 +114,6 @@ private:
MacroTree *_mt;
std::deque<std::shared_ptr<Macro>> &_macros;
bool _hasGroups = false;
friend class MacroTree;
friend class MacroTreeItem;

135
lib/utils/crash-handler.cpp Normal file
View File

@@ -0,0 +1,135 @@
#include "crash-handler.hpp"
#include "log-helper.hpp"
#include "obs-module-helper.hpp"
#include "plugin-state-helpers.hpp"
#include "ui-helpers.hpp"
#include <obs-frontend-api.h>
#include <obs-module.h>
#include <QDir>
#include <QFile>
#include <thread>
namespace advss {
static constexpr std::string_view sentinel = ".running";
#ifndef NDEBUG
static constexpr bool handleUncleanShutdown = false;
#else
static constexpr bool handleUncleanShutdown = true;
#endif
static bool wasCleanShutdown = false;
static void setup();
static bool setupDone = []() {
AddPluginInitStep(setup);
return true;
}();
static void handleShutdown(enum obs_frontend_event event, void *)
{
if (event != OBS_FRONTEND_EVENT_EXIT) {
return;
}
char *sentinelFile = obs_module_config_path(sentinel.data());
if (!sentinelFile) {
return;
}
QFile file(sentinelFile);
if (!file.exists()) {
bfree(sentinelFile);
return;
}
if (!file.remove()) {
blog(LOG_WARNING, "failed to remove sentinel file");
}
bfree(sentinelFile);
}
static void setup()
{
char *sentinelFile = obs_module_config_path(sentinel.data());
if (!sentinelFile) {
return;
}
QString dirPath = QFileInfo(sentinelFile).absolutePath();
QDir dir(dirPath);
if (!dir.exists()) {
if (!dir.mkpath(dirPath)) {
blog(LOG_WARNING,
"failed to create directory for sentinel file");
bfree(sentinelFile);
return;
}
}
QFile file(sentinelFile);
wasCleanShutdown = file.exists();
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
blog(LOG_WARNING, "failed to create sentinel file");
bfree(sentinelFile);
return;
}
file.write("running");
file.close();
bfree(sentinelFile);
obs_frontend_add_event_callback(handleShutdown, nullptr);
return;
}
static bool wasUncleanShutdown()
{
static bool alreadyHandled = false;
if (!handleUncleanShutdown || !wasCleanShutdown || alreadyHandled) {
alreadyHandled = true;
return false;
}
alreadyHandled = true;
blog(LOG_WARNING, "unclean shutdown detected");
return true;
}
static bool askForStartupSkip()
{
return DisplayMessage(obs_module_text("AdvSceneSwitcher.crashDetected"),
true, false);
}
bool ShouldSkipPluginStartOnUncleanShutdown()
{
if (!wasUncleanShutdown()) {
return false;
}
std::thread t([]() {
obs_queue_task(
OBS_TASK_UI,
[](void *) {
const bool skipStart = askForStartupSkip();
if (!skipStart) {
StartPlugin();
}
},
nullptr, false);
});
t.detach();
return true;
}
} // namespace advss

View File

@@ -0,0 +1,7 @@
#pragma once
namespace advss {
bool ShouldSkipPluginStartOnUncleanShutdown();
} // namespace advss

View File

@@ -57,6 +57,7 @@ ResourceTable::ResourceTable(QWidget *parent, const QString &help,
auto layout = new QVBoxLayout();
layout->addLayout(helpAndTableLayout);
layout->addLayout(controlLayout);
layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);
QWidget::connect(_add, SIGNAL(clicked()), this, SLOT(Add()));

View File

@@ -261,6 +261,14 @@ std::optional<std::string> GetTextInWindow(const std::string &window)
return {};
}
DWORD pid = 0;
DWORD thid = 0;
thid = GetWindowThreadProcessId(hwnd, &pid);
// Calling CoCreateInstance() on the OBS windows might cause a deadlock
if (GetCurrentProcessId() == pid) {
return {};
}
IUIAutomation *automation = nullptr;
auto hr = CoCreateInstance(__uuidof(CUIAutomation), nullptr,
CLSCTX_INPROC_SERVER,

View File

@@ -29,6 +29,22 @@ static bool windowContainsText(const std::string &window,
return text == matchText;
}
void MacroConditionWindow::SetCheckText(bool value)
{
#ifdef _WIN32
_checkText = value;
#else
(void)value;
_checkText = false;
#endif
SetupTempVars();
}
bool MacroConditionWindow::GetCheckText()
{
return _checkText;
}
bool MacroConditionWindow::WindowMatchesRequirements(
const std::string &window) const
{
@@ -94,12 +110,18 @@ void MacroConditionWindow::SetVariableValueBasedOnMatch(
#ifdef _WIN32
SetTempVarValue("windowClass",
GetWindowClassByWindowTitle(matchWindow));
if (_checkText) {
const auto text = GetTextInWindow(matchWindow);
if (text) {
SetTempVarValue("windowText", *text);
}
}
#endif
if (!IsReferencedInVars()) {
return;
}
if (_checkText) {
auto text = GetTextInWindow(matchWindow);
const auto text = GetTextInWindow(matchWindow);
SetVariableValue(text.value_or(""));
} else {
SetVariableValue(ForegroundWindowTitle());
@@ -186,6 +208,16 @@ void MacroConditionWindow::SetupTempVars()
obs_module_text("AdvSceneSwitcher.tempVar.window.windowClass"),
obs_module_text(
"AdvSceneSwitcher.tempVar.window.windowClass.description"));
if (!_checkText) {
return;
}
AddTempvar(
"windowText",
obs_module_text("AdvSceneSwitcher.tempVar.window.windowText"),
obs_module_text(
"AdvSceneSwitcher.tempVar.window.windowText.description"));
#endif
}
@@ -349,7 +381,7 @@ void MacroConditionWindowEdit::CheckTitleChanged(int state)
void MacroConditionWindowEdit::CheckTextChanged(int state)
{
GUARD_LOADING_AND_LOCK();
_entryData->_checkText = state;
_entryData->SetCheckText(state);
SetWidgetVisibility();
}
@@ -409,8 +441,8 @@ void MacroConditionWindowEdit::SetWidgetVisibility()
_entryData->_focus || _entryData->_windowFocusChanged);
_windowSelection->setVisible(_entryData->_checkTitle);
_windowRegex->setVisible(_entryData->_checkTitle);
_textRegex->setVisible(_entryData->_checkText);
_text->setVisible(_entryData->_checkText);
_textRegex->setVisible(_entryData->GetCheckText());
_text->setVisible(_entryData->GetCheckText());
adjustSize();
updateGeometry();
}
@@ -429,7 +461,7 @@ void MacroConditionWindowEdit::UpdateEntryData()
_maximized->setChecked(_entryData->_maximized);
_focused->setChecked(_entryData->_focus);
_windowFocusChanged->setChecked(_entryData->_windowFocusChanged);
_checkText->setChecked(_entryData->_checkText);
_checkText->setChecked(_entryData->GetCheckText());
_text->setPlainText(_entryData->_text);
_textRegex->SetRegexConfig(_entryData->_textRegex);
SetWidgetVisibility();

View File

@@ -22,6 +22,9 @@ public:
return std::make_shared<MacroConditionWindow>(m);
}
void SetCheckText(bool value);
bool GetCheckText();
StringVariable _window;
RegexConfig _windowRegex;
bool _checkTitle = true;
@@ -30,8 +33,6 @@ public:
bool _focus = true;
bool _windowFocusChanged = false;
// For now only supported on Windows
bool _checkText = false;
StringVariable _text;
RegexConfig _textRegex = RegexConfig::PartialMatchRegexConfig();
@@ -42,6 +43,9 @@ private:
void SetVariableValueBasedOnMatch(const std::string &matchWindow);
void SetupTempVars();
// For now only supported on Windows
bool _checkText = false;
static bool _registered;
static const std::string id;
};