From 06c23784ed8b2152b884d5e5c6ba2c1287c919ff Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Sat, 30 Sep 2023 11:15:32 +0330 Subject: [PATCH] Fix minor bugs --- assets/translations/strings.i18n.json | 9 ++-- assets/translations/strings_fa.i18n.json | 1 - lib/core/router/app_router.dart | 54 +++++++++++++++++++++--- lib/features/common/profile_tile.dart | 19 ++++----- 4 files changed, 60 insertions(+), 23 deletions(-) diff --git a/assets/translations/strings.i18n.json b/assets/translations/strings.i18n.json index 2456c252..b3972266 100644 --- a/assets/translations/strings.i18n.json +++ b/assets/translations/strings.i18n.json @@ -36,15 +36,14 @@ "profile": { "overviewPageTitle": "Profiles", "detailsPageTitle": "Profile", - "activeProfileNameSemanticLabel": "Active profile name: ${name}", - "nonActiveProfileNameSemanticLabel": "Profile name: ${name}", - "activeProfileBtnSemanticLabel": "View all profiles", - "nonActiveProfileBtnSemanticLabel": "Select ${name} as active", + "activeProfileNameSemanticLabel": "Active profile name: \"${name}\".", + "activeProfileBtnSemanticLabel": "View all profiles.", + "nonActiveProfileBtnSemanticLabel": "Select \"${name}\" as active profile.", "subscription": { "traffic": "Traffic", "updatedTimeAgo": "Updated ${timeago}", "remainingDuration": "${duration} Days Remaining", - "remainingTrafficSemanticLabel": "${consumed} of ${total} traffic consumed", + "remainingTrafficSemanticLabel": "${consumed} of ${total} traffic consumed.", "expired": "Expired", "noTraffic": "No more traffic" }, diff --git a/assets/translations/strings_fa.i18n.json b/assets/translations/strings_fa.i18n.json index 77ddea39..9926f296 100644 --- a/assets/translations/strings_fa.i18n.json +++ b/assets/translations/strings_fa.i18n.json @@ -37,7 +37,6 @@ "overviewPageTitle": "پروفایل‌ها", "detailsPageTitle": "پروفایل", "activeProfileNameSemanticLabel": "نام پروفایل فعال: ${name}", - "nonActiveProfileNameSemanticLabel": "نام پروفایل: ${name}", "activeProfileBtnSemanticLabel": "همه‌ی پروفایل‌ها", "nonActiveProfileBtnSemanticLabel": "انتخاب ${name} به عنوان پروفایل فعال", "subscription": { diff --git a/lib/core/router/app_router.dart b/lib/core/router/app_router.dart index f8bd47bd..f53e4ec5 100644 --- a/lib/core/router/app_router.dart +++ b/lib/core/router/app_router.dart @@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart'; import 'package:hiddify/core/prefs/prefs.dart'; import 'package:hiddify/core/router/routes/routes.dart'; import 'package:hiddify/services/deep_link_service.dart'; +import 'package:hiddify/utils/utils.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; @@ -11,7 +12,7 @@ part 'app_router.g.dart'; // TODO: test and improve handling of deep link @riverpod GoRouter router(RouterRef ref) { - final introCompleted = ref.watch(introCompletedProvider); + final notifier = ref.watch(routerListenableProvider.notifier); final deepLink = ref.listen( deepLinkServiceProvider, (_, next) async { @@ -31,15 +32,11 @@ GoRouter router(RouterRef ref) { initialLocation: initialLocation, debugLogDiagnostics: true, routes: $routes, + refreshListenable: notifier, + redirect: notifier.redirect, observers: [ SentryNavigatorObserver(), ], - redirect: (context, state) { - if (!introCompleted && state.uri.path != const IntroRoute().location) { - return const IntroRoute().location; - } - return null; - }, ); } @@ -67,3 +64,46 @@ void switchTab(int index, BuildContext context) { const AboutRoute().go(context); } } + +@riverpod +class RouterListenable extends _$RouterListenable + with AppLogger + implements Listenable { + VoidCallback? _routerListener; + bool _introCompleted = false; + + @override + Future build() async { + _introCompleted = ref.watch(introCompletedProvider); + + ref.listenSelf((_, __) { + if (state.isLoading) return; + loggy.debug("triggering listener"); + _routerListener?.call(); + }); + } + + String? redirect(BuildContext context, GoRouterState state) { + // if (this.state.isLoading || this.state.hasError) return null; + + final isIntro = state.uri.path == const IntroRoute().location; + + if (!_introCompleted) { + return const IntroRoute().location; + } else if (isIntro) { + return const HomeRoute().location; + } + + return null; + } + + @override + void addListener(VoidCallback listener) { + _routerListener = listener; + } + + @override + void removeListener(VoidCallback listener) { + _routerListener = null; + } +} diff --git a/lib/features/common/profile_tile.dart b/lib/features/common/profile_tile.dart index a42ac8c0..f3db3077 100644 --- a/lib/features/common/profile_tile.dart +++ b/lib/features/common/profile_tile.dart @@ -71,17 +71,14 @@ class ProfileTile extends HookConsumerWidget { width: 1, color: effectiveOutlineColor, ), - Flexible( + Expanded( child: Semantics( button: true, sortKey: isMain ? const OrdinalSortKey(0) : null, focused: isMain, liveRegion: isMain, namesRoute: isMain, - label: isMain - ? t.profile.activeProfileBtnSemanticLabel - : t.profile - .nonActiveProfileBtnSemanticLabel(name: profile.name), + label: isMain ? t.profile.activeProfileBtnSemanticLabel : null, child: InkWell( onTap: () { if (isMain) { @@ -133,10 +130,13 @@ class ProfileTile extends HookConsumerWidget { else Text( profile.name, - semanticsLabel: - t.profile.nonActiveProfileNameSemanticLabel( - name: profile.name, - ), + semanticsLabel: profile.active + ? t.profile.activeProfileNameSemanticLabel( + name: profile.name, + ) + : t.profile.nonActiveProfileBtnSemanticLabel( + name: profile.name, + ), style: theme.textTheme.titleMedium, ), if (subInfo != null) ...[ @@ -171,7 +171,6 @@ class ProfileActionButton extends HookConsumerWidget { final updateProfileMutation = useMutation( initialOnFailure: (err) { - // CustomToast.error(t.printError(err)).show(context); CustomAlertDialog.fromErr(t.presentError(err)).show(context); }, initialOnSuccess: () =>