From 68dd01c4a0f5facaac6dde436736a26b7e921a8d Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sat, 29 Jul 2023 22:55:58 +0200 Subject: [PATCH] refactor(neon): Await active account --- packages/neon/neon/lib/src/app.dart | 2 +- packages/neon/neon/lib/src/blocs/accounts.dart | 8 ++++---- packages/neon/neon/lib/src/pages/account_settings.dart | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/neon/neon/lib/src/app.dart b/packages/neon/neon/lib/src/app.dart index ab6224ed..4a9ce8d4 100644 --- a/packages/neon/neon/lib/src/app.dart +++ b/packages/neon/neon/lib/src/app.dart @@ -227,7 +227,7 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra } final matches = _appRegex.allMatches(shortcutType); - final activeAccount = _accountsBloc.activeAccount.valueOrNull; + final activeAccount = await _accountsBloc.activeAccount.first; if (matches.isNotEmpty && activeAccount != null) { await _openAppFromExternal(activeAccount, matches.first.group(1)!); } diff --git a/packages/neon/neon/lib/src/blocs/accounts.dart b/packages/neon/neon/lib/src/blocs/accounts.dart index 407f9426..d79fae77 100644 --- a/packages/neon/neon/lib/src/blocs/accounts.dart +++ b/packages/neon/neon/lib/src/blocs/accounts.dart @@ -130,7 +130,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState BehaviorSubject> accounts = BehaviorSubject>.seeded([]); @override - BehaviorSubject activeAccount = BehaviorSubject.seeded(null) + BehaviorSubject activeAccount = BehaviorSubject() ..distinct((final current, final next) => current?.id != next?.id); @override @@ -191,10 +191,10 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState /// The currently active account. /// - /// Equivalent to activeAccount.value but throws a [StateError] when no user is logged in. + /// Equivalent to activeAccount.valueOrNull but throws a [StateError] when no user is logged in. @visibleForTesting Account get aa { - final aa = activeAccount.value; + final aa = activeAccount.valueOrNull; if (aa == null) { throw StateError('No user is logged in.'); @@ -204,7 +204,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState } /// Whether accounts are logged in. - bool get hasAccounts => activeAccount.value != null; + bool get hasAccounts => activeAccount.valueOrNull != null; /// The options for the [activeAccount]. /// diff --git a/packages/neon/neon/lib/src/pages/account_settings.dart b/packages/neon/neon/lib/src/pages/account_settings.dart index 618af5f4..21e752c4 100644 --- a/packages/neon/neon/lib/src/pages/account_settings.dart +++ b/packages/neon/neon/lib/src/pages/account_settings.dart @@ -41,7 +41,7 @@ class AccountSettingsPage extends StatelessWidget { context, AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID), )) { - final isActive = bloc.activeAccount.value == account; + final isActive = bloc.activeAccount.valueOrNull == account; bloc.removeAccount(account);