fix route select issue &&

add route export
This commit is contained in:
Nova 2025-01-20 03:40:57 +03:30
parent 0ba7ada673
commit 6a5b5dc0bd
4 changed files with 47 additions and 10 deletions

View File

@ -31,7 +31,9 @@ private:
QList<std::shared_ptr<NekoGui::RoutingChain>> chainList; QList<std::shared_ptr<NekoGui::RoutingChain>> chainList;
int currentRouteProfileID = -1; std::shared_ptr<NekoGui::RoutingChain> currentRoute;
int tooltipID = 0;
void set_dns_hijack_enability(bool enable) const; void set_dns_hijack_enability(bool enable) const;
@ -47,6 +49,8 @@ public slots:
void on_new_route_clicked(); void on_new_route_clicked();
void on_export_route_clicked();
void on_clone_route_clicked(); void on_clone_route_clicked();
void on_edit_route_clicked(); void on_edit_route_clicked();

View File

@ -545,6 +545,13 @@ For more information, see the document &quot;Configuration/DNS&quot;.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="export_route">
<property name="text">
<string>Export</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="edit_route"> <widget class="QPushButton" name="edit_route">
<property name="text"> <property name="text">

View File

@ -477,9 +477,9 @@ namespace NekoGui {
for (const auto &item: newChain) { for (const auto &item: newChain) {
if (!AddRouteChain(item)) { if (!AddRouteChain(item)) {
routes[item->id] = item; routes[item->id] = item;
routesIdOrder << item->id;
item->Save(); item->Save();
} }
routesIdOrder << item->id;
} }
auto currFiles = filterIntJsonFile("route_profiles"); auto currFiles = filterIntJsonFile("route_profiles");
for (const auto &item: currFiles) { // clean up removed route profiles for (const auto &item: currFiles) { // clean up removed route profiles

View File

@ -1,4 +1,7 @@
#include "include/ui/setting/dialog_manage_routes.h" #include "include/ui/setting/dialog_manage_routes.h"
#include <QClipboard>
#include "include/dataStore/Database.hpp" #include "include/dataStore/Database.hpp"
#include "3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp" #include "3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp"
@ -8,6 +11,8 @@
#include <QFile> #include <QFile>
#include <QMessageBox> #include <QMessageBox>
#include <QShortcut> #include <QShortcut>
#include <QTimer>
#include <QToolTip>
#include <include/api/gRPC.h> #include <include/api/gRPC.h>
void DialogManageRoutes::reloadProfileItems() { void DialogManageRoutes::reloadProfileItems() {
@ -25,14 +30,14 @@ void DialogManageRoutes::reloadProfileItems() {
for (const auto &item: chainList) { for (const auto &item: chainList) {
ui->route_prof->addItem(item->name); ui->route_prof->addItem(item->name);
ui->route_profiles->addItem(item->name); ui->route_profiles->addItem(item->name);
if (item->id == currentRouteProfileID) { if (item == currentRoute) {
ui->route_prof->setCurrentIndex(i); ui->route_prof->setCurrentIndex(i);
selectedChainGone=false; selectedChainGone=false;
} }
i++; i++;
} }
if (selectedChainGone) { if (selectedChainGone) {
currentRouteProfileID=chainList[0]->id; currentRoute=chainList[0];
ui->route_prof->setCurrentIndex(0); ui->route_prof->setCurrentIndex(0);
} }
blocker.unblock(); blocker.unblock();
@ -65,8 +70,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
NekoGui::profileManager->AddRouteChain(defaultChain); NekoGui::profileManager->AddRouteChain(defaultChain);
chainList.append(defaultChain); chainList.append(defaultChain);
} }
currentRouteProfileID = NekoGui::dataStore->routing->current_route_id; currentRoute = NekoGui::profileManager->GetRouteChain(NekoGui::dataStore->routing->current_route_id);
if (currentRouteProfileID < 0) currentRouteProfileID = chainList[0]->id; if (currentRoute == nullptr) currentRoute = chainList[0];
QStringList qsValue = {""}; QStringList qsValue = {""};
QString dnsHelpDocumentUrl; QString dnsHelpDocumentUrl;
@ -173,7 +178,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
} }
void DialogManageRoutes::updateCurrentRouteProfile(int idx) { void DialogManageRoutes::updateCurrentRouteProfile(int idx) {
currentRouteProfileID = chainList[idx]->id; currentRoute = chainList[idx];
} }
DialogManageRoutes::~DialogManageRoutes() { DialogManageRoutes::~DialogManageRoutes() {
@ -203,7 +208,7 @@ void DialogManageRoutes::accept() {
NekoGui::dataStore->fake_dns = ui->enable_fakeip->isChecked(); NekoGui::dataStore->fake_dns = ui->enable_fakeip->isChecked();
NekoGui::profileManager->UpdateRouteChains(chainList); NekoGui::profileManager->UpdateRouteChains(chainList);
NekoGui::dataStore->routing->current_route_id = currentRouteProfileID; NekoGui::dataStore->routing->current_route_id = currentRoute->id;
NekoGui::dataStore->routing->def_outbound = ui->default_out->currentText(); NekoGui::dataStore->routing->def_outbound = ui->default_out->currentText();
NekoGui::dataStore->enable_dns_server = ui->dnshijack_enable->isChecked(); NekoGui::dataStore->enable_dns_server = ui->dnshijack_enable->isChecked();
@ -241,6 +246,27 @@ void DialogManageRoutes::on_new_route_clicked() {
}); });
} }
void DialogManageRoutes::on_export_route_clicked()
{
auto idx = ui->route_profiles->currentRow();
if (idx < 0) return;
QJsonArray arr = chainList[idx]->get_route_rules(true, {});
QStringList res;
for (int i = 0; i < arr.count(); i++)
{
res.append(QJsonObject2QString(arr[i].toObject(), false));
}
QApplication::clipboard()->setText("[" + res.join(",") + "]");
QToolTip::showText(QCursor::pos(), "Copied!", this);
int r = ++tooltipID;
QTimer::singleShot(1500, [=] {
if (tooltipID != r) return;
QToolTip::hideText();
});
}
void DialogManageRoutes::on_clone_route_clicked() { void DialogManageRoutes::on_clone_route_clicked() {
auto idx = ui->route_profiles->currentRow(); auto idx = ui->route_profiles->currentRow();
if (idx < 0) return; if (idx < 0) return;
@ -282,8 +308,8 @@ void DialogManageRoutes::on_delete_route_clicked() {
return; return;
} }
chainList.removeAt(idx); chainList.removeAt(idx);
if (profileToDel->id == currentRouteProfileID) { if (profileToDel == currentRoute) {
currentRouteProfileID = chainList[0]->id; currentRoute = chainList[0];
} }
reloadProfileItems(); reloadProfileItems();
} }