Improve error handling and presentation

This commit is contained in:
problematicconsumer
2023-10-02 23:57:20 +03:30
parent e1108dc1a7
commit 81658a1c86
6 changed files with 58 additions and 29 deletions

View File

@@ -1,3 +1,4 @@
import 'package:dartx/dartx.dart';
import 'package:hiddify/core/prefs/general_prefs.dart';
import 'package:hiddify/features/common/app_update_notifier.dart';
import 'package:hiddify/features/common/connectivity/connectivity_controller.dart';
@@ -19,7 +20,8 @@ void commonControllers(CommonControllersRef ref) {
introCompletedProvider,
(_, completed) async {
if (completed) {
await ref.read(cronServiceProvider).startScheduler();
await Future.delayed(5.seconds)
.then((_) async => ref.read(cronServiceProvider).startScheduler());
}
},
fireImmediately: true,

View File

@@ -176,7 +176,9 @@ class ProfileActionButton extends HookConsumerWidget {
final updateProfileMutation = useMutation(
initialOnFailure: (err) {
CustomAlertDialog.fromErr(t.presentError(err)).show(context);
CustomAlertDialog.fromErr(
t.presentError(err, action: t.profile.update.failureMsg),
).show(context);
},
initialOnSuccess: () =>
CustomToast.success(t.profile.update.successMsg).show(context),
@@ -241,7 +243,9 @@ class ProfileActionsMenu extends HookConsumerWidget {
final updateProfileMutation = useMutation(
initialOnFailure: (err) {
CustomAlertDialog.fromErr(t.presentError(err)).show(context);
CustomAlertDialog.fromErr(
t.presentError(err, action: t.profile.update.failureMsg),
).show(context);
},
initialOnSuccess: () =>
CustomToast.success(t.profile.update.successMsg).show(context),

View File

@@ -1,9 +1,5 @@
import 'package:flutter/material.dart';
import 'package:fpdart/fpdart.dart';
import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/core/router/router.dart';
import 'package:hiddify/data/data_providers.dart';
import 'package:hiddify/domain/failures.dart';
import 'package:hiddify/domain/profiles/profiles.dart';
import 'package:hiddify/services/service_providers.dart';
import 'package:hiddify/utils/utils.dart';
@@ -20,22 +16,6 @@ typedef ProfileUpdateResult = ({
class ProfilesUpdateNotifier extends _$ProfilesUpdateNotifier with AppLogger {
@override
Stream<ProfileUpdateResult> build() {
ref.listenSelf(
(previous, next) {
if (next case AsyncData(value: final result)) {
final t = ref.read(translationsProvider);
final context = rootNavigatorKey.currentContext;
if (context == null || !context.mounted) return;
SnackBar(content: Text(t.profile.update.successMsg));
switch (result.failureOrSuccess) {
case Right():
CustomToast.success(t.profile.update.successMsg).show(context);
case Left(value: final err):
CustomToast.error(t.printError(err)).show(context);
}
}
},
);
_schedule();
return const Stream.empty();
}