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<void> get openNotifications;
BehaviorSubject<Iterable<(String, Object?)>?> get appVersions; BehaviorSubject<Map<String, String?>> get appVersions;
} }
@internal @internal
@ -116,24 +116,23 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
return; return;
} }
final appIds = { final notSupported = <String, String?>{};
'core',
...apps.requireData.map((final a) => a.id),
};
final notSupported = <(String, Object?)>[];
for (final id in appIds) {
try { try {
final (supported, minVersion) = switch (id) { final (coreSupported, coreMinimumVersion) = _account.client.core.isSupported(capabilities.requireData);
'core' => _account.client.core.isSupported(capabilities.requireData), if (!coreSupported) {
AppIDs.news => await _account.client.news.isSupported(), notSupported['core'] = coreMinimumVersion.toString();
AppIDs.notes => _account.client.notes.isSupported(capabilities.requireData), }
_ => (true, null), } catch (e, s) {
}; debugPrint(e.toString());
debugPrint(s.toString());
}
if (!supported) { for (final app in apps.requireData) {
notSupported.add((id, minVersion)); try {
final (supported, minimumVersion) = await app.isSupported(_account, capabilities.requireData);
if (!(supported ?? true)) {
notSupported[app.id] = minimumVersion;
} }
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());
@ -193,7 +192,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
BehaviorSubject<void> openNotifications = BehaviorSubject(); BehaviorSubject<void> openNotifications = BehaviorSubject();
@override @override
BehaviorSubject<List<(String, Object?)>?> appVersions = BehaviorSubject(); BehaviorSubject<Map<String, String?>> appVersions = BehaviorSubject();
@override @override
Future<void> refresh() async { 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:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.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/settings/models/storage.dart';
import 'package:neon/src/utils/provider.dart'; import 'package:neon/src/utils/provider.dart';
import 'package:neon/src/widgets/drawer_destination.dart'; import 'package:neon/src/widgets/drawer_destination.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
import 'package:vector_graphics/vector_graphics.dart'; import 'package:vector_graphics/vector_graphics.dart';
@ -33,6 +36,18 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>
@mustBeOverridden @mustBeOverridden
R get options; 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>(); final blocsCache = AccountCache<T>();
T getBloc(final Account account) => blocsCache[account] ??= buildBloc(account); 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 GlobalOptions _globalOptions;
late AccountsBloc _accountsBloc; late AccountsBloc _accountsBloc;
late AppsBloc _appsBloc; late AppsBloc _appsBloc;
late StreamSubscription<List<(String, Object?)>?> _versionCheckSubscription; late StreamSubscription<Map<String, String?>> _versionCheckSubscription;
@override @override
void initState() { void initState() {
@ -47,7 +47,7 @@ class _HomePageState extends State<HomePage> {
_appsBloc = _accountsBloc.activeAppsBloc; _appsBloc = _accountsBloc.activeAppsBloc;
_versionCheckSubscription = _appsBloc.appVersions.listen((final values) { _versionCheckSubscription = _appsBloc.appVersions.listen((final values) {
if (values == null || !mounted) { if (!mounted) {
return; return;
} }
@ -55,8 +55,9 @@ class _HomePageState extends State<HomePage> {
final buffer = StringBuffer()..writeln(); final buffer = StringBuffer()..writeln();
for (final error in values) { for (final error in values.entries) {
final (appId, minVersion) = error; final appId = error.key;
final minVersion = error.value;
final appName = l10n.appImplementationName(appId); final appName = l10n.appImplementationName(appId);
if (appName.isNotEmpty && minVersion != null) { 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 @override
final RouteBase route = $filesAppRoute; 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 @override
BehaviorSubject<int> getUnreadCounter(final NewsBloc bloc) => bloc.unreadCounter; 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 @override
final RouteBase route = $notesAppRoute; 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 @override
BehaviorSubject<int> getUnreadCounter(final NotificationsBloc bloc) => bloc.unreadCounter; 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