From b36aad61f8cf2429ccce63ac158fdf431949e2e4 Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Wed, 17 May 2023 22:04:05 +0900 Subject: [PATCH] limit log rate in UI --- ui/mainwindow.cpp | 13 ++++++++----- ui/mainwindow_grpc.cpp | 5 ----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 97018f1..5151b71 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -48,6 +47,7 @@ #include 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); diff --git a/ui/mainwindow_grpc.cpp b/ui/mainwindow_grpc.cpp index 6a4a925..a02cd3b 100644 --- a/ui/mainwindow_grpc.cpp +++ b/ui/mainwindow_grpc.cpp @@ -26,11 +26,6 @@ void MainWindow::setup_grpc() { MW_show_log("[Error] gRPC: " + errStr); }, "127.0.0.1:" + Int2String(NekoRay::dataStore->core_port), NekoRay::dataStore->core_token); - auto t = new QTimer(); - connect(t, &QTimer::timeout, this, [=]() { - refresh_status(); - }); - t->start(2000); // Looper runOnNewThread([=] { NekoRay::traffic::trafficLooper->Loop(); });