mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
limit log rate in UI
This commit is contained in:
@@ -36,7 +36,6 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QMutex>
|
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
@@ -48,6 +47,7 @@
|
|||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
QElapsedTimer coreRestartTimer;
|
QElapsedTimer coreRestartTimer;
|
||||||
|
QAtomicInt logCounter;
|
||||||
|
|
||||||
void UI_InitMainWindow() {
|
void UI_InitMainWindow() {
|
||||||
mainwindow = new MainWindow;
|
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) {
|
MW_show_log_ext_vt100 = [=](const QString &log) {
|
||||||
runOnUiThread([=] { show_log_impl(cleanVT100String(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
|
// table UI
|
||||||
ui->proxyListTable->callback_save_order = [=] {
|
ui->proxyListTable->callback_save_order = [=] {
|
||||||
@@ -672,10 +677,7 @@ void MainWindow::on_menu_exit_triggered() {
|
|||||||
QDir::setCurrent(QApplication::applicationDirPath());
|
QDir::setCurrent(QApplication::applicationDirPath());
|
||||||
|
|
||||||
auto arguments = NekoRay::dataStore->argv;
|
auto arguments = NekoRay::dataStore->argv;
|
||||||
if (arguments.length() > 0) {
|
if (arguments.length() > 0) arguments.removeFirst();
|
||||||
arguments.removeFirst();
|
|
||||||
arguments.removeAll("-tray");
|
|
||||||
}
|
|
||||||
auto isLauncher = qEnvironmentVariable("NKR_FROM_LAUNCHER") == "1";
|
auto isLauncher = qEnvironmentVariable("NKR_FROM_LAUNCHER") == "1";
|
||||||
if (isLauncher) arguments.prepend("--");
|
if (isLauncher) arguments.prepend("--");
|
||||||
auto program = isLauncher ? "./launcher" : QApplication::applicationFilePath();
|
auto program = isLauncher ? "./launcher" : QApplication::applicationFilePath();
|
||||||
@@ -1491,6 +1493,7 @@ void MainWindow::show_log_impl(const QString &log) {
|
|||||||
if (showThisLine) newLines << line;
|
if (showThisLine) newLines << line;
|
||||||
}
|
}
|
||||||
if (newLines.isEmpty()) return;
|
if (newLines.isEmpty()) return;
|
||||||
|
if (logCounter.fetchAndAddRelaxed(newLines.count()) > NekoRay::dataStore->max_log_line) return;
|
||||||
|
|
||||||
FastAppendTextDocument(newLines.join("\n"), qvLogDocument);
|
FastAppendTextDocument(newLines.join("\n"), qvLogDocument);
|
||||||
// qvLogDocument->setPlainText(qvLogDocument->toPlainText() + log);
|
// qvLogDocument->setPlainText(qvLogDocument->toPlainText() + log);
|
||||||
|
|||||||
@@ -26,11 +26,6 @@ void MainWindow::setup_grpc() {
|
|||||||
MW_show_log("[Error] gRPC: " + errStr);
|
MW_show_log("[Error] gRPC: " + errStr);
|
||||||
},
|
},
|
||||||
"127.0.0.1:" + Int2String(NekoRay::dataStore->core_port), NekoRay::dataStore->core_token);
|
"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
|
// Looper
|
||||||
runOnNewThread([=] { NekoRay::traffic::trafficLooper->Loop(); });
|
runOnNewThread([=] { NekoRay::traffic::trafficLooper->Loop(); });
|
||||||
|
|||||||
Reference in New Issue
Block a user