mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Utils: Queue notifications in the UI thread
Soooooooooo apparently doing notifications natively shouldn't even work. This is probably what was crashing OBS in 4.x. Fixed now I guess...
This commit is contained in:
parent
aaadf4d2ff
commit
17cbde0e48
2
docs/partials/enumsHeader.md
Normal file
2
docs/partials/enumsHeader.md
Normal file
@ -0,0 +1,2 @@
|
||||
# Enums
|
||||
These are enumeration declarations, which are referenced throughout obs-websocket's protocol.
|
23
src/requesthandler/RequestHandler_Sources.cpp
Normal file
23
src/requesthandler/RequestHandler_Sources.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "RequestHandler.h"
|
||||
|
||||
#include "../plugin-macros.generated.h"
|
||||
|
||||
RequestResult RequestHandler::GetSourceActive(const Request& request)
|
||||
{
|
||||
RequestStatus::RequestStatus statusCode;
|
||||
std::string comment;
|
||||
if (!request.ValidateString("sourceName", statusCode, comment)) {
|
||||
return RequestResult::Error(statusCode, comment);
|
||||
}
|
||||
|
||||
std::string sourceName = request.RequestData["sourceName"];
|
||||
|
||||
OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str());
|
||||
if (!source)
|
||||
return RequestResult::Error(RequestStatus::SourceNotFound);
|
||||
|
||||
json responseData;
|
||||
responseData["videoActive"] = obs_source_active(source);
|
||||
responseData["videoShowing"] = obs_source_showing(source);
|
||||
return RequestResult::Success(responseData);
|
||||
}
|
@ -78,12 +78,25 @@ bool Utils::Platform::GetCommandLineFlagSet(QString arg)
|
||||
return parser.isSet(cmdlineOption);
|
||||
}
|
||||
|
||||
struct SystemTrayNotification {
|
||||
QSystemTrayIcon::MessageIcon icon;
|
||||
QString title;
|
||||
QString body;
|
||||
};
|
||||
|
||||
void Utils::Platform::SendTrayNotification(QSystemTrayIcon::MessageIcon icon, QString title, QString body)
|
||||
{
|
||||
if (!QSystemTrayIcon::isSystemTrayAvailable() || !QSystemTrayIcon::supportsMessages())
|
||||
return;
|
||||
|
||||
void *systemTrayPtr = obs_frontend_get_system_tray();
|
||||
auto systemTray = reinterpret_cast<QSystemTrayIcon*>(systemTrayPtr);
|
||||
systemTray->showMessage(title, body, icon);
|
||||
SystemTrayNotification *notification = new SystemTrayNotification{icon, title, body};
|
||||
|
||||
obs_queue_task(OBS_TASK_UI, [](void* param) {
|
||||
void *systemTrayPtr = obs_frontend_get_system_tray();
|
||||
auto systemTray = reinterpret_cast<QSystemTrayIcon*>(systemTrayPtr);
|
||||
|
||||
auto notification = reinterpret_cast<SystemTrayNotification*>(param);
|
||||
systemTray->showMessage(notification->title, notification->body, notification->icon);
|
||||
delete notification;
|
||||
}, (void*)notification, false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user