Browse Source

Merge pull request #877 from nextcloud/refactor/neon/app-support-check

Move app support check to app implementations
pull/851/head
Kate 1 year ago committed by GitHub
parent
commit
dd20f02ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      packages/neon/neon/lib/src/blocs/apps.dart
  2. 15
      packages/neon/neon/lib/src/models/app_implementation.dart
  3. 9
      packages/neon/neon/lib/src/pages/home.dart
  4. 7
      packages/neon/neon_files/lib/neon_files.dart
  5. 7
      packages/neon/neon_news/lib/neon_news.dart
  6. 9
      packages/neon/neon_notes/lib/neon_notes.dart
  7. 7
      packages/neon/neon_notifications/lib/neon_notifications.dart

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

@ -36,7 +36,7 @@ abstract interface class AppsBlocStates {
BehaviorSubject<void> get openNotifications;
BehaviorSubject<Iterable<(String, Object?)>?> get appVersions;
BehaviorSubject<Map<String, String?>> get appVersions;
}
@internal
@ -116,24 +116,23 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
return;
}
final appIds = {
'core',
...apps.requireData.map((final a) => a.id),
};
final notSupported = <String, String?>{};
final notSupported = <(String, Object?)>[];
try {
final (coreSupported, coreMinimumVersion) = _account.client.core.isSupported(capabilities.requireData);
if (!coreSupported) {
notSupported['core'] = coreMinimumVersion.toString();
}
} catch (e, s) {
debugPrint(e.toString());
debugPrint(s.toString());
}
for (final id in appIds) {
for (final app in apps.requireData) {
try {
final (supported, minVersion) = switch (id) {
'core' => _account.client.core.isSupported(capabilities.requireData),
AppIDs.news => await _account.client.news.isSupported(),
AppIDs.notes => _account.client.notes.isSupported(capabilities.requireData),
_ => (true, null),
};
if (!supported) {
notSupported.add((id, minVersion));
final (supported, minimumVersion) = await app.isSupported(_account, capabilities.requireData);
if (!(supported ?? true)) {
notSupported[app.id] = minimumVersion;
}
} catch (e, s) {
debugPrint(e.toString());
@ -193,7 +192,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
BehaviorSubject<void> openNotifications = BehaviorSubject();
@override
BehaviorSubject<List<(String, Object?)>?> appVersions = BehaviorSubject();
BehaviorSubject<Map<String, String?>> appVersions = BehaviorSubject();
@override
Future<void> refresh() async {

15
packages/neon/neon/lib/src/models/app_implementation.dart

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
@ -12,6 +14,7 @@ import 'package:neon/src/settings/models/options_collection.dart';
import 'package:neon/src/settings/models/storage.dart';
import 'package:neon/src/utils/provider.dart';
import 'package:neon/src/widgets/drawer_destination.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';
import 'package:vector_graphics/vector_graphics.dart';
@ -33,6 +36,18 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>
@mustBeOverridden
R get options;
/// Checks if the app is supported on the server of the [account].
///
/// A `supported` value of `null` means that it can not be known if the app is supported.
/// This is the case for apps that depend on the server version like files and we assume that the app is supported.
/// The server support is handled differently.
///
/// The first value of the record is the supported status and the second value is the supported minimum version.
FutureOr<(bool? supported, String? minimumVersion)> isSupported(
final Account account,
final CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
);
final blocsCache = AccountCache<T>();
T getBloc(final Account account) => blocsCache[account] ??= buildBloc(account);

9
packages/neon/neon/lib/src/pages/home.dart

@ -36,7 +36,7 @@ class _HomePageState extends State<HomePage> {
late GlobalOptions _globalOptions;
late AccountsBloc _accountsBloc;
late AppsBloc _appsBloc;
late StreamSubscription<List<(String, Object?)>?> _versionCheckSubscription;
late StreamSubscription<Map<String, String?>> _versionCheckSubscription;
@override
void initState() {
@ -47,7 +47,7 @@ class _HomePageState extends State<HomePage> {
_appsBloc = _accountsBloc.activeAppsBloc;
_versionCheckSubscription = _appsBloc.appVersions.listen((final values) {
if (values == null || !mounted) {
if (!mounted) {
return;
}
@ -55,8 +55,9 @@ class _HomePageState extends State<HomePage> {
final buffer = StringBuffer()..writeln();
for (final error in values) {
final (appId, minVersion) = error;
for (final error in values.entries) {
final appId = error.key;
final minVersion = error.value;
final appName = l10n.appImplementationName(appId);
if (appName.isNotEmpty && minVersion != null) {

7
packages/neon/neon_files/lib/neon_files.dart

@ -71,4 +71,11 @@ class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {
@override
final RouteBase route = $filesAppRoute;
@override
(bool? supported, String? minimumVersion) isSupported(
final Account account,
final CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) =>
const (null, null);
}

7
packages/neon/neon_news/lib/neon_news.dart

@ -81,4 +81,11 @@ class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
@override
BehaviorSubject<int> getUnreadCounter(final NewsBloc bloc) => bloc.unreadCounter;
@override
Future<(bool? supported, String? minimumVersion)> isSupported(
final Account account,
final CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) =>
account.client.news.isSupported();
}

9
packages/neon/neon_notes/lib/neon_notes.dart

@ -67,4 +67,13 @@ class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
@override
final RouteBase route = $notesAppRoute;
@override
(bool? supported, String? minimumVersion) isSupported(
final Account account,
final CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) {
final (supported, minimumVersion) = account.client.notes.isSupported(capabilities);
return (supported, minimumVersion.toString());
}
}

7
packages/neon/neon_notifications/lib/neon_notifications.dart

@ -52,4 +52,11 @@ class NotificationsApp extends AppImplementation<NotificationsBloc, Notification
@override
BehaviorSubject<int> getUnreadCounter(final NotificationsBloc bloc) => bloc.unreadCounter;
@override
(bool? supported, String? minimumVersion) isSupported(
final Account account,
final CoreOcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) =>
const (null, null);
}

Loading…
Cancel
Save