Browse Source

neon: cleanup AppsBloc initialApp

pull/466/head
Nikolas Rimikis 1 year ago
parent
commit
e1b61c6977
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 36
      packages/neon/neon/lib/src/blocs/apps.dart

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

@ -50,19 +50,15 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
}); });
appImplementations.listen((final result) { appImplementations.listen((final result) {
if (result.hasData) { if (!result.hasData) {
return;
}
final options = _accountsBloc.getOptionsFor(_account); final options = _accountsBloc.getOptionsFor(_account);
unawaited( unawaited(
options.initialApp.stream.first.then((var initialApp) async { options.initialApp.stream.first.then((var initialApp) async {
if (initialApp == null) { initialApp ??= _getInitialAppFallback();
if (result.requireData.tryFind('files') != null) {
initialApp = 'files';
} else if (result.requireData.isNotEmpty) {
// This should never happen, because the files app is always installed and can not be removed, but just in
// case this changes at a later point.
initialApp = result.requireData.first.id;
}
}
if (!activeApp.hasValue && initialApp != null) { if (!activeApp.hasValue && initialApp != null) {
await setActiveApp(initialApp); await setActiveApp(initialApp);
} }
@ -70,7 +66,6 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
); );
unawaited(_checkCompatibility()); unawaited(_checkCompatibility());
}
}); });
_capabilitiesBloc.capabilities.listen((final result) { _capabilitiesBloc.capabilities.listen((final result) {
@ -86,6 +81,25 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
unawaited(refresh()); unawaited(refresh());
} }
/// Determines the appid of initial app.
///
/// It requires [appImplementations] to have both a value and data.
///
/// The files app is always installed and can not be removed so it will be used, but in the
/// case this changes at a later point the first supported app will be returned.
///
/// Returns null when no app is supported by the server.
String? _getInitialAppFallback() {
final supportedApps = appImplementations.value.requireData;
if (supportedApps.tryFind('files') != null) {
return 'files';
} else if (supportedApps.isNotEmpty) {
return supportedApps.first.id;
}
return null;
}
Future<void> _checkCompatibility() async { Future<void> _checkCompatibility() async {
final apps = appImplementations.valueOrNull; final apps = appImplementations.valueOrNull;
final capabilities = _capabilitiesBloc.capabilities.valueOrNull; final capabilities = _capabilitiesBloc.capabilities.valueOrNull;

Loading…
Cancel
Save