frontend: Use signal to update log viewer

Instead of calling the log viewer directly, use a signal instead.
This commit is contained in:
cg2121
2025-05-24 08:27:46 -05:00
committed by Ryan Foster
parent 31574b416f
commit 4b403d2a3e
4 changed files with 13 additions and 12 deletions

View File

@@ -74,8 +74,6 @@ extern bool opt_disable_missing_files_check;
extern string opt_starting_collection;
extern string opt_starting_profile;
extern QPointer<OBSLogViewer> obsLogViewer;
#ifndef _WIN32
int OBSApp::sigintFd[2];
#endif
@@ -1757,3 +1755,8 @@ void OBSApp::applicationShutdown() noexcept
libobs_initialized = false;
}
}
void OBSApp::addLogLine(int logLevel, const QString &message)
{
emit logLineAdded(logLevel, message);
}

View File

@@ -119,6 +119,7 @@ private slots:
#endif
private slots:
void addLogLine(int logLevel, const QString &message);
void themeFileChanged(const QString &);
void applicationShutdown() noexcept;
@@ -212,6 +213,7 @@ public slots:
void ProcessSigInt();
signals:
void logLineAdded(int logLevel, const QString &message);
void StyleChanged();
void logUploadFinished(OBS::LogFileType, const QString &fileUrl);

View File

@@ -29,6 +29,8 @@ OBSLogViewer::OBSLogViewer(QWidget *parent) : QDialog(parent), ui(new Ui::OBSLog
}
InitLog();
connect(App(), &OBSApp::logLineAdded, this, &OBSLogViewer::AddLine);
}
OBSLogViewer::~OBSLogViewer()
@@ -41,8 +43,6 @@ void OBSLogViewer::on_showStartup_clicked(bool checked)
config_set_bool(App()->GetUserConfig(), "LogViewer", "ShowLogStartup", checked);
}
extern QPointer<OBSLogViewer> obsLogViewer;
void OBSLogViewer::InitLog()
{
char logDir[512];
@@ -74,8 +74,6 @@ void OBSLogViewer::InitLog()
}
QScrollBar *scroll = ui->textArea->verticalScrollBar();
scroll->setValue(scroll->maximum());
obsLogViewer = this;
}
void OBSLogViewer::AddLine(int type, const QString &str)

View File

@@ -16,7 +16,6 @@
******************************************************************************/
#include <OBSApp.hpp>
#include <dialogs/OBSLogViewer.hpp>
#ifdef __APPLE__
#include <dialogs/OBSPermissions.hpp>
#endif
@@ -33,7 +32,9 @@
#include <util/windows/win-version.h>
#endif
#include <QFontDatabase>
#include <QProcess>
#include <QPushButton>
#include <curl/curl.h>
#include <fstream>
@@ -80,8 +81,6 @@ bool restart = false;
bool restart_safe = false;
static QStringList arguments;
QPointer<OBSLogViewer> obsLogViewer;
string CurrentTimeString()
{
using namespace std::chrono;
@@ -115,9 +114,8 @@ static void LogString(fstream &logFile, const char *timeString, char *str, int l
logFile << msg << endl;
logfile_mutex.unlock();
if (!!obsLogViewer)
QMetaObject::invokeMethod(obsLogViewer.data(), "AddLine", Qt::QueuedConnection, Q_ARG(int, log_level),
Q_ARG(QString, QString(msg.c_str())));
QMetaObject::invokeMethod(App(), "addLogLine", Qt::QueuedConnection, Q_ARG(int, log_level),
Q_ARG(QString, QString(msg.c_str())));
}
static inline void LogStringChunk(fstream &logFile, char *str, int log_level)