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": {
"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"
},

View File

@@ -37,7 +37,6 @@
"overviewPageTitle": "پروفایل‌ها",
"detailsPageTitle": "پروفایل",
"activeProfileNameSemanticLabel": "نام پروفایل فعال: ${name}",
"nonActiveProfileNameSemanticLabel": "نام پروفایل: ${name}",
"activeProfileBtnSemanticLabel": "همه‌ی پروفایل‌ها",
"nonActiveProfileBtnSemanticLabel": "انتخاب ${name} به عنوان پروفایل فعال",
"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/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<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,
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: () =>