limit log rate in UI

This commit is contained in:
arm64v8a
2023-05-17 22:04:05 +09:00
parent c58f57cd71
commit b36aad61f8
2 changed files with 8 additions and 10 deletions

View File

@@ -36,7 +36,6 @@
#include <QLabel>
#include <QTextBlock>
#include <QScrollBar>
#include <QMutex>
#include <QScreen>
#include <QDesktopServices>
#include <QInputDialog>
@@ -48,6 +47,7 @@
#include <QElapsedTimer>
QElapsedTimer coreRestartTimer;
QAtomicInt logCounter;
void UI_InitMainWindow() {
mainwindow = new MainWindow;
@@ -150,6 +150,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
MW_show_log_ext_vt100 = [=](const QString &log) {
runOnUiThread([=] { show_log_impl(cleanVT100String(log)); });
};
//
auto logCounterTimer = new QTimer(this);
connect(logCounterTimer, &QTimer::timeout, this, [&] { logCounter.fetchAndStoreRelaxed(0); });
logCounterTimer->setInterval(1000);
logCounterTimer->start();
// table UI
ui->proxyListTable->callback_save_order = [=] {
@@ -672,10 +677,7 @@ void MainWindow::on_menu_exit_triggered() {
QDir::setCurrent(QApplication::applicationDirPath());
auto arguments = NekoRay::dataStore->argv;
if (arguments.length() > 0) {
arguments.removeFirst();
arguments.removeAll("-tray");
}
if (arguments.length() > 0) arguments.removeFirst();
auto isLauncher = qEnvironmentVariable("NKR_FROM_LAUNCHER") == "1";
if (isLauncher) arguments.prepend("--");
auto program = isLauncher ? "./launcher" : QApplication::applicationFilePath();
@@ -1491,6 +1493,7 @@ void MainWindow::show_log_impl(const QString &log) {
if (showThisLine) newLines << line;
}
if (newLines.isEmpty()) return;
if (logCounter.fetchAndAddRelaxed(newLines.count()) > NekoRay::dataStore->max_log_line) return;
FastAppendTextDocument(newLines.join("\n"), qvLogDocument);
// qvLogDocument->setPlainText(qvLogDocument->toPlainText() + log);