mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-18 20:50:09 +08:00
refactor: declare ruleSetMap as static const
This commit is contained in:
parent
6a1dec8755
commit
16e7c35885
@ -76,11 +76,11 @@ namespace Configs {
|
||||
|
||||
bool IsValid(const std::shared_ptr<ProxyEntity> &ent);
|
||||
|
||||
std::shared_ptr<BuildTestConfigResult> BuildTestConfig(const QList<std::shared_ptr<ProxyEntity>>& profiles, const std::map<std::string, std::string>& ruleSetMap);
|
||||
std::shared_ptr<BuildTestConfigResult> BuildTestConfig(const QList<std::shared_ptr<ProxyEntity>>& profiles);
|
||||
|
||||
std::shared_ptr<BuildConfigResult> BuildConfig(const std::shared_ptr<ProxyEntity> &ent, const std::map<std::string, std::string>& ruleSetMap, bool forTest, bool forExport, int chainID = 0);
|
||||
std::shared_ptr<BuildConfigResult> BuildConfig(const std::shared_ptr<ProxyEntity> &ent, bool forTest, bool forExport, int chainID = 0);
|
||||
|
||||
void BuildConfigSingBox(const std::shared_ptr<BuildConfigStatus> &status, const std::map<std::string, std::string>& ruleSetMap);
|
||||
void BuildConfigSingBox(const std::shared_ptr<BuildConfigStatus> &status);
|
||||
|
||||
QJsonObject BuildDnsObject(QString address, bool tunEnabled);
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "Utils.hpp"
|
||||
#include "ConfigItem.hpp"
|
||||
#include "DataStore.hpp"
|
||||
#include <srslist.h>
|
||||
|
||||
// Switch core support
|
||||
|
||||
|
||||
@ -207,8 +207,6 @@ private:
|
||||
// shortcuts
|
||||
QList<QShortcut*> hiddenMenuShortcuts;
|
||||
|
||||
std::map<std::string, std::string> ruleSetMap;
|
||||
|
||||
QStringList remoteRouteProfiles;
|
||||
QMutex mu_remoteRouteProfiles;
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ class RouteItem : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RouteItem(QWidget *parent = nullptr, const std::shared_ptr<Configs::RoutingChain>& routeChain = nullptr, const std::map<std::string, std::string>& ruleSetMap = {});
|
||||
explicit RouteItem(QWidget *parent = nullptr, const std::shared_ptr<Configs::RoutingChain>& routeChain = nullptr);
|
||||
~RouteItem() override;
|
||||
|
||||
std::shared_ptr<Configs::RoutingChain> chain;
|
||||
|
||||
@ -18,7 +18,7 @@ class DialogManageRoutes : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogManageRoutes(QWidget *parent = nullptr, const std::map<std::string, std::string>& dataMap = {});
|
||||
explicit DialogManageRoutes(QWidget *parent = nullptr);
|
||||
|
||||
~DialogManageRoutes() override;
|
||||
|
||||
@ -35,8 +35,6 @@ private:
|
||||
|
||||
int tooltipID = 0;
|
||||
|
||||
std::map<std::string, std::string> ruleSetMap;
|
||||
|
||||
void set_dns_hijack_enability(bool enable) const;
|
||||
|
||||
static bool validate_dns_rules(const QString &rawString);
|
||||
|
||||
@ -41,7 +41,7 @@ namespace Configs {
|
||||
|
||||
// Common
|
||||
|
||||
std::shared_ptr<BuildConfigResult> BuildConfig(const std::shared_ptr<ProxyEntity> &ent, const std::map<std::string, std::string>& ruleSetMap, bool forTest, bool forExport, int chainID) {
|
||||
std::shared_ptr<BuildConfigResult> BuildConfig(const std::shared_ptr<ProxyEntity> &ent, bool forTest, bool forExport, int chainID) {
|
||||
auto result = std::make_shared<BuildConfigResult>();
|
||||
result->extraCoreData = std::make_shared<ExtraCoreData>();
|
||||
auto status = std::make_shared<BuildConfigStatus>();
|
||||
@ -60,7 +60,7 @@ namespace Configs {
|
||||
}
|
||||
result->coreConfig = QString2QJsonObject(customBean->config_simple);
|
||||
} else {
|
||||
BuildConfigSingBox(status, ruleSetMap);
|
||||
BuildConfigSingBox(status);
|
||||
}
|
||||
|
||||
// apply custom config
|
||||
@ -116,7 +116,7 @@ namespace Configs {
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<BuildTestConfigResult> BuildTestConfig(const QList<std::shared_ptr<ProxyEntity>>& profiles, const std::map<std::string, std::string>& ruleSetMap) {
|
||||
std::shared_ptr<BuildTestConfigResult> BuildTestConfig(const QList<std::shared_ptr<ProxyEntity>>& profiles) {
|
||||
auto results = std::make_shared<BuildTestConfigResult>();
|
||||
|
||||
QJsonArray outboundArray = {
|
||||
@ -140,7 +140,7 @@ namespace Configs {
|
||||
item->latency = -1;
|
||||
continue;
|
||||
}
|
||||
auto res = BuildConfig(item, ruleSetMap, true, false, ++index);
|
||||
auto res = BuildConfig(item, true, false, ++index);
|
||||
if (!res->error.isEmpty()) {
|
||||
results->error = res->error;
|
||||
return results;
|
||||
@ -509,7 +509,7 @@ namespace Configs {
|
||||
}
|
||||
|
||||
|
||||
void BuildConfigSingBox(const std::shared_ptr<BuildConfigStatus> &status, const std::map<std::string, std::string>& ruleSetMap) {
|
||||
void BuildConfigSingBox(const std::shared_ptr<BuildConfigStatus> &status) {
|
||||
// Prefetch
|
||||
auto routeChain = profileManager->GetRouteChain(dataStore->routing->current_route_id);
|
||||
if (routeChain == nullptr) {
|
||||
|
||||
@ -59,8 +59,6 @@
|
||||
|
||||
#include "include/sys/macos/MacOS.h"
|
||||
|
||||
#include <srslist.h>
|
||||
|
||||
void UI_InitMainWindow() {
|
||||
mainwindow = new MainWindow;
|
||||
}
|
||||
@ -448,9 +446,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
}
|
||||
});
|
||||
|
||||
std::vector<uint8_t> srsvec(std::begin(srslist), std::end(srslist));
|
||||
ruleSetMap = spb::pb::deserialize<libcore::RuleSet>(srsvec).items;
|
||||
|
||||
auto getRemoteRouteProfiles = [=,this]
|
||||
{
|
||||
auto resp = NetworkRequestHelper::HttpGet("https://api.github.com/repos/throneproj/routeprofiles/git/trees/profile");
|
||||
@ -906,7 +901,7 @@ void MainWindow::on_menu_manage_groups_triggered() {
|
||||
void MainWindow::on_menu_routing_settings_triggered() {
|
||||
if (dialog_is_using) return;
|
||||
dialog_is_using = true;
|
||||
auto dialog = new DialogManageRoutes(this, ruleSetMap);
|
||||
auto dialog = new DialogManageRoutes(this);
|
||||
connect(dialog, &QDialog::finished, this, [=,this] {
|
||||
dialog->deleteLater();
|
||||
dialog_is_using = false;
|
||||
@ -1782,7 +1777,7 @@ void MainWindow::on_menu_export_config_triggered() {
|
||||
auto ent = ents.first();
|
||||
if (ent->bean->DisplayCoreType() != software_core_name) return;
|
||||
|
||||
auto result = BuildConfig(ent, ruleSetMap, false, true);
|
||||
auto result = BuildConfig(ent, false, true);
|
||||
QString config_core = QJsonObject2QString(result->coreConfig, true);
|
||||
QApplication::clipboard()->setText(config_core);
|
||||
|
||||
@ -1794,11 +1789,11 @@ void MainWindow::on_menu_export_config_triggered() {
|
||||
msg.setDefaultButton(QMessageBox::Ok);
|
||||
msg.exec();
|
||||
if (msg.clickedButton() == button_1) {
|
||||
result = BuildConfig(ent, ruleSetMap, false, false);
|
||||
result = BuildConfig(ent, false, false);
|
||||
config_core = QJsonObject2QString(result->coreConfig, true);
|
||||
QApplication::clipboard()->setText(config_core);
|
||||
} else if (msg.clickedButton() == button_2) {
|
||||
result = BuildConfig(ent, ruleSetMap, true, false);
|
||||
result = BuildConfig(ent, true, false);
|
||||
config_core = QJsonObject2QString(result->coreConfig, true);
|
||||
QApplication::clipboard()->setText(config_core);
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ void MainWindow::urltest_current_group(const QList<std::shared_ptr<Configs::Prox
|
||||
}
|
||||
|
||||
runOnNewThread([this, profiles]() {
|
||||
auto buildObject = Configs::BuildTestConfig(profiles, ruleSetMap);
|
||||
auto buildObject = Configs::BuildTestConfig(profiles);
|
||||
if (!buildObject->error.isEmpty()) {
|
||||
MW_show_log(tr("Failed to build test config: ") + buildObject->error);
|
||||
speedtestRunning.unlock();
|
||||
@ -237,7 +237,7 @@ void MainWindow::speedtest_current_group(const QList<std::shared_ptr<Configs::Pr
|
||||
runOnNewThread([this, profiles, testCurrent]() {
|
||||
if (!testCurrent)
|
||||
{
|
||||
auto buildObject = Configs::BuildTestConfig(profiles, ruleSetMap);
|
||||
auto buildObject = Configs::BuildTestConfig(profiles);
|
||||
if (!buildObject->error.isEmpty()) {
|
||||
MW_show_log(tr("Failed to build test config: ") + buildObject->error);
|
||||
speedtestRunning.unlock();
|
||||
@ -466,7 +466,7 @@ void MainWindow::profile_start(int _id) {
|
||||
auto group = Configs::profileManager->GetGroup(ent->gid);
|
||||
if (group == nullptr || group->archive) return;
|
||||
|
||||
auto result = BuildConfig(ent, ruleSetMap, false, false);
|
||||
auto result = BuildConfig(ent, false, false);
|
||||
if (!result->error.isEmpty()) {
|
||||
MessageBoxWarning(tr("BuildConfig return error"), result->error);
|
||||
return;
|
||||
|
||||
@ -47,7 +47,7 @@ QStringList get_all_outbounds() {
|
||||
return res;
|
||||
}
|
||||
|
||||
RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<Configs::RoutingChain>& routeChain, const std::map<std::string, std::string>& ruleSetMap)
|
||||
RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<Configs::RoutingChain>& routeChain)
|
||||
: QDialog(parent), ui(new Ui::RouteItem) {
|
||||
ui->setupUi(this);
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ bool DialogManageRoutes::validate_dns_rules(const QString &rawString) {
|
||||
return true;
|
||||
}
|
||||
|
||||
DialogManageRoutes::DialogManageRoutes(QWidget *parent, const std::map<std::string, std::string>& dataMap) : QDialog(parent), ui(new Ui::DialogManageRoutes) {
|
||||
DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(new Ui::DialogManageRoutes) {
|
||||
ui->setupUi(this);
|
||||
auto profiles = Configs::profileManager->routes;
|
||||
for (const auto &item: profiles) {
|
||||
@ -141,7 +141,6 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent, const std::map<std::stri
|
||||
MessageBoxInfo("What is this?", Configs::Information::HijackInfo);
|
||||
});
|
||||
|
||||
ruleSetMap = dataMap;
|
||||
QStringList ruleItems = {"domain:", "suffix:", "regex:"};
|
||||
for (const auto& item : ruleSetMap) {
|
||||
ruleItems.append("ruleset:" + QString::fromStdString(item.first));
|
||||
@ -234,7 +233,7 @@ void DialogManageRoutes::accept() {
|
||||
}
|
||||
|
||||
void DialogManageRoutes::on_new_route_clicked() {
|
||||
routeChainWidget = new RouteItem(this, Configs::ProfileManager::NewRouteChain(), ruleSetMap);
|
||||
routeChainWidget = new RouteItem(this, Configs::ProfileManager::NewRouteChain());
|
||||
routeChainWidget->setWindowModality(Qt::ApplicationModal);
|
||||
routeChainWidget->show();
|
||||
connect(routeChainWidget, &RouteItem::settingsChanged, this, [=,this](const std::shared_ptr<Configs::RoutingChain>& chain) {
|
||||
@ -280,7 +279,7 @@ void DialogManageRoutes::on_edit_route_clicked() {
|
||||
auto idx = ui->route_profiles->currentRow();
|
||||
if (idx < 0) return;
|
||||
|
||||
routeChainWidget = new RouteItem(this, chainList[idx], ruleSetMap);
|
||||
routeChainWidget = new RouteItem(this, chainList[idx]);
|
||||
routeChainWidget->setWindowModality(Qt::ApplicationModal);
|
||||
routeChainWidget->show();
|
||||
connect(routeChainWidget, &RouteItem::settingsChanged, this, [=,this](const std::shared_ptr<Configs::RoutingChain>& chain) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user