mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 10:50:23 +08:00
remove: removed return type when setting up system proxy, related: #330
This commit is contained in:
parent
8c9d152f0b
commit
86b8ca5ef5
@ -168,11 +168,16 @@ namespace Qv2ray::components::proxy
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool SetSystemProxy(const QString &address, int httpPort, int socksPort, bool usePAC)
|
void SetSystemProxy(const QString &address, int httpPort, int socksPort, bool usePAC)
|
||||||
{
|
{
|
||||||
bool hasHTTP = (httpPort != 0);
|
bool hasHTTP = (httpPort != 0);
|
||||||
bool hasSOCKS = (socksPort != 0);
|
bool hasSOCKS = (socksPort != 0);
|
||||||
|
|
||||||
|
if (!(hasHTTP || hasSOCKS || usePAC)) {
|
||||||
|
LOG(PROXY, "Nothing?")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (usePAC) {
|
if (usePAC) {
|
||||||
LOG(PROXY, "Qv2ray will set system proxy to use PAC file")
|
LOG(PROXY, "Qv2ray will set system proxy to use PAC file")
|
||||||
} else {
|
} else {
|
||||||
@ -195,82 +200,69 @@ namespace Qv2ray::components::proxy
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG(PROXY, "Windows proxy string: " + __a)
|
LOG(PROXY, "Windows proxy string: " + __a)
|
||||||
|
auto proxyStrW = new WCHAR[__a.length() + 1];
|
||||||
|
wcscpy(proxyStrW, __a.toStdWString().c_str());
|
||||||
|
//
|
||||||
|
__QueryProxyOptions();
|
||||||
|
|
||||||
if (hasHTTP || hasSOCKS) {
|
if (!__SetProxyOptions(proxyStrW, usePAC)) {
|
||||||
auto proxyStrW = new WCHAR[__a.length() + 1];
|
LOG(PROXY, "Failed to set proxy.")
|
||||||
wcscpy(proxyStrW, __a.toStdWString().c_str());
|
|
||||||
//
|
|
||||||
__QueryProxyOptions();
|
|
||||||
|
|
||||||
if (!__SetProxyOptions(proxyStrW, usePAC)) {
|
|
||||||
LOG(PROXY, "Failed to set proxy.")
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
__QueryProxyOptions();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__QueryProxyOptions();
|
||||||
#elif defined(Q_OS_LINUX)
|
#elif defined(Q_OS_LINUX)
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
if (usePAC) {
|
if (usePAC) {
|
||||||
result = result && QProcess::execute("gsettings set org.gnome.system.proxy mode 'auto'") == QProcess::NormalExit;
|
QProcess::execute("gsettings set org.gnome.system.proxy mode 'auto'");
|
||||||
result = result && QProcess::execute("gsettings set org.gnome.system.proxy autoconfig-url '" + address + "'") == QProcess::NormalExit;
|
QProcess::execute("gsettings set org.gnome.system.proxy autoconfig-url '" + address + "'");
|
||||||
} else {
|
} else {
|
||||||
result = result && QProcess::execute("gsettings set org.gnome.system.proxy mode 'manual'") == QProcess::NormalExit;
|
QProcess::execute("gsettings set org.gnome.system.proxy mode 'manual'");
|
||||||
|
|
||||||
if (hasHTTP) {
|
if (hasHTTP) {
|
||||||
result = result && QProcess::execute("gsettings set org.gnome.system.proxy.http host '" + address + "'") == QProcess::NormalExit;
|
QProcess::execute("gsettings set org.gnome.system.proxy.http host '" + address + "'");
|
||||||
result = result && QProcess::execute("gsettings set org.gnome.system.proxy.http port " + QSTRN(httpPort)) == QProcess::NormalExit;
|
QProcess::execute("gsettings set org.gnome.system.proxy.http port " + QSTRN(httpPort));
|
||||||
//
|
QProcess::execute("gsettings set org.gnome.system.proxy.https host '" + address + "'");
|
||||||
result = result && QProcess::execute("gsettings set org.gnome.system.proxy.https host '" + address + "'") == QProcess::NormalExit;
|
QProcess::execute("gsettings set org.gnome.system.proxy.https port " + QSTRN(httpPort));
|
||||||
result = result && QProcess::execute("gsettings set org.gnome.system.proxy.https port " + QSTRN(httpPort)) == QProcess::NormalExit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSOCKS) {
|
if (hasSOCKS) {
|
||||||
result = result && QProcess::execute("gsettings set org.gnome.system.proxy.socks host '" + address + "'") == QProcess::NormalExit;
|
QProcess::execute("gsettings set org.gnome.system.proxy.socks host '" + address + "'");
|
||||||
result = result && QProcess::execute("gsettings set org.gnome.system.proxy.socks port " + QSTRN(socksPort)) == QProcess::NormalExit;
|
QProcess::execute("gsettings set org.gnome.system.proxy.socks port " + QSTRN(socksPort));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result) {
|
//if (!result) {
|
||||||
LOG(PROXY, "Something wrong happens when setting system proxy -> Gnome ONLY.")
|
// 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.")
|
// LOG(PROXY, "If you are using KDE Plasma and receiving this message, just simply ignore this.")
|
||||||
}
|
//}
|
||||||
|
|
||||||
return result;
|
|
||||||
#else
|
#else
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
for (auto service : macOSgetNetworkServices()) {
|
for (auto service : macOSgetNetworkServices()) {
|
||||||
LOG(PROXY, "Setting proxy for interface: " + service)
|
LOG(PROXY, "Setting proxy for interface: " + service)
|
||||||
|
|
||||||
if (usePAC) {
|
if (usePAC) {
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setautoproxystate " + service + " on") == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setautoproxystate " + service + " on");
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setautoproxyurl " + service + " " + address) == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setautoproxyurl " + service + " " + address);
|
||||||
} else {
|
} else {
|
||||||
if (hasHTTP) {
|
if (hasHTTP) {
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setwebproxystate " + service + " on") == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setwebproxystate " + service + " on");
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setsecurewebproxystate " + service + " on") == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setsecurewebproxystate " + service + " on");
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setwebproxy " + service + " " + address + " " + QSTRN(httpPort)) == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setwebproxy " + service + " " + address + " " + QSTRN(httpPort));
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setsecurewebproxy " + service + " " + address + " " + QSTRN(httpPort)) == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setsecurewebproxy " + service + " " + address + " " + QSTRN(httpPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSOCKS) {
|
if (hasSOCKS) {
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setsocksfirewallproxystate " + service + " on") == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setsocksfirewallproxystate " + service + " on");
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setsocksfirewallproxy " + service + " " + address + " " + QSTRN(socksPort)) == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setsocksfirewallproxy " + service + " " + address + " " + QSTRN(socksPort));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClearSystemProxy()
|
void ClearSystemProxy()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
LOG(PROXY, "Cleaning system proxy settings.")
|
LOG(PROXY, "Cleaning system proxy settings.")
|
||||||
@ -303,18 +295,17 @@ namespace Qv2ray::components::proxy
|
|||||||
InternetSetOption(nullptr, INTERNET_OPTION_REFRESH, nullptr, 0);
|
InternetSetOption(nullptr, INTERNET_OPTION_REFRESH, nullptr, 0);
|
||||||
return bReturn;
|
return bReturn;
|
||||||
#elif defined(Q_OS_LINUX)
|
#elif defined(Q_OS_LINUX)
|
||||||
return QProcess::execute("gsettings set org.gnome.system.proxy mode 'none'") == QProcess::ExitStatus::NormalExit;
|
QProcess::execute("gsettings set org.gnome.system.proxy mode 'none'");
|
||||||
#else
|
#else
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
for (auto service : macOSgetNetworkServices()) {
|
for (auto service : macOSgetNetworkServices()) {
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setautoproxystate " + service + " off") == QProcess::NormalExit;
|
LOG(PROXY, "Clearing proxy for interface: " + service)
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setwebproxystate " + service + " off") == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setautoproxystate " + service + " off");
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setsecurewebproxystate " + service + " off") == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setwebproxystate " + service + " off");
|
||||||
result = result && QProcess::execute("/usr/sbin/networksetup -setsocksfirewallproxystate " + service + " off") == QProcess::NormalExit;
|
QProcess::execute("/usr/sbin/networksetup -setsecurewebproxystate " + service + " off");
|
||||||
|
QProcess::execute("/usr/sbin/networksetup -setsocksfirewallproxystate " + service + " off");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
//
|
//
|
||||||
namespace Qv2ray::components::proxy
|
namespace Qv2ray::components::proxy
|
||||||
{
|
{
|
||||||
bool ClearSystemProxy();
|
void ClearSystemProxy();
|
||||||
bool SetSystemProxy(const QString &address, int http_port, int socks_port, bool usePAC);
|
void SetSystemProxy(const QString &address, int http_port, int socks_port, bool usePAC);
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace Qv2ray::components;
|
using namespace Qv2ray::components;
|
||||||
|
Loading…
Reference in New Issue
Block a user