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)" let proxyConfig = "\(host):\(port)"
result(proxyConfig) result(proxyConfig)
} else { } else {
result("") result("no proxy")
} }
} }

View File

@@ -125,16 +125,15 @@ class AppDio extends DioForNative {
} }
void setSystemProxy() { void setSystemProxy() {
HttpOverrides.global = _ProxyHttpOverrides() HttpOverrides.global = _ProxyHttpOverrides()..findProxy(Uri());
..findProxy(Uri());
} }
class _ProxyHttpOverrides extends HttpOverrides { class _ProxyHttpOverrides extends HttpOverrides {
String proxy = "DIRECT"; String proxy = "DIRECT";
String findProxy(Uri uri) { String findProxy(Uri uri) {
var haveUserProxy = appdata.settings["proxy"] != null var haveUserProxy = appdata.settings["proxy"] != null &&
&& appdata.settings["proxy"].toString().isNotEmpty; appdata.settings["proxy"].toString().removeAllBlank.isNotEmpty;
if (!App.isLinux && !haveUserProxy) { if (!App.isLinux && !haveUserProxy) {
var channel = const MethodChannel("pixes/proxy"); var channel = const MethodChannel("pixes/proxy");
channel.invokeMethod("getProxy").then((value) { channel.invokeMethod("getProxy").then((value) {
@@ -158,6 +157,16 @@ class _ProxyHttpOverrides extends HttpOverrides {
proxy = "PROXY ${appdata.settings["proxy"]}"; 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; return proxy;
} }