feat: max log lines

This commit is contained in:
arm64v8a
2023-01-02 13:53:11 +09:00
parent 0e97c61293
commit 5e1d0cdce4
7 changed files with 168 additions and 133 deletions

View File

@@ -69,6 +69,7 @@ namespace NekoRay {
_add(new configItem("enable_js_hook", &enable_js_hook, itemType::integer));
_add(new configItem("log_ignore", &log_ignore, itemType::stringList));
_add(new configItem("start_minimal", &start_minimal, itemType::boolean));
_add(new configItem("max_log_line", &max_log_line, itemType::integer));
}
void DataStore::UpdateStartedId(int id) {

View File

@@ -76,6 +76,7 @@ namespace NekoRay {
QString system_proxy_format = "";
QStringList log_ignore = {};
bool start_minimal = false;
int max_log_line = 200;
// Subscription
QString user_agent = "Nekoray/1.0 (Prefer Clash Format)";

View File

@@ -213,6 +213,10 @@
<source>Please select a valid square image.</source>
<translation>لطفاً یک تصویر مربع معتبر انتخاب کنید.</translation>
</message>
<message>
<source>Max log lines</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DialogEditGroup</name>

View File

@@ -211,6 +211,10 @@
<source>Hide dashboard at startup</source>
<translation></translation>
</message>
<message>
<source>Max log lines</source>
<translation></translation>
</message>
</context>
<context>
<name>DialogEditGroup</name>

View File

@@ -101,6 +101,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
D_LOAD_BOOL(check_include_pre)
D_LOAD_BOOL(connection_statistics)
D_LOAD_BOOL(start_minimal)
D_LOAD_INT(max_log_line)
//
if (NekoRay::dataStore->traffic_loop_interval == 500) {
ui->rfsh_r->setCurrentIndex(0);
@@ -256,6 +257,11 @@ void DialogBasicSettings::accept() {
D_SAVE_BOOL(connection_statistics)
D_SAVE_BOOL(check_include_pre)
D_SAVE_BOOL(start_minimal)
D_SAVE_INT(max_log_line)
if (NekoRay::dataStore->max_log_line <= 0) {
NekoRay::dataStore->max_log_line = 200;
}
if (ui->rfsh_r->currentIndex() == 0) {
NekoRay::dataStore->traffic_loop_interval = 500;

View File

@@ -20,16 +20,6 @@
<string>Basic Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="7" column="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
@@ -250,93 +240,139 @@
<string>Style</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="4" column="0">
<layout class="QHBoxLayout" name="_4">
<item>
<widget class="QGroupBox" name="horizontalGroupBox2">
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QPushButton" name="set_custom_icon">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Set custom icon</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="horizontalGroupBox_5">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QCheckBox" name="start_minimal">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Hide dashboard at startup</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Theme</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="theme">
<layout class="QHBoxLayout" name="_3">
<item>
<widget class="QGroupBox" name="groupBox">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<property name="text">
<string>System</string>
</property>
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Theme</string>
</property>
</widget>
</item>
<item>
<property name="text">
<string notr="true">flatgray</string>
</property>
<widget class="QComboBox" name="theme">
<item>
<property name="text">
<string>System</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">flatgray</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">lightblue</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">blacksoft</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox2">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_15">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item>
<property name="text">
<string notr="true">lightblue</string>
</property>
<widget class="QComboBox" name="language">
<item>
<property name="text">
<string>System</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">English</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">简体中文</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">فارسی</string>
</property>
</item>
</widget>
</item>
<item>
<property name="text">
<string notr="true">blacksoft</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</layout>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox2">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_15">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Language</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="language">
<item>
<property name="text">
<string>System</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">English</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">简体中文</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">فارسی</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QGroupBox" name="traffic_statistics_box">
@@ -392,47 +428,21 @@
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_22">
<item>
<widget class="QGroupBox" name="horizontalGroupBox2">
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QPushButton" name="set_custom_icon">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Set custom icon</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="horizontalGroupBox_5">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QCheckBox" name="start_minimal">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Hide dashboard at startup</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
<item row="5" column="0">
<widget class="QGroupBox" name="groupBox_2">
<layout class="QHBoxLayout" name="horizontalLayout_23">
<item>
<widget class="QLabel" name="label_17">
<property name="text">
<string>Max log lines</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="max_log_line"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
@@ -492,7 +502,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<layout class="QHBoxLayout" name="horizontalLayout_22">
<item>
<widget class="QLabel" name="label_12">
<property name="text">
@@ -654,6 +664,16 @@
</widget>
</widget>
</item>
<item row="7" column="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>

View File

@@ -1295,11 +1295,10 @@ void MainWindow::show_log_impl(const QString &log) {
FastAppendTextDocument(newLines.join("\n"), qvLogDocument);
// qvLogDocument->setPlainText(qvLogDocument->toPlainText() + log);
// From https://gist.github.com/jemyzhang/7130092
auto maxLines = 200;
auto block = qvLogDocument->begin();
while (block.isValid()) {
if (qvLogDocument->blockCount() > maxLines) {
if (qvLogDocument->blockCount() > NekoRay::dataStore->max_log_line) {
QTextCursor cursor(block);
block = block.next();
cursor.select(QTextCursor::BlockUnderCursor);