mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
remember latency
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "fmt/includes.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QColor>
|
||||
|
||||
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 {
|
||||
|
||||
@@ -27,18 +27,20 @@ namespace NekoRay {
|
||||
|
||||
int id = -1;
|
||||
int gid = 0;
|
||||
int latency = 0;
|
||||
QSharedPointer<fmt::AbstractBean> bean;
|
||||
QSharedPointer<traffic::TrafficData> traffic_data = QSharedPointer<traffic::TrafficData>(
|
||||
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();
|
||||
};
|
||||
|
||||
@@ -752,8 +752,13 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
|
||||
|
||||
// C4: Test Result
|
||||
f = f0->clone();
|
||||
if (profile->full_test_report.isEmpty()) {
|
||||
auto color = profile->DisplayLatencyColor();
|
||||
if (color.isValid()) f->setForeground(color);
|
||||
f->setText(profile->DisplayLatency());
|
||||
if (!profile->full_test_report.isEmpty()) f->setText(profile->full_test_report);
|
||||
} 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();
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user