mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 13:50:12 +08:00
fix route select issue &&
add route export
This commit is contained in:
parent
0ba7ada673
commit
6a5b5dc0bd
@ -31,7 +31,9 @@ private:
|
||||
|
||||
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;
|
||||
|
||||
@ -47,6 +49,8 @@ public slots:
|
||||
|
||||
void on_new_route_clicked();
|
||||
|
||||
void on_export_route_clicked();
|
||||
|
||||
void on_clone_route_clicked();
|
||||
|
||||
void on_edit_route_clicked();
|
||||
|
||||
@ -545,6 +545,13 @@ For more information, see the document "Configuration/DNS".</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="export_route">
|
||||
<property name="text">
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="edit_route">
|
||||
<property name="text">
|
||||
|
||||
@ -477,9 +477,9 @@ namespace NekoGui {
|
||||
for (const auto &item: newChain) {
|
||||
if (!AddRouteChain(item)) {
|
||||
routes[item->id] = item;
|
||||
routesIdOrder << item->id;
|
||||
item->Save();
|
||||
}
|
||||
routesIdOrder << item->id;
|
||||
}
|
||||
auto currFiles = filterIntJsonFile("route_profiles");
|
||||
for (const auto &item: currFiles) { // clean up removed route profiles
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
#include "include/ui/setting/dialog_manage_routes.h"
|
||||
|
||||
#include <QClipboard>
|
||||
|
||||
#include "include/dataStore/Database.hpp"
|
||||
|
||||
#include "3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp"
|
||||
@ -8,6 +11,8 @@
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <QShortcut>
|
||||
#include <QTimer>
|
||||
#include <QToolTip>
|
||||
#include <include/api/gRPC.h>
|
||||
|
||||
void DialogManageRoutes::reloadProfileItems() {
|
||||
@ -25,14 +30,14 @@ void DialogManageRoutes::reloadProfileItems() {
|
||||
for (const auto &item: chainList) {
|
||||
ui->route_prof->addItem(item->name);
|
||||
ui->route_profiles->addItem(item->name);
|
||||
if (item->id == currentRouteProfileID) {
|
||||
if (item == currentRoute) {
|
||||
ui->route_prof->setCurrentIndex(i);
|
||||
selectedChainGone=false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (selectedChainGone) {
|
||||
currentRouteProfileID=chainList[0]->id;
|
||||
currentRoute=chainList[0];
|
||||
ui->route_prof->setCurrentIndex(0);
|
||||
}
|
||||
blocker.unblock();
|
||||
@ -65,8 +70,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
|
||||
NekoGui::profileManager->AddRouteChain(defaultChain);
|
||||
chainList.append(defaultChain);
|
||||
}
|
||||
currentRouteProfileID = NekoGui::dataStore->routing->current_route_id;
|
||||
if (currentRouteProfileID < 0) currentRouteProfileID = chainList[0]->id;
|
||||
currentRoute = NekoGui::profileManager->GetRouteChain(NekoGui::dataStore->routing->current_route_id);
|
||||
if (currentRoute == nullptr) currentRoute = chainList[0];
|
||||
|
||||
QStringList qsValue = {""};
|
||||
QString dnsHelpDocumentUrl;
|
||||
@ -173,7 +178,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
|
||||
}
|
||||
|
||||
void DialogManageRoutes::updateCurrentRouteProfile(int idx) {
|
||||
currentRouteProfileID = chainList[idx]->id;
|
||||
currentRoute = chainList[idx];
|
||||
}
|
||||
|
||||
DialogManageRoutes::~DialogManageRoutes() {
|
||||
@ -203,7 +208,7 @@ void DialogManageRoutes::accept() {
|
||||
NekoGui::dataStore->fake_dns = ui->enable_fakeip->isChecked();
|
||||
|
||||
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->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() {
|
||||
auto idx = ui->route_profiles->currentRow();
|
||||
if (idx < 0) return;
|
||||
@ -282,8 +308,8 @@ void DialogManageRoutes::on_delete_route_clicked() {
|
||||
return;
|
||||
}
|
||||
chainList.removeAt(idx);
|
||||
if (profileToDel->id == currentRouteProfileID) {
|
||||
currentRouteProfileID = chainList[0]->id;
|
||||
if (profileToDel == currentRoute) {
|
||||
currentRoute = chainList[0];
|
||||
}
|
||||
reloadProfileItems();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user