Fix minor bugs

This commit is contained in:
problematicconsumer
2023-09-30 11:15:32 +03:30
parent eb4db44c06
commit 06c23784ed
4 changed files with 60 additions and 23 deletions

View File

@@ -36,15 +36,14 @@
"profile": { "profile": {
"overviewPageTitle": "Profiles", "overviewPageTitle": "Profiles",
"detailsPageTitle": "Profile", "detailsPageTitle": "Profile",
"activeProfileNameSemanticLabel": "Active profile name: ${name}", "activeProfileNameSemanticLabel": "Active profile name: \"${name}\".",
"nonActiveProfileNameSemanticLabel": "Profile name: ${name}", "activeProfileBtnSemanticLabel": "View all profiles.",
"activeProfileBtnSemanticLabel": "View all profiles", "nonActiveProfileBtnSemanticLabel": "Select \"${name}\" as active profile.",
"nonActiveProfileBtnSemanticLabel": "Select ${name} as active",
"subscription": { "subscription": {
"traffic": "Traffic", "traffic": "Traffic",
"updatedTimeAgo": "Updated ${timeago}", "updatedTimeAgo": "Updated ${timeago}",
"remainingDuration": "${duration} Days Remaining", "remainingDuration": "${duration} Days Remaining",
"remainingTrafficSemanticLabel": "${consumed} of ${total} traffic consumed", "remainingTrafficSemanticLabel": "${consumed} of ${total} traffic consumed.",
"expired": "Expired", "expired": "Expired",
"noTraffic": "No more traffic" "noTraffic": "No more traffic"
}, },

View File

@@ -37,7 +37,6 @@
"overviewPageTitle": "پروفایل‌ها", "overviewPageTitle": "پروفایل‌ها",
"detailsPageTitle": "پروفایل", "detailsPageTitle": "پروفایل",
"activeProfileNameSemanticLabel": "نام پروفایل فعال: ${name}", "activeProfileNameSemanticLabel": "نام پروفایل فعال: ${name}",
"nonActiveProfileNameSemanticLabel": "نام پروفایل: ${name}",
"activeProfileBtnSemanticLabel": "همه‌ی پروفایل‌ها", "activeProfileBtnSemanticLabel": "همه‌ی پروفایل‌ها",
"nonActiveProfileBtnSemanticLabel": "انتخاب ${name} به عنوان پروفایل فعال", "nonActiveProfileBtnSemanticLabel": "انتخاب ${name} به عنوان پروفایل فعال",
"subscription": { "subscription": {

View File

@@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart';
import 'package:hiddify/core/prefs/prefs.dart'; import 'package:hiddify/core/prefs/prefs.dart';
import 'package:hiddify/core/router/routes/routes.dart'; import 'package:hiddify/core/router/routes/routes.dart';
import 'package:hiddify/services/deep_link_service.dart'; import 'package:hiddify/services/deep_link_service.dart';
import 'package:hiddify/utils/utils.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';
@@ -11,7 +12,7 @@ part 'app_router.g.dart';
// TODO: test and improve handling of deep link // TODO: test and improve handling of deep link
@riverpod @riverpod
GoRouter router(RouterRef ref) { GoRouter router(RouterRef ref) {
final introCompleted = ref.watch(introCompletedProvider); final notifier = ref.watch(routerListenableProvider.notifier);
final deepLink = ref.listen( final deepLink = ref.listen(
deepLinkServiceProvider, deepLinkServiceProvider,
(_, next) async { (_, next) async {
@@ -31,15 +32,11 @@ GoRouter router(RouterRef ref) {
initialLocation: initialLocation, initialLocation: initialLocation,
debugLogDiagnostics: true, debugLogDiagnostics: true,
routes: $routes, routes: $routes,
refreshListenable: notifier,
redirect: notifier.redirect,
observers: [ observers: [
SentryNavigatorObserver(), 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); const AboutRoute().go(context);
} }
} }
@riverpod
class RouterListenable extends _$RouterListenable
with AppLogger
implements Listenable {
VoidCallback? _routerListener;
bool _introCompleted = false;
@override
Future<void> 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;
}
}

View File

@@ -71,17 +71,14 @@ class ProfileTile extends HookConsumerWidget {
width: 1, width: 1,
color: effectiveOutlineColor, color: effectiveOutlineColor,
), ),
Flexible( Expanded(
child: Semantics( child: Semantics(
button: true, button: true,
sortKey: isMain ? const OrdinalSortKey(0) : null, sortKey: isMain ? const OrdinalSortKey(0) : null,
focused: isMain, focused: isMain,
liveRegion: isMain, liveRegion: isMain,
namesRoute: isMain, namesRoute: isMain,
label: isMain label: isMain ? t.profile.activeProfileBtnSemanticLabel : null,
? t.profile.activeProfileBtnSemanticLabel
: t.profile
.nonActiveProfileBtnSemanticLabel(name: profile.name),
child: InkWell( child: InkWell(
onTap: () { onTap: () {
if (isMain) { if (isMain) {
@@ -133,10 +130,13 @@ class ProfileTile extends HookConsumerWidget {
else else
Text( Text(
profile.name, profile.name,
semanticsLabel: semanticsLabel: profile.active
t.profile.nonActiveProfileNameSemanticLabel( ? t.profile.activeProfileNameSemanticLabel(
name: profile.name, name: profile.name,
), )
: t.profile.nonActiveProfileBtnSemanticLabel(
name: profile.name,
),
style: theme.textTheme.titleMedium, style: theme.textTheme.titleMedium,
), ),
if (subInfo != null) ...[ if (subInfo != null) ...[
@@ -171,7 +171,6 @@ class ProfileActionButton extends HookConsumerWidget {
final updateProfileMutation = useMutation( final updateProfileMutation = useMutation(
initialOnFailure: (err) { initialOnFailure: (err) {
// CustomToast.error(t.printError(err)).show(context);
CustomAlertDialog.fromErr(t.presentError(err)).show(context); CustomAlertDialog.fromErr(t.presentError(err)).show(context);
}, },
initialOnSuccess: () => initialOnSuccess: () =>