mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 12:57:24 +00:00
fix proxy
This commit is contained in:
@@ -17,7 +17,7 @@ import Flutter
|
|||||||
let proxyConfig = "\(host):\(port)"
|
let proxyConfig = "\(host):\(port)"
|
||||||
result(proxyConfig)
|
result(proxyConfig)
|
||||||
} else {
|
} else {
|
||||||
result("")
|
result("no proxy")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user