fix proxy

This commit is contained in:
wgh19
2024-05-16 17:54:17 +08:00
parent ed9213b12e
commit bfad0dc176
2 changed files with 18 additions and 9 deletions

View File

@@ -17,7 +17,7 @@ import Flutter
let proxyConfig = "\(host):\(port)"
result(proxyConfig)
} else {
result("")
result("no proxy")
}
}

View File

@@ -125,23 +125,22 @@ class AppDio extends DioForNative {
}
void setSystemProxy() {
HttpOverrides.global = _ProxyHttpOverrides()
..findProxy(Uri());
HttpOverrides.global = _ProxyHttpOverrides()..findProxy(Uri());
}
class _ProxyHttpOverrides extends HttpOverrides {
String proxy = "DIRECT";
String findProxy(Uri uri) {
var haveUserProxy = appdata.settings["proxy"] != null
&& appdata.settings["proxy"].toString().isNotEmpty;
if(!App.isLinux && !haveUserProxy){
var haveUserProxy = appdata.settings["proxy"] != null &&
appdata.settings["proxy"].toString().removeAllBlank.isNotEmpty;
if (!App.isLinux && !haveUserProxy) {
var channel = const MethodChannel("pixes/proxy");
channel.invokeMethod("getProxy").then((value) {
if(value.toString().toLowerCase() == "no proxy"){
if (value.toString().toLowerCase() == "no proxy") {
proxy = "DIRECT";
} else {
if(proxy.contains("https")){
if (proxy.contains("https")) {
var proxies = value.split(";");
for (String proxy in proxies) {
proxy = proxy.removeAllBlank;
@@ -154,10 +153,20 @@ class _ProxyHttpOverrides extends HttpOverrides {
}
});
} else {
if(haveUserProxy){
if (haveUserProxy) {
proxy = "PROXY ${appdata.settings["proxy"]}";
}
}
// check validation
if (proxy.startsWith("PROXY")) {
var uri = proxy.replaceFirst("PROXY", "").removeAllBlank;
if (!uri.startsWith("http")) {
uri += "http://";
}
if (!uri.isURL) {
return "DIRECT";
}
}
return proxy;
}