Base: General code cleanup

This commit is contained in:
tt2468 2021-06-22 15:51:52 -07:00
parent 33137496a7
commit 0a02015f7d
5 changed files with 15 additions and 27 deletions

View File

@ -66,6 +66,7 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
if (!incomingMessage.contains("messageType")) {
if (incomingMessage.contains("request-type")) {
blog(LOG_WARNING, "Client %s appears to be running a pre-5.0.0 protocol.", session->RemoteAddress().c_str())
ret.closeCode = WebSocketServer::WebSocketCloseCode::UnsupportedProtocolVersion;
ret.closeReason = "You appear to be attempting to connect with the pre-5.0.0 plugin protocol. Check to make sure your client is updated.";
return ret;
@ -191,10 +192,8 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
if (!Utils::Crypto::CheckAuthenticationString(session->Secret(), session->Challenge(), incomingMessage["authentication"])) {
auto conf = GetConfig();
if (conf && conf->AlertsEnabled) {
obs_frontend_push_ui_translation(obs_module_get_string);
QString title = QObject::tr("OBSWebSocket.TrayNotification.AuthenticationFailed.Title");
QString body = QObject::tr("OBSWebSocket.TrayNotification.AuthenticationFailed.Body").arg(QString::fromStdString(session->RemoteAddress()));
obs_frontend_pop_ui_translation();
QString title = obs_module_text("OBSWebSocket.TrayNotification.AuthenticationFailed.Title");
QString body = QString(obs_module_text("OBSWebSocket.TrayNotification.AuthenticationFailed.Body")).arg(QString::fromStdString(session->RemoteAddress()));
Utils::Platform::SendTrayNotification(QSystemTrayIcon::Warning, title, body);
}
ret.closeCode = WebSocketServer::WebSocketCloseCode::AuthenticationFailed;
@ -225,10 +224,8 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
auto conf = GetConfig();
if (conf && conf->AlertsEnabled) {
obs_frontend_push_ui_translation(obs_module_get_string);
QString title = QObject::tr("OBSWebSocket.TrayNotification.Identified.Title");
QString body = QObject::tr("OBSWebSocket.TrayNotification.Identified.Body").arg(QString::fromStdString(session->RemoteAddress()));
obs_frontend_pop_ui_translation();
QString title = obs_module_text("OBSWebSocket.TrayNotification.Identified.Title");
QString body = QString(obs_module_text("OBSWebSocket.TrayNotification.Identified.Body")).arg(QString::fromStdString(session->RemoteAddress()));
Utils::Platform::SendTrayNotification(QSystemTrayIcon::Information, title, body);
}

View File

@ -2,7 +2,6 @@
#include <thread>
#include <QtConcurrent>
#include <QDateTime>
#include <obs-module.h>
#include <obs-frontend-api.h>
@ -353,10 +352,8 @@ void WebSocketServer::onClose(websocketpp::connection_hdl hdl)
// If previously identified, not going away, and notifications enabled, send a tray notification
if (isIdentified && (conn->get_local_close_code() != websocketpp::close::status::going_away) && conf->AlertsEnabled) {
obs_frontend_push_ui_translation(obs_module_get_string);
QString title = QObject::tr("OBSWebSocket.TrayNotification.Disconnected.Title");
QString body = QObject::tr("OBSWebSocket.TrayNotification.Disconnected.Body").arg(QString::fromStdString(remoteAddress));
obs_frontend_pop_ui_translation();
QString title = obs_module_text("OBSWebSocket.TrayNotification.Disconnected.Title");
QString body = QString(obs_module_text("OBSWebSocket.TrayNotification.Disconnected.Body")).arg(QString::fromStdString(remoteAddress));
Utils::Platform::SendTrayNotification(QSystemTrayIcon::Information, title, body);
}
}

View File

@ -1,7 +1,6 @@
#include <obs-module.h>
#include <obs-frontend-api.h>
#include <QClipboard>
#include <QPainter>
#include <obs-module.h>
#include "../../deps/qr/cpp/QrCode.hpp"
#include "ConnectInfo.h"
@ -50,9 +49,7 @@ void ConnectInfo::showEvent(QShowEvent *event)
serverPassword = conf->ServerPassword;
} else {
ui->copyServerPasswordButton->setEnabled(false);
obs_frontend_push_ui_translation(obs_module_get_string);
serverPassword = QObject::tr("OBSWebSocket.ConnectInfo.ServerPasswordPlaceholderText");
obs_frontend_pop_ui_translation();
serverPassword = obs_module_text("OBSWebSocket.ConnectInfo.ServerPasswordPlaceholderText");
}
ui->serverPasswordLineEdit->setText(serverPassword);

View File

@ -1,8 +1,8 @@
#include <obs-module.h>
#include <obs-frontend-api.h>
#include <QtWidgets/QMessageBox>
#include <QDateTime>
#include <QTime>
#include <obs-module.h>
#include <obs.hpp>
#include "SettingsDialog.h"
#include "../obs-websocket.h"
@ -190,9 +190,7 @@ void SettingsDialog::FillSessionTable()
QPixmap crossIconPixmap = crossIcon.pixmap(QSize(25, 25));
// Todo: Make a util for translations so that we don't need to import a bunch of obs libraries in order to use them.
obs_frontend_push_ui_translation(obs_module_get_string);
QString kickButtonText = QObject::tr("OBSWebSocket.SessionTable.KickButtonText");
obs_frontend_pop_ui_translation();
QString kickButtonText = obs_module_text("OBSWebSocket.SessionTable.KickButtonText");
ui->websocketSessionTable->setRowCount(rowCount);
size_t i = 0;

View File

@ -1,11 +1,10 @@
#include <obs-module.h>
#include <obs-frontend-api.h>
#include <obs-data.h>
#include <QtCore/QTimer>
#include <QtWidgets/QAction>
#include <QtWidgets/QMainWindow>
#include <QTime>
#include <obs-module.h>
#include <obs-data.h>
#include <obs-frontend-api.h>
#include "obs-websocket.h"
#include "Config.h"