From 4f00cee35dd807f60c490fac14fd1ef3ea8989d8 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Fri, 13 Jan 2023 13:20:46 +0100 Subject: [PATCH] neon: Fix opening app from shortcut --- packages/neon/lib/src/app.dart | 2 +- .../neon/lib/src/apps/notifications/pages/main.dart | 2 +- packages/neon/lib/src/blocs/apps.dart | 9 ++++++--- packages/neon/lib/src/pages/home.dart | 11 +++++++---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/neon/lib/src/app.dart b/packages/neon/lib/src/app.dart index 30726ee4..751e596c 100644 --- a/packages/neon/lib/src/app.dart +++ b/packages/neon/lib/src/app.dart @@ -255,7 +255,7 @@ class _NeonAppState extends State with WidgetsBindingObserver, tray.Tra } Future _openAppFromExternal(final Account account, final String id) async { - _accountsBloc.getAppsBloc(account).setActiveApp(id); + await _accountsBloc.getAppsBloc(account).setActiveApp(id); _navigatorKey.currentState!.popUntil((final route) => route.settings.name == 'home'); await _showAndRestoreWindow(); } diff --git a/packages/neon/lib/src/apps/notifications/pages/main.dart b/packages/neon/lib/src/apps/notifications/pages/main.dart index 72fda038..b63efa75 100644 --- a/packages/neon/lib/src/apps/notifications/pages/main.dart +++ b/packages/neon/lib/src/apps/notifications/pages/main.dart @@ -94,7 +94,7 @@ class _NotificationsMainPageState extends State { final matchingAppImplementations = allAppImplementations.where((final a) => a.id == notification.app); if (matchingAppImplementations.isNotEmpty) { final accountsBloc = Provider.of(context, listen: false); - accountsBloc.getAppsBloc(accountsBloc.activeAccount.value!).setActiveApp(notification.app); + await accountsBloc.getAppsBloc(accountsBloc.activeAccount.value!).setActiveApp(notification.app); } else { await showDialog( context: context, diff --git a/packages/neon/lib/src/blocs/apps.dart b/packages/neon/lib/src/blocs/apps.dart index 400b0a6f..c793172a 100644 --- a/packages/neon/lib/src/blocs/apps.dart +++ b/packages/neon/lib/src/blocs/apps.dart @@ -44,7 +44,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates } } if (!activeAppID.hasValue) { - setActiveApp(initialApp); + await setActiveApp(initialApp); } }), ); @@ -119,8 +119,11 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates } @override - void setActiveApp(final String? appID) { - if (appImplementations.value.data!.where((final app) => app.id == appID).isNotEmpty) { + Future setActiveApp(final String? appID) async { + if ((await appImplementations.firstWhere((final a) => a.data != null)) + .data! + .where((final app) => app.id == appID) + .isNotEmpty) { if (activeAppID.valueOrNull != appID) { activeAppID.add(appID); } diff --git a/packages/neon/lib/src/pages/home.dart b/packages/neon/lib/src/pages/home.dart index c05c8d93..35374ef3 100644 --- a/packages/neon/lib/src/pages/home.dart +++ b/packages/neon/lib/src/pages/home.dart @@ -321,8 +321,8 @@ class _HomePageState extends State { return Tooltip( message: appImplementation.name(context), child: IconButton( - onPressed: () { - _appsBloc.setActiveApp(appImplementation.id); + onPressed: () async { + await _appsBloc.setActiveApp(appImplementation.id); }, icon: AppImplementationIcon( appImplementation: appImplementation, @@ -352,10 +352,13 @@ class _HomePageState extends State { ), leading: appImplementation.buildIcon(context), minLeadingWidth: 0, - onTap: () { - _appsBloc.setActiveApp(appImplementation.id); + onTap: () async { + await _appsBloc.setActiveApp(appImplementation.id); if (navigationMode == NavigationMode.drawer) { // Don't pop when the drawer is always shown + if (!mounted) { + return; + } Navigator.of(context).pop(); } },