diff --git a/lib/controllers/client.dart b/lib/controllers/client.dart index c855d0d..90f8896 100644 --- a/lib/controllers/client.dart +++ b/lib/controllers/client.dart @@ -15,7 +15,6 @@ import "package:nexus/controllers/rooms.dart"; import "package:nexus/controllers/space_edges.dart"; import "package:nexus/controllers/sync_status.dart"; import "package:nexus/controllers/top_level_spaces.dart"; -import "package:nexus/controllers/unified_push.dart"; import "package:nexus/helpers/extensions/gomuks_buffer.dart"; import "package:nexus/main.dart"; import "package:nexus/models/capabilities.dart"; @@ -345,10 +344,7 @@ class ClientController extends AsyncNotifier { Future downloadMedia(DownloadMediaRequest request) async => .new((await _sendCommand("download_media", request.toJson()))["path"]); - Future logout() async { - await ref.watch(UnifiedPushController.provider.notifier).deregister(); - await _sendCommand("logout"); - } + Future logout() => _sendCommand("logout"); Future markRead(Room room) async { final eventRowId = room.timeline[room.timeline.keys.reduce(max)]; diff --git a/lib/controllers/settings_sections.dart b/lib/controllers/settings_sections.dart index 7f25cb9..7fc1b3f 100644 --- a/lib/controllers/settings_sections.dart +++ b/lib/controllers/settings_sections.dart @@ -252,16 +252,14 @@ class SettingsSectionsController final colorScheme = Theme.of(context).colorScheme; return M3EButton.icon( onPressed: () async { - Navigator.of(context) - .popUntil((route) => route.isFirst); - Navigator.of(context) - .popUntil((route) => route.isFirst); - - await WidgetsBinding.instance.endOfFrame; - + await ref + .watch(UnifiedPushController.provider.notifier) + .deregister() + .onError(showError); await ref .watch(ClientController.provider.notifier) - .logout(); + .logout() + .onError(showError); }, label: Text(title), icon: Icon(icon), diff --git a/lib/controllers/unified_push.dart b/lib/controllers/unified_push.dart index 59ef5d4..181a3d6 100644 --- a/lib/controllers/unified_push.dart +++ b/lib/controllers/unified_push.dart @@ -132,9 +132,8 @@ class UnifiedPushController extends AsyncNotifier { ); } - if (!alreadyRegistered && - !await UnifiedPush.tryUseCurrentOrDefaultDistributor()) { - throw Exception("No UnifiedPush distributors found"); + if (!await UnifiedPush.tryUseCurrentOrDefaultDistributor()) { + throw Exception("No UnifiedPush distributors found."); } await UnifiedPush.register( diff --git a/lib/pages/select_server.dart b/lib/pages/select_server.dart index 85c84cb..a903cf6 100644 --- a/lib/pages/select_server.dart +++ b/lib/pages/select_server.dart @@ -78,9 +78,11 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget { ClientIdController.provider(url).future, ), ), - ) - .onError(showError); + ); } + } catch (error, stackTrace) { + showError(error, stackTrace); + rethrow; } finally { isLoading.value = false; } @@ -95,7 +97,7 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget { style: .new(color: theme.colorScheme.onErrorContainer), ), action: SnackBarAction( - onPressed: () => tryLogin(newHomeserver!), + onPressed: () => tryLogin(newHomeserver!).onError(showError), label: "Attempt log in anyways", textColor: theme.colorScheme.onErrorContainer, ), @@ -103,11 +105,12 @@ class const SelectServerPage({super.key}) extends HookConsumerWidget { ), ); } else { - tryLogin(newUrl); + await tryLogin(newUrl); } } } catch (error, stackTrace) { showError(error, stackTrace); + rethrow; } finally { isLoading.value = false; }