From b9461e50191f3f96b77b0ce752a397554716775d Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 12 May 2024 22:29:38 +0800 Subject: [PATCH] :lipstick: Optimize connection experience --- lib/providers/chat.dart | 2 ++ lib/providers/notify.dart | 2 ++ lib/widgets/provider_init.dart | 29 +++++++++++++++++------------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/providers/chat.dart b/lib/providers/chat.dart index 1db0b21..3aad8dd 100644 --- a/lib/providers/chat.dart +++ b/lib/providers/chat.dart @@ -55,6 +55,8 @@ class ChatProvider extends ChangeNotifier { if (!noRetry) { await auth.client!.refreshToken(auth.client!.currentRefreshToken!); connect(auth, noRetry: true); + } else { + rethrow; } } diff --git a/lib/providers/notify.dart b/lib/providers/notify.dart index cf5404b..e8d3b21 100644 --- a/lib/providers/notify.dart +++ b/lib/providers/notify.dart @@ -95,6 +95,8 @@ class NotifyProvider extends ChangeNotifier { if (!noRetry) { await auth.client!.refreshToken(auth.client!.currentRefreshToken!); connect(auth, noRetry: true); + } else { + rethrow; } } diff --git a/lib/widgets/provider_init.dart b/lib/widgets/provider_init.dart index e490a2d..1b6560f 100644 --- a/lib/widgets/provider_init.dart +++ b/lib/widgets/provider_init.dart @@ -5,6 +5,7 @@ import 'package:solian/providers/chat.dart'; import 'package:solian/providers/keypair.dart'; import 'package:solian/providers/notify.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:solian/widgets/exts.dart'; class ProviderInitializer extends StatefulWidget { final Widget child; @@ -29,18 +30,22 @@ class _ProviderInitializerState extends State { ), ); - if (await auth.isAuthorized()) { - if (auth.client == null) { - await auth.loadClient(); - } + try { + if (await auth.isAuthorized()) { + if (auth.client == null) { + await auth.loadClient(); + } - nty.fetch(auth); - chat.connect(auth); - keypair.channel = await nty.connect( - auth, - onKexRequest: keypair.provideKeypair, - onKexProvide: keypair.receiveKeypair, - ); + nty.fetch(auth); + chat.connect(auth); + keypair.channel = await nty.connect( + auth, + onKexRequest: keypair.provideKeypair, + onKexProvide: keypair.receiveKeypair, + ); + } + } catch (e) { + context.showErrorDialog(e); } notify.close(); @@ -56,4 +61,4 @@ class _ProviderInitializerState extends State { Widget build(BuildContext context) { return widget.child; } -} \ No newline at end of file +}