fix: url test issues, avoid multiple test, and change outbound on test
This commit is contained in:
@@ -40,20 +40,16 @@ class IpInfoNotifier extends _$IpInfoNotifier with AppLogger {
|
||||
// );
|
||||
if (!_forceCheck && !serviceRunning) {
|
||||
throw const ServiceNotRunning();
|
||||
} else if ((_idle && !_forceCheck) ||
|
||||
(!_forceCheck && serviceRunning && !autoCheck)) {
|
||||
} else if ((_idle && !_forceCheck) || (!_forceCheck && serviceRunning && !autoCheck)) {
|
||||
throw const UnknownIp();
|
||||
}
|
||||
|
||||
_forceCheck = false;
|
||||
final info = await ref
|
||||
.watch(proxyRepositoryProvider)
|
||||
.getCurrentIpInfo(cancelToken)
|
||||
.getOrElse(
|
||||
final info = await ref.watch(proxyRepositoryProvider).getCurrentIpInfo(cancelToken).getOrElse(
|
||||
(err) {
|
||||
loggy.warning("error getting proxy ip info", err, StackTrace.current);
|
||||
// throw err; //hiddify: remove exception to be logged
|
||||
throw const UnknownIp();
|
||||
throw err; //hiddify: remove exception to be logged
|
||||
//throw const UnknownIp();
|
||||
},
|
||||
).run();
|
||||
|
||||
@@ -93,11 +89,7 @@ class ActiveProxyNotifier extends _$ActiveProxyNotifier with AppLogger {
|
||||
throw const ServiceNotRunning();
|
||||
}
|
||||
|
||||
yield* ref
|
||||
.watch(proxyRepositoryProvider)
|
||||
.watchActiveProxies()
|
||||
.map((event) => event.getOrElse((l) => throw l))
|
||||
.map((event) => event.firstOrNull!.items.first);
|
||||
yield* ref.watch(proxyRepositoryProvider).watchActiveProxies().map((event) => event.getOrElse((l) => throw l)).map((event) => event.firstOrNull!.items.first);
|
||||
}
|
||||
|
||||
final _urlTestThrottler = Throttler(const Duration(seconds: 2));
|
||||
@@ -106,17 +98,9 @@ class ActiveProxyNotifier extends _$ActiveProxyNotifier with AppLogger {
|
||||
var groupTag = groupTag_;
|
||||
_urlTestThrottler(
|
||||
() async {
|
||||
loggy.debug("testing group: [$groupTag]");
|
||||
if (!["auto", "select"].contains(groupTag)) {
|
||||
loggy.warning("only proxy group can do url test");
|
||||
groupTag = "select";
|
||||
}
|
||||
if (state case AsyncData()) {
|
||||
await ref.read(hapticServiceProvider.notifier).lightImpact();
|
||||
await ref
|
||||
.read(proxyRepositoryProvider)
|
||||
.urlTest(groupTag)
|
||||
.getOrElse((err) {
|
||||
await ref.read(proxyRepositoryProvider).urlTest(groupTag).getOrElse((err) {
|
||||
loggy.warning("error testing group", err);
|
||||
throw err;
|
||||
}).run();
|
||||
|
||||
@@ -19,9 +19,7 @@ abstract interface class ProxyRepository {
|
||||
TaskEither<ProxyFailure, Unit> urlTest(String groupTag);
|
||||
}
|
||||
|
||||
class ProxyRepositoryImpl
|
||||
with ExceptionHandler, InfraLogger
|
||||
implements ProxyRepository {
|
||||
class ProxyRepositoryImpl with ExceptionHandler, InfraLogger implements ProxyRepository {
|
||||
ProxyRepositoryImpl({
|
||||
required this.singbox,
|
||||
required this.client,
|
||||
@@ -103,10 +101,7 @@ class ProxyRepositoryImpl
|
||||
String outboundTag,
|
||||
) {
|
||||
return exceptionHandler(
|
||||
() => singbox
|
||||
.selectOutbound(groupTag, outboundTag)
|
||||
.mapLeft(ProxyUnexpectedFailure.new)
|
||||
.run(),
|
||||
() => singbox.selectOutbound(groupTag, outboundTag).mapLeft(ProxyUnexpectedFailure.new).run(),
|
||||
ProxyUnexpectedFailure.new,
|
||||
);
|
||||
}
|
||||
@@ -114,18 +109,19 @@ class ProxyRepositoryImpl
|
||||
@override
|
||||
TaskEither<ProxyFailure, Unit> urlTest(String groupTag_) {
|
||||
var groupTag = groupTag_;
|
||||
if (!["auto", "select"].contains(groupTag)) {
|
||||
loggy.warning("only proxy group can do url test");
|
||||
groupTag = "select";
|
||||
loggy.debug("testing group: [$groupTag]");
|
||||
if (!["auto"].contains(groupTag)) {
|
||||
loggy.warning("only auto proxy group can do url test. Please change go code if you want");
|
||||
}
|
||||
groupTag = "auto";
|
||||
|
||||
return exceptionHandler(
|
||||
() => singbox.urlTest(groupTag).mapLeft(ProxyUnexpectedFailure.new).run(),
|
||||
ProxyUnexpectedFailure.new,
|
||||
);
|
||||
}
|
||||
|
||||
final Map<String, IpInfo Function(Map<String, dynamic> response)>
|
||||
_ipInfoSources = {
|
||||
static final Map<String, IpInfo Function(Map<String, dynamic> response)> _ipInfoSources = {
|
||||
// "https://geolocation-db.com/json/": IpInfo.fromGeolocationDbComJson, //bug response is not json
|
||||
"https://ipwho.is/": IpInfo.fromIpwhoIsJson,
|
||||
"https://api.ip.sb/geoip/": IpInfo.fromIpSbJson,
|
||||
@@ -144,6 +140,7 @@ class ProxyRepositoryImpl
|
||||
final response = await client.get<Map<String, dynamic>>(
|
||||
source.key,
|
||||
cancelToken: cancelToken,
|
||||
proxyOnly: true,
|
||||
);
|
||||
if (response.statusCode == 200 && response.data != null) {
|
||||
return source.value(response.data!);
|
||||
|
||||
2
libcore
2
libcore
Submodule libcore updated: 5098951147...e9a3396024
Reference in New Issue
Block a user