diff --git a/db/Database.cpp b/db/Database.cpp index 052f323fe..0446dd448 100644 --- a/db/Database.cpp +++ b/db/Database.cpp @@ -3,6 +3,7 @@ #include "fmt/includes.h" #include +#include namespace NekoRay { @@ -99,6 +100,7 @@ namespace NekoRay { _add(new configItem("type", &type, itemType::string)); _add(new configItem("id", &id, itemType::integer)); _add(new configItem("gid", &gid, itemType::integer)); + _add(new configItem("yc", &latency, itemType::integer)); // 可以不关联 bean,只加载 ProxyEntity 的信息 if (bean != nullptr) { @@ -119,6 +121,22 @@ namespace NekoRay { } } + QColor ProxyEntity::DisplayLatencyColor() const { + if (latency < 0) { + return Qt::red; + } else if (latency > 0) { + if (latency < 100) { + return Qt::darkGreen; + } else if (latency < 200) { + return Qt::darkYellow; + } else { + return Qt::darkRed; + } + } else { + return {}; + } + } + // Profile int ProfileManager::NewProfileID() const { diff --git a/db/ProxyEntity.hpp b/db/ProxyEntity.hpp index ecb4c6305..b0f026a4a 100644 --- a/db/ProxyEntity.hpp +++ b/db/ProxyEntity.hpp @@ -27,18 +27,20 @@ namespace NekoRay { int id = -1; int gid = 0; + int latency = 0; QSharedPointer bean; QSharedPointer traffic_data = QSharedPointer( new traffic::TrafficData("")); // Cache - int latency = 0; QString full_test_report; ProxyEntity(fmt::AbstractBean *bean, QString _type); [[nodiscard]] QString DisplayLatency() const; + [[nodiscard]] QColor DisplayLatencyColor() const; + [[nodiscard]] fmt::ChainBean *ChainBean() const { return (fmt::ChainBean *) bean.get(); }; diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 09ab2da0a..327fa4dfa 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -752,8 +752,13 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction // C4: Test Result f = f0->clone(); - f->setText(profile->DisplayLatency()); - if (!profile->full_test_report.isEmpty()) f->setText(profile->full_test_report); + if (profile->full_test_report.isEmpty()) { + auto color = profile->DisplayLatencyColor(); + if (color.isValid()) f->setForeground(color); + f->setText(profile->DisplayLatency()); + } else { + f->setText(profile->full_test_report); + } ui->proxyListTable->setItem(row, 4, f); // C5: Traffic @@ -1072,6 +1077,7 @@ void MainWindow::on_menu_clear_test_result_triggered() { if (NekoRay::dataStore->current_group != profile->gid) continue; profile->latency = 0; profile->full_test_report = ""; + profile->Save(); } refresh_proxy_list(); } diff --git a/ui/mainwindow_grpc.cpp b/ui/mainwindow_grpc.cpp index 345d72c3e..c21c902a6 100644 --- a/ui/mainwindow_grpc.cpp +++ b/ui/mainwindow_grpc.cpp @@ -148,6 +148,7 @@ void MainWindow::speedtest_current_group(int mode) { profile->latency = result.ms(); if (profile->latency == 0) profile->latency = -1; // sn profile->full_test_report = result.full_report().c_str(); + profile->Save(); runOnUiThread([=] { if (!result.error().empty()) {