mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
UI: System tray notification on new connections
This commit is contained in:
parent
007604cc21
commit
f2028c506a
21
Utils.cpp
21
Utils.cpp
@ -384,3 +384,24 @@ const char* Utils::OBSVersionString() {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QSystemTrayIcon* Utils::GetTrayIcon()
|
||||
{
|
||||
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||
|
||||
QSystemTrayIcon* trayIcon = main->findChildren<QSystemTrayIcon*>().first();
|
||||
blog(LOG_INFO, "tray icon : %s", trayIcon);
|
||||
|
||||
return trayIcon;
|
||||
}
|
||||
|
||||
void Utils::SysTrayNotify(QString &text, QSystemTrayIcon::MessageIcon icon, QString title)
|
||||
{
|
||||
if (!QSystemTrayIcon::supportsMessages())
|
||||
return;
|
||||
|
||||
QSystemTrayIcon* trayIcon = GetTrayIcon();
|
||||
|
||||
if (trayIcon)
|
||||
trayIcon->showMessage(title, text, icon);
|
||||
}
|
4
Utils.h
4
Utils.h
@ -23,6 +23,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#include <QPushButton>
|
||||
#include <QLayout>
|
||||
#include <QListWidget>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <stdio.h>
|
||||
#include <obs-module.h>
|
||||
|
||||
@ -62,6 +63,9 @@ class Utils
|
||||
static void TransitionToProgram();
|
||||
|
||||
static const char* OBSVersionString();
|
||||
|
||||
static QSystemTrayIcon* GetTrayIcon();
|
||||
static void SysTrayNotify(QString &text, QSystemTrayIcon::MessageIcon n, QString title = QString("obs-websocket"));
|
||||
};
|
||||
|
||||
#endif // UTILS_H
|
||||
|
@ -234,8 +234,6 @@ void WSEvents::connectTransitionSignals(obs_source_t* transition)
|
||||
|
||||
void WSEvents::connectSceneSignals(obs_source_t* scene)
|
||||
{
|
||||
// TODO : connect to all scenes, not just the current one.
|
||||
|
||||
if (scene_handler)
|
||||
{
|
||||
signal_handler_disconnect(scene_handler, "reorder", OnSceneReordered, this);
|
||||
@ -244,6 +242,7 @@ void WSEvents::connectSceneSignals(obs_source_t* scene)
|
||||
signal_handler_disconnect(scene_handler, "item_visible", OnSceneItemVisibilityChanged, this);
|
||||
}
|
||||
|
||||
// TODO : connect to all scenes, not just the current one.
|
||||
scene_handler = obs_source_get_signal_handler(scene);
|
||||
signal_handler_connect(scene_handler, "reorder", OnSceneReordered, this);
|
||||
signal_handler_connect(scene_handler, "item_add", OnSceneItemAdd, this);
|
||||
|
@ -63,7 +63,7 @@ class WSEvents : public QObject
|
||||
uint64_t _lastBytesSentTime;
|
||||
|
||||
void broadcastUpdate(const char *updateType, obs_data_t *additionalFields);
|
||||
|
||||
|
||||
void OnSceneChange();
|
||||
void OnSceneListChange();
|
||||
void OnSceneCollectionChange();
|
||||
|
@ -24,6 +24,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#include "WSServer.h"
|
||||
#include "obs-websocket.h"
|
||||
#include "Config.h"
|
||||
#include "Utils.h"
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
@ -114,6 +115,9 @@ void WSServer::onNewConnection()
|
||||
|
||||
QByteArray client_ip = pSocket->peerAddress().toString().toUtf8();
|
||||
blog(LOG_INFO, "new client connection from %s:%d", client_ip.constData(), pSocket->peerPort());
|
||||
|
||||
QString msg = QString("Client IP: ") + pSocket->peerAddress().toString();
|
||||
Utils::SysTrayNotify(msg, QSystemTrayIcon::Information, QString("New WebSocket connection"));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user