mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
fix latency sort
This commit is contained in:
@@ -55,6 +55,7 @@ namespace NekoRay::fmt {
|
||||
|
||||
QJsonObject outbound;
|
||||
outbound["type"] = socks_http_type == type_HTTP ? "http" : "socks";
|
||||
if (socks_http_type == type_Socks4) outbound["version"] = "4";
|
||||
outbound["server"] = serverAddress;
|
||||
outbound["server_port"] = serverPort;
|
||||
|
||||
|
||||
@@ -850,12 +850,16 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
|
||||
ms_a = NekoRay::profileManager->GetProfile(a)->full_test_report;
|
||||
ms_b = NekoRay::profileManager->GetProfile(b)->full_test_report;
|
||||
}
|
||||
auto get_latency_for_sort = [](int id) {
|
||||
auto i = NekoRay::profileManager->GetProfile(id)->latency;
|
||||
if (i < 0) i = 99999;
|
||||
return i;
|
||||
};
|
||||
if (groupSortAction.descending) {
|
||||
if (groupSortAction.method == NekoRay::GroupSortMethod::ByLatency) {
|
||||
auto int_a = NekoRay::profileManager->GetProfile(a)->latency;
|
||||
auto int_b = NekoRay::profileManager->GetProfile(b)->latency;
|
||||
if (int_a > 0 && int_b > 0) {
|
||||
return int_a > int_b;
|
||||
if (ms_a.isEmpty() && ms_b.isEmpty()) {
|
||||
// compare latency if full_test_report is empty
|
||||
return get_latency_for_sort(a) > get_latency_for_sort(b);
|
||||
}
|
||||
}
|
||||
return ms_a > ms_b;
|
||||
@@ -863,8 +867,9 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
|
||||
if (groupSortAction.method == NekoRay::GroupSortMethod::ByLatency) {
|
||||
auto int_a = NekoRay::profileManager->GetProfile(a)->latency;
|
||||
auto int_b = NekoRay::profileManager->GetProfile(b)->latency;
|
||||
if (int_a > 0 && int_b > 0) {
|
||||
return int_a < int_b;
|
||||
if (ms_a.isEmpty() && ms_b.isEmpty()) {
|
||||
// compare latency if full_test_report is empty
|
||||
return get_latency_for_sort(a) < get_latency_for_sort(b);
|
||||
}
|
||||
}
|
||||
return ms_a < ms_b;
|
||||
|
||||
@@ -126,9 +126,13 @@ void MainWindow::speedtest_current_group(int mode) {
|
||||
}
|
||||
if (!rpcOK) return;
|
||||
|
||||
if (result.error().empty()) {
|
||||
profile->latency = result.ms();
|
||||
if (profile->latency == 0) profile->latency = -1; // sn
|
||||
profile->full_test_report = result.full_report().c_str();
|
||||
if (profile->latency == 0) profile->latency = 1; // nekoray use 0 to represents not tested
|
||||
} else {
|
||||
profile->latency = -1;
|
||||
}
|
||||
profile->full_test_report = result.full_report().c_str(); // higher priority
|
||||
profile->Save();
|
||||
|
||||
if (!result.error().empty()) {
|
||||
|
||||
Reference in New Issue
Block a user