Skip to content

Commit

Permalink
remember latency
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Sep 11, 2022
1 parent a7fe8de commit fd13c92
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
18 changes: 18 additions & 0 deletions db/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "fmt/includes.h"

#include <QFile>
#include <QColor>

namespace NekoRay {

Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion db/ProxyEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
10 changes: 8 additions & 2 deletions ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions ui/mainwindow_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit fd13c92

Please sign in to comment.