Merge branch 'dev-proxyconfig-refactoring' into dev

This commit is contained in:
Qv2ray-dev 2020-02-11 20:17:56 +08:00
commit 1e78f358cf

View File

@ -211,30 +211,40 @@ namespace Qv2ray::components::proxy
__QueryProxyOptions(); __QueryProxyOptions();
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
QStringList actions;
auto proxyMode = usePAC ? "auto" : "manual";
actions << QString("gsettings set org.gnome.system.proxy mode '%1'").arg(proxyMode);
if (usePAC) { if (usePAC) {
QProcess::execute("gsettings set org.gnome.system.proxy mode 'auto'"); actions << QString("gsettings set org.gnome.system.proxy autoconfig-url '%1'").arg(address);
QProcess::execute("gsettings set org.gnome.system.proxy autoconfig-url '" + address + "'");
} else { } else {
QProcess::execute("gsettings set org.gnome.system.proxy mode 'manual'");
if (hasHTTP) { if (hasHTTP) {
QProcess::execute("gsettings set org.gnome.system.proxy.http host '" + address + "'"); actions << QString("gsettings set org.gnome.system.proxy.http host '%1'").arg(address);
QProcess::execute("gsettings set org.gnome.system.proxy.http port " + QSTRN(httpPort)); actions << QString("gsettings set org.gnome.system.proxy.http port %1").arg(httpPort);
QProcess::execute("gsettings set org.gnome.system.proxy.https host '" + address + "'"); //
QProcess::execute("gsettings set org.gnome.system.proxy.https port " + QSTRN(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 (hasSOCKS) { if (hasSOCKS) {
QProcess::execute("gsettings set org.gnome.system.proxy.socks host '" + address + "'"); actions << QString("gsettings set org.gnome.system.proxy.socks host '%1'").arg(address);
QProcess::execute("gsettings set org.gnome.system.proxy.socks port " + QSTRN(socksPort)); actions << QString("gsettings set org.gnome.system.proxy.socks port %1").arg(socksPort);
} }
} }
//if (!result) { // note: do not use std::all_of / any_of / none_of,
// LOG(PROXY, "Something wrong happens when setting system proxy -> Gnome ONLY.") // because those are short-circuit and cannot guarantee atomicity.
// LOG(PROXY, "If you are using KDE Plasma and receiving this message, just simply ignore this.") auto result = std::count_if(actions.cbegin(), actions.cend(), [](const QString & action) {
//} DEBUG(PROXY, action)
return QProcess::execute(action) == QProcess::NormalExit;
}) == actions.size();
if (!result) {
LOG(PROXY, "Something wrong happens when setting system proxy -> Gnome ONLY.")
LOG(PROXY, "If you are using KDE Plasma and receiving this message, just simply ignore this.")
}
Q_UNUSED(result);
#else #else
for (auto service : macOSgetNetworkServices()) { for (auto service : macOSgetNetworkServices()) {