From 003ffc161b7570eee3360edf471be2ce7cda38ec Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sun, 24 Mar 2024 14:43:45 +0100 Subject: [PATCH] Show warning if system tray is disabled in OBS settings --- data/locale/en-US.ini | 1 + plugins/base/macro-action-systray.cpp | 44 ++++++++++++++++++++++----- plugins/base/macro-action-systray.hpp | 4 +++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 6863a4d0..50103adc 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -853,6 +853,7 @@ AdvSceneSwitcher.action.systray.title="Title:" AdvSceneSwitcher.action.systray.message="Message:" AdvSceneSwitcher.action.systray.icon="Icon:" AdvSceneSwitcher.action.systray.iconHint="Leave blank to use the default icon" +AdvSceneSwitcher.action.systray.disabled="System tray notifications seem to be disabled in the OBS settings!" AdvSceneSwitcher.action.screenshot="Screenshot" AdvSceneSwitcher.action.screenshot.save.default="Default" AdvSceneSwitcher.action.screenshot.save.custom="Custom" diff --git a/plugins/base/macro-action-systray.cpp b/plugins/base/macro-action-systray.cpp index 0e54cc3d..9ebb57a4 100644 --- a/plugins/base/macro-action-systray.cpp +++ b/plugins/base/macro-action-systray.cpp @@ -2,6 +2,9 @@ #include "layout-helpers.hpp" #include "ui-helpers.hpp" +#include +#include + namespace advss { const std::string MacroActionSystray::id = "systray_notification"; @@ -72,7 +75,9 @@ MacroActionSystrayEdit::MacroActionSystrayEdit( : QWidget(parent), _message(new VariableLineEdit(this)), _title(new VariableLineEdit(this)), - _iconPath(new FileSelection()) + _iconPath(new FileSelection()), + _trayDisableWarning( + new QLabel("AdvSceneSwitcher.action.systray.disabled")) { _iconPath->setToolTip( obs_module_text("AdvSceneSwitcher.action.systray.iconHint")); @@ -85,25 +90,35 @@ MacroActionSystrayEdit::MacroActionSystrayEdit( SLOT(IconPathChanged(const QString &))); auto layout = new QGridLayout(); + int row = 0; layout->addWidget(new QLabel(obs_module_text( "AdvSceneSwitcher.action.systray.title")), - 0, 0); - layout->addWidget(_title, 0, 1); + row, 0); + layout->addWidget(_title, ++row, 1); layout->addWidget(new QLabel(obs_module_text( "AdvSceneSwitcher.action.systray.message")), - 1, 0); - layout->addWidget(_message, 1, 1); + row, 0); + layout->addWidget(_message, ++row, 1); layout->addWidget(new QLabel(obs_module_text( "AdvSceneSwitcher.action.systray.icon")), - 2, 0); - layout->addWidget(_iconPath, 2, 1); - setLayout(layout); + row, 0); + layout->addWidget(_iconPath, ++row, 1); + + auto mainlayout = new QVBoxLayout(); + mainlayout->addLayout(layout); + mainlayout->addWidget(_trayDisableWarning); + setLayout(mainlayout); _entryData = entryData; _message->setText(_entryData->_message); _title->setText(_entryData->_title); _iconPath->SetPath(_entryData->_iconPath); _loading = false; + + CheckIfTrayIsDisabled(); + QWidget::connect(&_checkTrayDisableTimer, SIGNAL(timeout()), this, + SLOT(CheckIfTrayIsDisabled())); + _checkTrayDisableTimer.start(1000); } void MacroActionSystrayEdit::TitleChanged() @@ -126,6 +141,19 @@ void MacroActionSystrayEdit::IconPathChanged(const QString &text) _entryData->_iconPath = text.toStdString(); } +void MacroActionSystrayEdit::CheckIfTrayIsDisabled() +{ + auto config = obs_frontend_get_global_config(); + if (!config) { + return; + } + + _trayDisableWarning->setVisible( + !config_get_bool(config, "BasicWindow", "SysTrayEnabled")); + adjustSize(); + updateGeometry(); +} + void MacroActionSystrayEdit::MessageChanged() { if (_loading || !_entryData) { diff --git a/plugins/base/macro-action-systray.hpp b/plugins/base/macro-action-systray.hpp index b9654e27..da2d5dd7 100644 --- a/plugins/base/macro-action-systray.hpp +++ b/plugins/base/macro-action-systray.hpp @@ -50,6 +50,7 @@ private slots: void MessageChanged(); void TitleChanged(); void IconPathChanged(const QString &text); + void CheckIfTrayIsDisabled(); protected: std::shared_ptr _entryData; @@ -58,6 +59,9 @@ private: VariableLineEdit *_message; VariableLineEdit *_title; FileSelection *_iconPath; + QLabel *_trayDisableWarning; + + QTimer _checkTrayDisableTimer; bool _loading = true; };