From 39ae86a5380736f84c2ede1b84b15be3c5572df6 Mon Sep 17 00:00:00 2001 From: hiddify-com <114227601+hiddify-com@users.noreply.github.com> Date: Mon, 5 Aug 2024 02:07:07 +0200 Subject: [PATCH] fix: some bugs --- .../profile/add/add_profile_modal.dart | 2 +- lib/features/profile/widget/profile_tile.dart | 51 ++++++------------- .../proxy/active/active_proxy_notifier.dart | 4 +- lib/utils/sentry_utils.dart | 2 + 4 files changed, 20 insertions(+), 39 deletions(-) diff --git a/lib/features/profile/add/add_profile_modal.dart b/lib/features/profile/add/add_profile_modal.dart index 24a614e6..0e28f096 100644 --- a/lib/features/profile/add/add_profile_modal.dart +++ b/lib/features/profile/add/add_profile_modal.dart @@ -39,7 +39,7 @@ class AddProfileModal extends HookConsumerWidget { if (next case AsyncData(value: final _?)) { WidgetsBinding.instance.addPostFrameCallback( (_) { - if (context.mounted) context.pop(); + if (context.mounted && context.canPop()) context.pop(); }, ); } diff --git a/lib/features/profile/widget/profile_tile.dart b/lib/features/profile/widget/profile_tile.dart index 522a3a12..f5e671a3 100644 --- a/lib/features/profile/widget/profile_tile.dart +++ b/lib/features/profile/widget/profile_tile.dart @@ -41,7 +41,7 @@ class ProfileTile extends HookConsumerWidget { CustomToast.error(t.presentShortError(err)).show(context); }, initialOnSuccess: () { - if (context.mounted) context.pop(); + if (context.mounted && context.canPop()) context.pop(); }, ); @@ -50,12 +50,9 @@ class ProfileTile extends HookConsumerWidget { _ => null, }; - final effectiveMargin = isMain - ? const EdgeInsets.symmetric(horizontal: 16, vertical: 8) - : const EdgeInsets.only(left: 12, right: 12, bottom: 12); + final effectiveMargin = isMain ? const EdgeInsets.symmetric(horizontal: 16, vertical: 8) : const EdgeInsets.only(left: 12, right: 12, bottom: 12); final double effectiveElevation = profile.active ? 12 : 4; - final effectiveOutlineColor = - profile.active ? theme.colorScheme.outlineVariant : Colors.transparent; + final effectiveOutlineColor = profile.active ? theme.colorScheme.outlineVariant : Colors.transparent; return Card( margin: effectiveMargin, @@ -98,9 +95,7 @@ class ProfileTile extends HookConsumerWidget { if (selectActiveMutation.state.isInProgress) return; if (profile.active) return; selectActiveMutation.setFuture( - ref - .read(profilesOverviewNotifierProvider.notifier) - .selectActiveProfile(profile.id), + ref.read(profilesOverviewNotifierProvider.notifier).selectActiveProfile(profile.id), ); } }, @@ -120,20 +115,17 @@ class ProfileTile extends HookConsumerWidget { color: Colors.transparent, clipBehavior: Clip.antiAlias, child: Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible( child: Text( profile.name, maxLines: 2, overflow: TextOverflow.ellipsis, - style: - theme.textTheme.titleMedium?.copyWith( + style: theme.textTheme.titleMedium?.copyWith( fontFamily: FontFamily.emoji, ), - semanticsLabel: t.profile - .activeProfileNameSemanticLabel( + semanticsLabel: t.profile.activeProfileNameSemanticLabel( name: profile.name, ), ), @@ -201,9 +193,7 @@ class ProfileActionButton extends HookConsumerWidget { if (ref.read(updateProfileProvider(profile.id)).isLoading) { return; } - ref - .read(updateProfileProvider(profile.id).notifier) - .updateProfile(profile as RemoteProfileEntity); + ref.read(updateProfileProvider(profile.id).notifier).updateProfile(profile as RemoteProfileEntity); }, child: const Icon(FluentIcons.arrow_sync_24_filled), ), @@ -243,9 +233,7 @@ class ProfileActionsMenu extends HookConsumerWidget { initialOnFailure: (err) { CustomToast.error(t.presentShortError(err)).show(context); }, - initialOnSuccess: () => - CustomToast.success(t.profile.share.exportConfigToClipboardSuccess) - .show(context), + initialOnSuccess: () => CustomToast.success(t.profile.share.exportConfigToClipboardSuccess).show(context), ); final deleteProfileMutation = useMutation( initialOnFailure: (err) { @@ -262,9 +250,7 @@ class ProfileActionsMenu extends HookConsumerWidget { if (ref.read(updateProfileProvider(profile.id)).isLoading) { return; } - ref - .read(updateProfileProvider(profile.id).notifier) - .updateProfile(profile as RemoteProfileEntity); + ref.read(updateProfileProvider(profile.id).notifier).updateProfile(profile as RemoteProfileEntity); }, ), AdaptiveMenuItem( @@ -279,8 +265,7 @@ class ProfileActionsMenu extends HookConsumerWidget { if (link.isNotEmpty) { await Clipboard.setData(ClipboardData(text: link)); if (context.mounted) { - CustomToast(t.profile.share.exportToClipboardSuccess) - .show(context); + CustomToast(t.profile.share.exportToClipboardSuccess).show(context); } } }, @@ -305,9 +290,7 @@ class ProfileActionsMenu extends HookConsumerWidget { return; } exportConfigMutation.setFuture( - ref - .read(profilesOverviewNotifierProvider.notifier) - .exportConfigToClipboard(profile), + ref.read(profilesOverviewNotifierProvider.notifier).exportConfigToClipboard(profile), ); }, ), @@ -335,9 +318,7 @@ class ProfileActionsMenu extends HookConsumerWidget { ); if (deleteConfirmed) { deleteProfileMutation.setFuture( - ref - .read(profilesOverviewNotifierProvider.notifier) - .deleteProfile(profile), + ref.read(profilesOverviewNotifierProvider.notifier).deleteProfile(profile), ); } }, @@ -367,8 +348,7 @@ class ProfileSubscriptionInfo extends HookConsumerWidget { return (t.profile.subscription.remainingDuration(duration: "∞"), null); } else { return ( - t.profile.subscription - .remainingDuration(duration: subInfo.remaining.inDays), + t.profile.subscription.remainingDuration(duration: subInfo.remaining.inDays), null, ); } @@ -390,8 +370,7 @@ class ProfileSubscriptionInfo extends HookConsumerWidget { subInfo.total > 10 * 1099511627776 //10TB ? "∞ GiB" : subInfo.consumption.sizeOf(subInfo.total), - semanticsLabel: - t.profile.subscription.remainingTrafficSemanticLabel( + semanticsLabel: t.profile.subscription.remainingTrafficSemanticLabel( consumed: subInfo.consumption.sizeGB(), total: subInfo.total.sizeGB(), ), diff --git a/lib/features/proxy/active/active_proxy_notifier.dart b/lib/features/proxy/active/active_proxy_notifier.dart index 06536c40..75d4c138 100644 --- a/lib/features/proxy/active/active_proxy_notifier.dart +++ b/lib/features/proxy/active/active_proxy_notifier.dart @@ -48,8 +48,8 @@ class IpInfoNotifier extends _$IpInfoNotifier with AppLogger { 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(); diff --git a/lib/utils/sentry_utils.dart b/lib/utils/sentry_utils.dart index a8976a50..c560699e 100644 --- a/lib/utils/sentry_utils.dart +++ b/lib/utils/sentry_utils.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:hiddify/core/model/failures.dart'; +import 'package:hiddify/features/proxy/model/proxy_failure.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; @@ -15,6 +16,7 @@ bool canSendEvent(dynamic throwable) { UnexpectedFailure(:final error) => canSendEvent(error), DioException _ => false, SocketException _ => false, + UnknownIp _ => false, HttpException _ => false, HandshakeException _ => false, ExpectedFailure _ => false,