From f1c12e05b3ea9d6ce982dfe89a146fe484c2b9b8 Mon Sep 17 00:00:00 2001 From: Nova Date: Thu, 16 Jan 2025 01:58:45 +0330 Subject: [PATCH] add process in connection list --- core/cmd/nekobox_core/internal/main.go | 18 ------------ include/global/NekoGui_Utils.hpp | 8 ++++- .../stats/connections/connectionLister.hpp | 2 +- include/ui/mainwindow.ui | 6 ++-- src/configs/ConfigBuilder.cpp | 4 +++ .../connectionLister/connectionLister.cpp | 6 ++-- src/ui/mainwindow.cpp | 29 +++++++++---------- 7 files changed, 32 insertions(+), 41 deletions(-) delete mode 100644 core/cmd/nekobox_core/internal/main.go diff --git a/core/cmd/nekobox_core/internal/main.go b/core/cmd/nekobox_core/internal/main.go deleted file mode 100644 index 7388b13..0000000 --- a/core/cmd/nekobox_core/internal/main.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "fmt" - _ "unsafe" - - "nekobox_core/internal/boxbox" - "nekobox_core/internal/boxmain" - _ "nekobox_core/internal/distro/all" -) - -func main() { - fmt.Println("sing-box:", boxbox.Version) - fmt.Println() - - // sing-box - boxmain.Main() -} diff --git a/include/global/NekoGui_Utils.hpp b/include/global/NekoGui_Utils.hpp index 7324b05..78c7e82 100644 --- a/include/global/NekoGui_Utils.hpp +++ b/include/global/NekoGui_Utils.hpp @@ -130,7 +130,13 @@ inline QString WrapIPV6Host(QString &str) { inline QString DisplayAddress(QString serverAddress, int serverPort) { if (serverAddress.isEmpty() && serverPort == 0) return {}; return WrapIPV6Host(serverAddress) + ":" + Int2String(serverPort); -}; +} + +inline QString DisplayDest(const QString& dest, QString domain) +{ + if (domain.isEmpty() || dest.split(":").first() == domain) return domain; + return dest + " (" + domain + ")"; +} // Format & Misc diff --git a/include/stats/connections/connectionLister.hpp b/include/stats/connections/connectionLister.hpp index b5f9892..7a63791 100644 --- a/include/stats/connections/connectionLister.hpp +++ b/include/stats/connections/connectionLister.hpp @@ -11,7 +11,7 @@ namespace NekoGui_traffic Default, ByDownload, ByUpload, - ByDomain + ByProcess }; class ConnectionMetadata diff --git a/include/ui/mainwindow.ui b/include/ui/mainwindow.ui index 73d66ae..5335f05 100644 --- a/include/ui/mainwindow.ui +++ b/include/ui/mainwindow.ui @@ -343,7 +343,7 @@ - Destination + Destination (Domain) Click To Disable Sorting @@ -351,10 +351,10 @@ - Domain + Process - Click To Sort By Domain + Click To Sort By Process diff --git a/src/configs/ConfigBuilder.cpp b/src/configs/ConfigBuilder.cpp index cc7fcd1..6ae1a7e 100644 --- a/src/configs/ConfigBuilder.cpp +++ b/src/configs/ConfigBuilder.cpp @@ -473,6 +473,10 @@ namespace NekoGui { if (dataStore->spmode_vpn) { routeObj["auto_detect_interface"] = true; } + if (dataStore->enable_stats && !status->forTest) + { + routeObj["find_process"] = true; + } if (!status->forTest) routeObj["final"] = dataStore->routing->def_outbound; auto routeChain = NekoGui::profileManager->GetRouteChain(NekoGui::dataStore->routing->current_route_id); diff --git a/src/stats/connectionLister/connectionLister.cpp b/src/stats/connectionLister/connectionLister.cpp index 53b7ff3..98bc663 100644 --- a/src/stats/connectionLister/connectionLister.cpp +++ b/src/stats/connectionLister/connectionLister.cpp @@ -107,12 +107,12 @@ namespace NekoGui_traffic return asc ? a.upload < b.upload : a.upload > b.upload; }); } - if (sort == ByDomain) + if (sort == ByProcess) { std::sort(sorted.begin(), sorted.end(), [=](const ConnectionMetadata& a, const ConnectionMetadata& b) { - if (a.domain == b.domain) return asc ? a.id > b.id : a.id < b.id; - return asc ? a.domain > b.domain : a.domain < b.domain; + if (a.process == b.process) return asc ? a.id > b.id : a.id < b.id; + return asc ? a.process > b.process : a.process < b.process; }); } runOnUiThread([=] { diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index b9de378..3954914 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -171,7 +171,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi } if (index == 1) { - NekoGui_traffic::connection_lister->setSort(NekoGui_traffic::ByDomain); + NekoGui_traffic::connection_lister->setSort(NekoGui_traffic::ByProcess); NekoGui_traffic::connection_lister->ForceUpdate(); } if (index == 4) @@ -680,8 +680,7 @@ void MainWindow::on_commitDataRequest() { } void MainWindow::on_menu_exit_triggered() { - std::chrono::duration elapsed_milliseconds = std::chrono::steady_clock::now() - trayMenuTime; - if (elapsed_milliseconds.count() < 150) + if (std::chrono::duration elapsed_milliseconds = std::chrono::steady_clock::now() - trayMenuTime; elapsed_milliseconds.count() < 150) { return; } @@ -868,11 +867,11 @@ void MainWindow::UpdateConnectionList(const QMapconnections->item(row, 0)->setText(conn.dest); + // C0: Dest (Domain) + ui->connections->item(row, 0)->setText(DisplayDest(conn.dest, conn.domain)); - // C1: Domain - ui->connections->item(row, 1)->setText(conn.domain); + // C1: Process + ui->connections->item(row, 1)->setText(conn.process); // C2: Network ui->connections->item(row, 2)->setText(conn.network); @@ -893,14 +892,14 @@ void MainWindow::UpdateConnectionList(const QMap(); f0->setData(NekoGui_traffic::IDKEY, conn.id); - // C0: Dest + // C0: Dest (Domain) auto f = f0->clone(); - f->setText(conn.dest); + f->setText(DisplayDest(conn.dest, conn.domain)); ui->connections->setItem(row, 0, f); - // C1: Domain + // C1: Process f = f0->clone(); - f->setText(conn.domain); + f->setText(conn.process); ui->connections->setItem(row, 1, f); // C2: Network @@ -939,14 +938,14 @@ void MainWindow::UpdateConnectionListWithRecreate(const QList(); f0->setData(NekoGui_traffic::IDKEY, conn.id); - // C0: Dest + // C0: Dest (Domain) auto f = f0->clone(); - f->setText(conn.dest); + f->setText(DisplayDest(conn.dest, conn.domain)); ui->connections->setItem(row, 0, f); - // C1: Domain + // C1: Process f = f0->clone(); - f->setText(conn.domain); + f->setText(conn.process); ui->connections->setItem(row, 1, f); // C2: Network