Browse Source

fix(neon): Prevent race condition setting active app

pull/508/head
jld3103 1 year ago
parent
commit
df2bd48854
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 14
      packages/neon/neon/lib/src/blocs/apps.dart

14
packages/neon/neon/lib/src/blocs/apps.dart

@ -19,7 +19,11 @@ import 'package:rxdart/rxdart.dart';
typedef NextcloudApp = CoreNavigationApps_Ocs_Data; typedef NextcloudApp = CoreNavigationApps_Ocs_Data;
abstract class AppsBlocEvents { abstract class AppsBlocEvents {
void setActiveApp(final String appID); /// Sets the active app using the [appID].
///
/// If the app is already the active app nothing will happen.
/// When using [skipAlreadySet] nothing will be done if there already is an active app.
void setActiveApp(final String appID, {final bool skipAlreadySet = false});
} }
abstract class AppsBlocStates { abstract class AppsBlocStates {
@ -57,8 +61,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
final options = _accountsBloc.getOptionsFor(_account); final options = _accountsBloc.getOptionsFor(_account);
final initialApp = options.initialApp.value ?? _getInitialAppFallback(); final initialApp = options.initialApp.value ?? _getInitialAppFallback();
if (!activeApp.hasValue && initialApp != null) { if (initialApp != null) {
await setActiveApp(initialApp); await setActiveApp(initialApp, skipAlreadySet: true);
} }
unawaited(_checkCompatibility()); unawaited(_checkCompatibility());
@ -201,7 +205,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
} }
@override @override
Future setActiveApp(final String appID) async { Future setActiveApp(final String appID, {final bool skipAlreadySet = false}) async {
if (appID == AppIDs.notifications) { if (appID == AppIDs.notifications) {
openNotifications.add(null); openNotifications.add(null);
return; return;
@ -210,7 +214,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
final apps = await appImplementations.firstWhere((final a) => a.hasData); final apps = await appImplementations.firstWhere((final a) => a.hasData);
final app = apps.requireData.tryFind(appID); final app = apps.requireData.tryFind(appID);
if (app != null) { if (app != null) {
if (activeApp.valueOrNull?.id != appID) { if ((!activeApp.hasValue || !skipAlreadySet) && activeApp.valueOrNull?.id != appID) {
activeApp.add(app); activeApp.add(app);
} }
} else { } else {

Loading…
Cancel
Save