fix: some bugs

This commit is contained in:
hiddify-com
2024-08-05 02:07:07 +02:00
parent 12290dc4e3
commit 39ae86a538
4 changed files with 20 additions and 39 deletions

View File

@@ -39,7 +39,7 @@ class AddProfileModal extends HookConsumerWidget {
if (next case AsyncData(value: final _?)) { if (next case AsyncData(value: final _?)) {
WidgetsBinding.instance.addPostFrameCallback( WidgetsBinding.instance.addPostFrameCallback(
(_) { (_) {
if (context.mounted) context.pop(); if (context.mounted && context.canPop()) context.pop();
}, },
); );
} }

View File

@@ -41,7 +41,7 @@ class ProfileTile extends HookConsumerWidget {
CustomToast.error(t.presentShortError(err)).show(context); CustomToast.error(t.presentShortError(err)).show(context);
}, },
initialOnSuccess: () { initialOnSuccess: () {
if (context.mounted) context.pop(); if (context.mounted && context.canPop()) context.pop();
}, },
); );
@@ -50,12 +50,9 @@ class ProfileTile extends HookConsumerWidget {
_ => null, _ => null,
}; };
final effectiveMargin = isMain final effectiveMargin = isMain ? const EdgeInsets.symmetric(horizontal: 16, vertical: 8) : const EdgeInsets.only(left: 12, right: 12, bottom: 12);
? const EdgeInsets.symmetric(horizontal: 16, vertical: 8)
: const EdgeInsets.only(left: 12, right: 12, bottom: 12);
final double effectiveElevation = profile.active ? 12 : 4; final double effectiveElevation = profile.active ? 12 : 4;
final effectiveOutlineColor = final effectiveOutlineColor = profile.active ? theme.colorScheme.outlineVariant : Colors.transparent;
profile.active ? theme.colorScheme.outlineVariant : Colors.transparent;
return Card( return Card(
margin: effectiveMargin, margin: effectiveMargin,
@@ -98,9 +95,7 @@ class ProfileTile extends HookConsumerWidget {
if (selectActiveMutation.state.isInProgress) return; if (selectActiveMutation.state.isInProgress) return;
if (profile.active) return; if (profile.active) return;
selectActiveMutation.setFuture( selectActiveMutation.setFuture(
ref ref.read(profilesOverviewNotifierProvider.notifier).selectActiveProfile(profile.id),
.read(profilesOverviewNotifierProvider.notifier)
.selectActiveProfile(profile.id),
); );
} }
}, },
@@ -120,20 +115,17 @@ class ProfileTile extends HookConsumerWidget {
color: Colors.transparent, color: Colors.transparent,
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
child: Row( child: Row(
mainAxisAlignment: mainAxisAlignment: MainAxisAlignment.spaceBetween,
MainAxisAlignment.spaceBetween,
children: [ children: [
Flexible( Flexible(
child: Text( child: Text(
profile.name, profile.name,
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: style: theme.textTheme.titleMedium?.copyWith(
theme.textTheme.titleMedium?.copyWith(
fontFamily: FontFamily.emoji, fontFamily: FontFamily.emoji,
), ),
semanticsLabel: t.profile semanticsLabel: t.profile.activeProfileNameSemanticLabel(
.activeProfileNameSemanticLabel(
name: profile.name, name: profile.name,
), ),
), ),
@@ -201,9 +193,7 @@ class ProfileActionButton extends HookConsumerWidget {
if (ref.read(updateProfileProvider(profile.id)).isLoading) { if (ref.read(updateProfileProvider(profile.id)).isLoading) {
return; return;
} }
ref ref.read(updateProfileProvider(profile.id).notifier).updateProfile(profile as RemoteProfileEntity);
.read(updateProfileProvider(profile.id).notifier)
.updateProfile(profile as RemoteProfileEntity);
}, },
child: const Icon(FluentIcons.arrow_sync_24_filled), child: const Icon(FluentIcons.arrow_sync_24_filled),
), ),
@@ -243,9 +233,7 @@ class ProfileActionsMenu extends HookConsumerWidget {
initialOnFailure: (err) { initialOnFailure: (err) {
CustomToast.error(t.presentShortError(err)).show(context); CustomToast.error(t.presentShortError(err)).show(context);
}, },
initialOnSuccess: () => initialOnSuccess: () => CustomToast.success(t.profile.share.exportConfigToClipboardSuccess).show(context),
CustomToast.success(t.profile.share.exportConfigToClipboardSuccess)
.show(context),
); );
final deleteProfileMutation = useMutation( final deleteProfileMutation = useMutation(
initialOnFailure: (err) { initialOnFailure: (err) {
@@ -262,9 +250,7 @@ class ProfileActionsMenu extends HookConsumerWidget {
if (ref.read(updateProfileProvider(profile.id)).isLoading) { if (ref.read(updateProfileProvider(profile.id)).isLoading) {
return; return;
} }
ref ref.read(updateProfileProvider(profile.id).notifier).updateProfile(profile as RemoteProfileEntity);
.read(updateProfileProvider(profile.id).notifier)
.updateProfile(profile as RemoteProfileEntity);
}, },
), ),
AdaptiveMenuItem( AdaptiveMenuItem(
@@ -279,8 +265,7 @@ class ProfileActionsMenu extends HookConsumerWidget {
if (link.isNotEmpty) { if (link.isNotEmpty) {
await Clipboard.setData(ClipboardData(text: link)); await Clipboard.setData(ClipboardData(text: link));
if (context.mounted) { if (context.mounted) {
CustomToast(t.profile.share.exportToClipboardSuccess) CustomToast(t.profile.share.exportToClipboardSuccess).show(context);
.show(context);
} }
} }
}, },
@@ -305,9 +290,7 @@ class ProfileActionsMenu extends HookConsumerWidget {
return; return;
} }
exportConfigMutation.setFuture( exportConfigMutation.setFuture(
ref ref.read(profilesOverviewNotifierProvider.notifier).exportConfigToClipboard(profile),
.read(profilesOverviewNotifierProvider.notifier)
.exportConfigToClipboard(profile),
); );
}, },
), ),
@@ -335,9 +318,7 @@ class ProfileActionsMenu extends HookConsumerWidget {
); );
if (deleteConfirmed) { if (deleteConfirmed) {
deleteProfileMutation.setFuture( deleteProfileMutation.setFuture(
ref ref.read(profilesOverviewNotifierProvider.notifier).deleteProfile(profile),
.read(profilesOverviewNotifierProvider.notifier)
.deleteProfile(profile),
); );
} }
}, },
@@ -367,8 +348,7 @@ class ProfileSubscriptionInfo extends HookConsumerWidget {
return (t.profile.subscription.remainingDuration(duration: ""), null); return (t.profile.subscription.remainingDuration(duration: ""), null);
} else { } else {
return ( return (
t.profile.subscription t.profile.subscription.remainingDuration(duration: subInfo.remaining.inDays),
.remainingDuration(duration: subInfo.remaining.inDays),
null, null,
); );
} }
@@ -390,8 +370,7 @@ class ProfileSubscriptionInfo extends HookConsumerWidget {
subInfo.total > 10 * 1099511627776 //10TB subInfo.total > 10 * 1099511627776 //10TB
? "∞ GiB" ? "∞ GiB"
: subInfo.consumption.sizeOf(subInfo.total), : subInfo.consumption.sizeOf(subInfo.total),
semanticsLabel: semanticsLabel: t.profile.subscription.remainingTrafficSemanticLabel(
t.profile.subscription.remainingTrafficSemanticLabel(
consumed: subInfo.consumption.sizeGB(), consumed: subInfo.consumption.sizeGB(),
total: subInfo.total.sizeGB(), total: subInfo.total.sizeGB(),
), ),

View File

@@ -48,8 +48,8 @@ class IpInfoNotifier extends _$IpInfoNotifier with AppLogger {
final info = await ref.watch(proxyRepositoryProvider).getCurrentIpInfo(cancelToken).getOrElse( final info = await ref.watch(proxyRepositoryProvider).getCurrentIpInfo(cancelToken).getOrElse(
(err) { (err) {
loggy.warning("error getting proxy ip info", err, StackTrace.current); loggy.warning("error getting proxy ip info", err, StackTrace.current);
throw err; //hiddify: remove exception to be logged // throw err; //hiddify: remove exception to be logged
//throw const UnknownIp(); throw const UnknownIp();
}, },
).run(); ).run();

View File

@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:hiddify/core/model/failures.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:riverpod_annotation/riverpod_annotation.dart';
import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/sentry_flutter.dart';
@@ -15,6 +16,7 @@ bool canSendEvent(dynamic throwable) {
UnexpectedFailure(:final error) => canSendEvent(error), UnexpectedFailure(:final error) => canSendEvent(error),
DioException _ => false, DioException _ => false,
SocketException _ => false, SocketException _ => false,
UnknownIp _ => false,
HttpException _ => false, HttpException _ => false,
HandshakeException _ => false, HandshakeException _ => false,
ExpectedFailure _ => false, ExpectedFailure _ => false,