Browse Source

refactor(neon): Await active account

pull/508/head
jld3103 1 year ago
parent
commit
68dd01c4a0
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 2
      packages/neon/neon/lib/src/app.dart
  2. 8
      packages/neon/neon/lib/src/blocs/accounts.dart
  3. 2
      packages/neon/neon/lib/src/pages/account_settings.dart

2
packages/neon/neon/lib/src/app.dart

@ -227,7 +227,7 @@ class _NeonAppState extends State<NeonApp> with WidgetsBindingObserver, tray.Tra
} }
final matches = _appRegex.allMatches(shortcutType); final matches = _appRegex.allMatches(shortcutType);
final activeAccount = _accountsBloc.activeAccount.valueOrNull; final activeAccount = await _accountsBloc.activeAccount.first;
if (matches.isNotEmpty && activeAccount != null) { if (matches.isNotEmpty && activeAccount != null) {
await _openAppFromExternal(activeAccount, matches.first.group(1)!); await _openAppFromExternal(activeAccount, matches.first.group(1)!);
} }

8
packages/neon/neon/lib/src/blocs/accounts.dart

@ -130,7 +130,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
BehaviorSubject<List<Account>> accounts = BehaviorSubject<List<Account>>.seeded([]); BehaviorSubject<List<Account>> accounts = BehaviorSubject<List<Account>>.seeded([]);
@override @override
BehaviorSubject<Account?> activeAccount = BehaviorSubject<Account?>.seeded(null) BehaviorSubject<Account?> activeAccount = BehaviorSubject<Account?>()
..distinct((final current, final next) => current?.id != next?.id); ..distinct((final current, final next) => current?.id != next?.id);
@override @override
@ -191,10 +191,10 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
/// The currently active account. /// 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 @visibleForTesting
Account get aa { Account get aa {
final aa = activeAccount.value; final aa = activeAccount.valueOrNull;
if (aa == null) { if (aa == null) {
throw StateError('No user is logged in.'); throw StateError('No user is logged in.');
@ -204,7 +204,7 @@ class AccountsBloc extends Bloc implements AccountsBlocEvents, AccountsBlocState
} }
/// Whether accounts are logged in. /// Whether accounts are logged in.
bool get hasAccounts => activeAccount.value != null; bool get hasAccounts => activeAccount.valueOrNull != null;
/// The options for the [activeAccount]. /// The options for the [activeAccount].
/// ///

2
packages/neon/neon/lib/src/pages/account_settings.dart

@ -41,7 +41,7 @@ class AccountSettingsPage extends StatelessWidget {
context, context,
AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID), AppLocalizations.of(context).accountOptionsRemoveConfirm(account.client.humanReadableID),
)) { )) {
final isActive = bloc.activeAccount.value == account; final isActive = bloc.activeAccount.valueOrNull == account;
bloc.removeAccount(account); bloc.removeAccount(account);

Loading…
Cancel
Save