mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-21 11:20:49 +08:00
refactor: system-proxy/linux/set
This commit is contained in:
parent
5c66b29879
commit
b5ec43c0df
@ -233,46 +233,62 @@ namespace Qv2ray::components::proxy
|
|||||||
actions << QString("gsettings set org.gnome.system.proxy mode '%1'").arg("manual");
|
actions << QString("gsettings set org.gnome.system.proxy mode '%1'").arg("manual");
|
||||||
bool isKDE = qEnvironmentVariable("XDG_SESSION_DESKTOP") == "KDE";
|
bool isKDE = qEnvironmentVariable("XDG_SESSION_DESKTOP") == "KDE";
|
||||||
const auto configPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
|
const auto configPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
|
||||||
if (isKDE)
|
|
||||||
|
// Setting Proxy Mode to Manual
|
||||||
{
|
{
|
||||||
LOG(MODULE_PROXY, "KDE detected")
|
// for GNOME:
|
||||||
actions << QString("kwriteconfig5 --file " + configPath + "/kioslaverc --group \"Proxy Settings\" --key ProxyType 1");
|
{
|
||||||
}
|
actions << "gsettings set org.gnome.system.proxy mode 'manual'";
|
||||||
if (hasHTTP)
|
}
|
||||||
{
|
|
||||||
actions << QString("gsettings set org.gnome.system.proxy.http host '%1'").arg(address);
|
// for KDE:
|
||||||
actions << QString("gsettings set org.gnome.system.proxy.http port %1").arg(httpPort);
|
|
||||||
//
|
|
||||||
actions << QString("gsettings set org.gnome.system.proxy.https host '%1'").arg(address);
|
|
||||||
actions << QString("gsettings set org.gnome.system.proxy.https port %1").arg(httpPort);
|
|
||||||
if (isKDE)
|
if (isKDE)
|
||||||
{
|
{
|
||||||
// FTP here should be scheme: ftp://
|
LOG(MODULE_PROXY, "KDE detected")
|
||||||
for (auto protocol : { "http", "ftp", "https" })
|
actions << QString("kwriteconfig5 --file %1/kioslaverc --group 'Proxy Settings' --key ProxyType 1").arg(configPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure HTTP Proxies for HTTP, FTP and HTTPS
|
||||||
|
if (hasHTTP)
|
||||||
|
{
|
||||||
|
// iterate over protocols...
|
||||||
|
for (const auto protocol : { "http", "ftp", "https" })
|
||||||
|
{
|
||||||
|
// for GNOME:
|
||||||
{
|
{
|
||||||
auto str =
|
actions << QString("gsettings set org.gnome.system.proxy.%1 host '%2'").arg(protocol, address);
|
||||||
QString("kwriteconfig5 --file " + configPath + "/kioslaverc --group \"Proxy Settings\" --key %1Proxy \"http://%2 %3\"")
|
actions << QString("gsettings set org.gnome.system.proxy.%1 port %2").arg(protocol, QSTRN(httpPort));
|
||||||
.arg(protocol)
|
}
|
||||||
.arg(address)
|
|
||||||
.arg(QSTRN(httpPort));
|
// for KDE:
|
||||||
actions << str;
|
if (isKDE)
|
||||||
|
{
|
||||||
|
actions << QString("kwriteconfig5 --file %1/kioslaverc --group 'Proxy Settings' --key %2Proxy 'http://%3 %4'")
|
||||||
|
.arg(configPath, protocol, address, QSTRN(httpPort));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure SOCKS5 Proxies
|
||||||
if (hasSOCKS)
|
if (hasSOCKS)
|
||||||
{
|
{
|
||||||
actions << QString("gsettings set org.gnome.system.proxy.socks host '%1'").arg(address);
|
// for GNOME:
|
||||||
actions << QString("gsettings set org.gnome.system.proxy.socks port %1").arg(socksPort);
|
{
|
||||||
|
actions << QString("gsettings set org.gnome.system.proxy.socks host '%1'").arg(address);
|
||||||
|
actions << QString("gsettings set org.gnome.system.proxy.socks port %1").arg(socksPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
// for KDE:
|
||||||
if (isKDE)
|
if (isKDE)
|
||||||
{
|
{
|
||||||
actions << QString("kwriteconfig5 --file " + configPath +
|
actions << QString("kwriteconfig5 --file %1/kioslaverc --group 'Proxy Settings' --key socksProxy 'socks://%2 %3'")
|
||||||
"/kioslaverc --group \"Proxy Settings\" --key socksProxy \"socks://%1 %2\"")
|
.arg(configPath, address, QSTRN(socksPort));
|
||||||
.arg(address)
|
|
||||||
.arg(QSTRN(socksPort));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute them all!
|
||||||
|
//
|
||||||
// note: do not use std::all_of / any_of / none_of,
|
// note: do not use std::all_of / any_of / none_of,
|
||||||
// because those are short-circuit and cannot guarantee atomicity.
|
// because those are short-circuit and cannot guarantee atomicity.
|
||||||
auto result = std::count_if(actions.cbegin(), actions.cend(), [](const QString &action) {
|
auto result = std::count_if(actions.cbegin(), actions.cend(), [](const QString &action) {
|
||||||
@ -286,7 +302,8 @@ namespace Qv2ray::components::proxy
|
|||||||
LOG(MODULE_PROXY, "It may happen if you are using KDE with no gsettings support.")
|
LOG(MODULE_PROXY, "It may happen if you are using KDE with no gsettings support.")
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_UNUSED(result);
|
// TODO: Post-settings for DDE
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
for (auto service : macOSgetNetworkServices())
|
for (auto service : macOSgetNetworkServices())
|
||||||
|
Loading…
Reference in New Issue
Block a user