diff --git a/include/configs/ConfigBuilder.hpp b/include/configs/ConfigBuilder.hpp index 748c00b..0416ede 100644 --- a/include/configs/ConfigBuilder.hpp +++ b/include/configs/ConfigBuilder.hpp @@ -4,6 +4,14 @@ #include "include/sys/Process.hpp" namespace Configs { + enum OSType + { + Unknown = 0, + Linux = 1, + Windows = 2, + Darwin = 3, + }; + class ExtraCoreData { public: @@ -52,6 +60,20 @@ namespace Configs { QJsonArray endpoints; }; + inline OSType getOS() + { +#ifdef Q_OS_MACOS + return Darwin; +#endif +#ifdef Q_OS_LINUX + return Linux; +#endif +#ifdef Q_OS_WIN + return Windows; +#endif + return Unknown; + }; + bool IsValid(const std::shared_ptr &ent); std::shared_ptr BuildTestConfig(const QList>& profiles, const std::map& ruleSetMap); diff --git a/include/ui/setting/dialog_manage_routes.ui b/include/ui/setting/dialog_manage_routes.ui index 1b28b0e..fb2dfa9 100644 --- a/include/ui/setting/dialog_manage_routes.ui +++ b/include/ui/setting/dialog_manage_routes.ui @@ -284,7 +284,7 @@ - + @@ -309,17 +309,8 @@ - - - - This is especially important and it is recommended to use the default value of "localhost". -If the default value does not work, try changing it to "223.5.5.5". -For more information, see the document "Configuration/DNS". - - - Direct DNS - - + + @@ -368,6 +359,28 @@ For more information, see the document "Configuration/DNS". + + + + <html><head/><body><p>Local DNS can not be used in some configurations, you will have to set an ip here to be used as local dns in such situations</p></body></html> + + + Local Override + + + + + + + This is especially important and it is recommended to use the default value of "localhost". +If the default value does not work, try changing it to "223.5.5.5". +For more information, see the document "Configuration/DNS". + + + Direct DNS + + + @@ -420,7 +433,7 @@ For more information, see the document "Configuration/DNS". - + Enable FakeIP diff --git a/src/configs/ConfigBuilder.cpp b/src/configs/ConfigBuilder.cpp index 0939188..9a820f2 100644 --- a/src/configs/ConfigBuilder.cpp +++ b/src/configs/ConfigBuilder.cpp @@ -434,6 +434,13 @@ namespace Configs { {"type", "underlying"} }; } + if (tunEnabled && getOS() == Darwin) + { + return { + {"type", "udp"}, + {"server", dataStore->core_box_underlying_dns} + }; + } return { {"type", "local"} }; @@ -522,6 +529,12 @@ namespace Configs { } } routeChain->Save(); + + if (getOS() == Darwin && dataStore->core_box_underlying_dns.isEmpty() && dataStore->spmode_vpn) + { + status->result->error = QObject::tr("Local DNS and Tun mode do not work together, please set an IP to be used as the Local DNS server in the Routing Settings -> Local override"); + return; + } // copy for modification routeChain = std::make_shared(*routeChain); @@ -789,7 +802,7 @@ namespace Configs { }; } } - if (Configs::dataStore->adblock_enable) { + if (dataStore->adblock_enable) { ruleSetArray += QJsonObject{ {"type", "remote"}, {"tag", "throne-adblocksingbox"}, @@ -925,7 +938,7 @@ namespace Configs { }; } - // Underlying 100% Working DNS + // Underlying DNS auto dnsLocalAddress = dataStore->core_box_underlying_dns.isEmpty() ? "local" : dataStore->core_box_underlying_dns; auto dnsLocalObj = BuildDnsObject(dnsLocalAddress, dataStore->spmode_vpn); dnsLocalObj["tag"] = "dns-local"; diff --git a/src/ui/setting/dialog_basic_settings.cpp b/src/ui/setting/dialog_basic_settings.cpp index 2fce444..e494ca1 100644 --- a/src/ui/setting/dialog_basic_settings.cpp +++ b/src/ui/setting/dialog_basic_settings.cpp @@ -269,19 +269,8 @@ void DialogBasicSettings::on_core_settings_clicked() { auto line = -1; MyLineEdit *core_box_clash_api; MyLineEdit *core_box_clash_api_secret; - MyLineEdit *core_box_underlying_dns; MyLineEdit *core_box_clash_listen_addr; // - auto core_box_underlying_dns_l = new QLabel(tr("Override underlying DNS")); - core_box_underlying_dns_l->setToolTip(tr( - "It is recommended to leave it blank, but it sometimes does not work, at this time you can set this option.\n" - "this rewrites the underlying(localhost) DNS in Tun Mode, normal mode, and also URL Test.")); - core_box_underlying_dns = new MyLineEdit; - core_box_underlying_dns->setText(Configs::dataStore->core_box_underlying_dns); - core_box_underlying_dns->setMinimumWidth(300); - layout->addWidget(core_box_underlying_dns_l, ++line, 0); - layout->addWidget(core_box_underlying_dns, line, 1); - // auto core_box_clash_listen_addr_l = new QLabel("Clash Api Listen Address"); core_box_clash_listen_addr = new MyLineEdit; core_box_clash_listen_addr->setText(Configs::dataStore->core_box_clash_listen_addr); @@ -304,7 +293,6 @@ void DialogBasicSettings::on_core_settings_clicked() { box->setOrientation(Qt::Horizontal); box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); connect(box, &QDialogButtonBox::accepted, w, [=,this] { - Configs::dataStore->core_box_underlying_dns = core_box_underlying_dns->text(); Configs::dataStore->core_box_clash_api = core_box_clash_api->text().toInt(); Configs::dataStore->core_box_clash_listen_addr = core_box_clash_listen_addr->text(); Configs::dataStore->core_box_clash_api_secret = core_box_clash_api_secret->text(); diff --git a/src/ui/setting/dialog_manage_routes.cpp b/src/ui/setting/dialog_manage_routes.cpp index a03e6a9..1000fe4 100644 --- a/src/ui/setting/dialog_manage_routes.cpp +++ b/src/ui/setting/dialog_manage_routes.cpp @@ -84,6 +84,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent, const std::mapdirect_dns_strategy->addItems(qsValue); ui->remote_dns_strategy->addItems(qsValue); + ui->local_override->setText(Configs::dataStore->core_box_underlying_dns); ui->enable_fakeip->setChecked(Configs::dataStore->fake_dns); // connect(ui->use_dns_object, &QCheckBox::stateChanged, this, [=,this](int state) { @@ -200,6 +201,7 @@ void DialogManageRoutes::accept() { Configs::dataStore->routing->remote_dns_strategy = ui->remote_dns_strategy->currentText(); Configs::dataStore->routing->direct_dns = ui->direct_dns->currentText(); Configs::dataStore->routing->direct_dns_strategy = ui->direct_dns_strategy->currentText(); + Configs::dataStore->core_box_underlying_dns = ui->local_override->text().trimmed(); Configs::dataStore->routing->dns_final_out = ui->dns_final_out->currentText(); Configs::dataStore->fake_dns = ui->enable_fakeip->isChecked();