diff --git a/lib/features/proxy/active/active_proxy_notifier.dart b/lib/features/proxy/active/active_proxy_notifier.dart index 0fd5fc57..3fa1e635 100644 --- a/lib/features/proxy/active/active_proxy_notifier.dart +++ b/lib/features/proxy/active/active_proxy_notifier.dart @@ -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(); diff --git a/lib/features/proxy/data/proxy_repository.dart b/lib/features/proxy/data/proxy_repository.dart index 54cc0703..41f049d7 100644 --- a/lib/features/proxy/data/proxy_repository.dart +++ b/lib/features/proxy/data/proxy_repository.dart @@ -19,9 +19,7 @@ abstract interface class ProxyRepository { TaskEither 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 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 response)> - _ipInfoSources = { + static final Map 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>( source.key, cancelToken: cancelToken, + proxyOnly: true, ); if (response.statusCode == 200 && response.data != null) { return source.value(response.data!); diff --git a/libcore b/libcore index 50989511..e9a33960 160000 --- a/libcore +++ b/libcore @@ -1 +1 @@ -Subproject commit 5098951147c4208d79c57dbbc059b5b4a8e67624 +Subproject commit e9a3396024cd34c559fa8dd0c15094a3c1fae31b