mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-22 01:44:49 -05:00
Add macro action to display system tray notifications
This commit is contained in:
parent
51b4ef326d
commit
f9afbcbc59
|
|
@ -226,6 +226,7 @@ set(advanced-scene-switcher_HEADERS
|
|||
src/headers/macro-action-scene-visibility.hpp
|
||||
src/headers/macro-action-source.hpp
|
||||
src/headers/macro-action-streaming.hpp
|
||||
src/headers/macro-action-systray.hpp
|
||||
src/headers/macro-action-timer.hpp
|
||||
src/headers/macro-action-transition.hpp
|
||||
src/headers/macro-action-virtual-cam.hpp
|
||||
|
|
@ -319,6 +320,7 @@ set(advanced-scene-switcher_SOURCES
|
|||
src/macro-action-scene-visibility.cpp
|
||||
src/macro-action-source.cpp
|
||||
src/macro-action-streaming.cpp
|
||||
src/macro-action-systray.cpp
|
||||
src/macro-action-timer.cpp
|
||||
src/macro-action-transition.cpp
|
||||
src/macro-action-virtual-cam.cpp
|
||||
|
|
|
|||
|
|
@ -355,6 +355,8 @@ AdvSceneSwitcher.action.timer.type.setTimeRemaining="Set time remaining of"
|
|||
AdvSceneSwitcher.action.timer.entry="{{timerAction}} timers on {{macros}} {{duration}}"
|
||||
AdvSceneSwitcher.action.random="Random"
|
||||
AdvSceneSwitcher.action.random.entry="Randomly run any of the following macros (paused macros are ignored)"
|
||||
AdvSceneSwitcher.action.systray="System tray notification"
|
||||
AdvSceneSwitcher.action.systray.entry="Show notification: {{message}}"
|
||||
|
||||
; Transition Tab
|
||||
AdvSceneSwitcher.transitionTab.title="Transition"
|
||||
|
|
|
|||
49
src/headers/macro-action-systray.hpp
Normal file
49
src/headers/macro-action-systray.hpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#pragma once
|
||||
#include "macro-action-edit.hpp"
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
class MacroActionSystray : public MacroAction {
|
||||
public:
|
||||
bool PerformAction();
|
||||
void LogAction();
|
||||
bool Save(obs_data_t *obj);
|
||||
bool Load(obs_data_t *obj);
|
||||
std::string GetId() { return id; };
|
||||
static std::shared_ptr<MacroAction> Create()
|
||||
{
|
||||
return std::make_shared<MacroActionSystray>();
|
||||
}
|
||||
|
||||
std::string _msg = "";
|
||||
|
||||
private:
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
|
||||
class MacroActionSystrayEdit : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroActionSystrayEdit(
|
||||
QWidget *parent,
|
||||
std::shared_ptr<MacroActionSystray> entryData = nullptr);
|
||||
static QWidget *Create(QWidget *parent,
|
||||
std::shared_ptr<MacroAction> action)
|
||||
{
|
||||
return new MacroActionSystrayEdit(
|
||||
parent,
|
||||
std::dynamic_pointer_cast<MacroActionSystray>(action));
|
||||
}
|
||||
|
||||
private slots:
|
||||
void MessageChanged();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<MacroActionSystray> _entryData;
|
||||
|
||||
private:
|
||||
QLineEdit *_msg;
|
||||
bool _loading = true;
|
||||
};
|
||||
70
src/macro-action-systray.cpp
Normal file
70
src/macro-action-systray.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#include "headers/macro-action-systray.hpp"
|
||||
#include "headers/advanced-scene-switcher.hpp"
|
||||
#include "headers/utility.hpp"
|
||||
|
||||
const std::string MacroActionSystray::id = "systray_notification";
|
||||
|
||||
bool MacroActionSystray::_registered = MacroActionFactory::Register(
|
||||
MacroActionSystray::id,
|
||||
{MacroActionSystray::Create, MacroActionSystrayEdit::Create,
|
||||
"AdvSceneSwitcher.action.systray"});
|
||||
|
||||
bool MacroActionSystray::PerformAction()
|
||||
{
|
||||
if (_msg.empty()) {
|
||||
return true;
|
||||
}
|
||||
DisplayTrayMessage(obs_module_text("AdvSceneSwitcher.pluginName"),
|
||||
QString::fromStdString(_msg));
|
||||
return true;
|
||||
}
|
||||
|
||||
void MacroActionSystray::LogAction()
|
||||
{
|
||||
vblog(LOG_INFO, "display systray message \"%s\"", _msg.c_str());
|
||||
}
|
||||
|
||||
bool MacroActionSystray::Save(obs_data_t *obj)
|
||||
{
|
||||
MacroAction::Save(obj);
|
||||
obs_data_set_string(obj, "message", _msg.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroActionSystray::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroAction::Load(obj);
|
||||
_msg = obs_data_get_string(obj, "message");
|
||||
return true;
|
||||
}
|
||||
|
||||
MacroActionSystrayEdit::MacroActionSystrayEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroActionSystray> entryData)
|
||||
: QWidget(parent)
|
||||
{
|
||||
_msg = new QLineEdit();
|
||||
QWidget::connect(_msg, SIGNAL(editingFinished()), this,
|
||||
SLOT(MessageChanged()));
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{message}}", _msg},
|
||||
};
|
||||
placeWidgets(obs_module_text("AdvSceneSwitcher.action.systray.entry"),
|
||||
mainLayout, widgetPlaceholders);
|
||||
setLayout(mainLayout);
|
||||
|
||||
_entryData = entryData;
|
||||
_msg->setText(QString::fromStdString(_entryData->_msg));
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
void MacroActionSystrayEdit::MessageChanged()
|
||||
{
|
||||
if (_loading || !_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
_entryData->_msg = _msg->text().toStdString();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user