Browse Source

refactor(neon,neon_news,neon_notes): Rework version checks to support maximum version

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/1157/head
jld3103 1 year ago
parent
commit
3c749930c9
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 18
      packages/neon/neon/lib/src/blocs/apps.dart
  2. 4
      packages/neon/neon/lib/src/models/app_implementation.dart
  3. 17
      packages/neon/neon/lib/src/pages/home.dart
  4. 5
      packages/neon/neon/lib/src/pages/login_check_server_status.dart
  5. 1
      packages/neon/neon/pubspec.yaml
  6. 4
      packages/neon/neon_news/lib/neon_news.dart
  7. 8
      packages/neon/neon_notes/lib/neon_notes.dart

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

@ -44,7 +44,7 @@ abstract interface class AppsBlocStates {
BehaviorSubject<void> get openNotifications; BehaviorSubject<void> get openNotifications;
/// A collection of unsupported apps and their minimum required version. /// A collection of unsupported apps and their minimum required version.
BehaviorSubject<Map<String, String?>> get appVersions; BehaviorSubject<Map<String, VersionCheck>> get appVersionChecks;
} }
/// The Bloc responsible for managing the [AppImplementation]s. /// The Bloc responsible for managing the [AppImplementation]s.
@ -131,12 +131,12 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
return; return;
} }
final notSupported = <String, String?>{}; final notSupported = <String, VersionCheck>{};
try { try {
final coreCheck = _account.client.core.isSupported(capabilities.requireData); final coreCheck = _account.client.core.getVersionCheck(capabilities.requireData);
if (!coreCheck.isSupported) { if (!coreCheck.isSupported) {
notSupported['core'] = coreCheck.minimumVersion.toString(); notSupported['core'] = coreCheck;
} }
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());
@ -145,14 +145,14 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
for (final app in apps.requireData) { for (final app in apps.requireData) {
try { try {
final check = await app.isSupported(_account, capabilities.requireData); final check = await app.getVersionCheck(_account, capabilities.requireData);
if (check == null) { if (check == null) {
continue; continue;
} }
if (!check.isSupported) { if (!check.isSupported) {
notSupported[app.id] = check.minimumVersion; notSupported[app.id] = check;
} }
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());
@ -161,7 +161,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
} }
if (notSupported.isNotEmpty) { if (notSupported.isNotEmpty) {
appVersions.add(notSupported); appVersionChecks.add(notSupported);
} }
} }
@ -190,7 +190,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
unawaited(notificationsAppImplementation.close()); unawaited(notificationsAppImplementation.close());
unawaited(activeApp.close()); unawaited(activeApp.close());
unawaited(openNotifications.close()); unawaited(openNotifications.close());
unawaited(appVersions.close()); unawaited(appVersionChecks.close());
super.dispose(); super.dispose();
} }
@ -209,7 +209,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
BehaviorSubject<void> openNotifications = BehaviorSubject(); BehaviorSubject<void> openNotifications = BehaviorSubject();
@override @override
BehaviorSubject<Map<String, String?>> appVersions = BehaviorSubject(); BehaviorSubject<Map<String, VersionCheck>> appVersionChecks = BehaviorSubject();
@override @override
Future<void> refresh() async { Future<void> refresh() async {

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

@ -15,7 +15,7 @@ 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/core.dart' as core; import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/nextcloud.dart' show VersionSupported; import 'package:nextcloud/nextcloud.dart' show VersionCheck;
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';
@ -61,7 +61,7 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>
/// A value of `null` means that it can not be known if the app is supported. /// A 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. /// 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 server support is handled differently.
FutureOr<VersionSupported<String>?> isSupported( FutureOr<VersionCheck?> getVersionCheck(
final Account account, final Account account,
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities, final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) => ) =>

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

@ -16,6 +16,7 @@ import 'package:neon/src/widgets/drawer.dart';
import 'package:neon/src/widgets/error.dart'; import 'package:neon/src/widgets/error.dart';
import 'package:neon/src/widgets/unified_search_results.dart'; import 'package:neon/src/widgets/unified_search_results.dart';
import 'package:nextcloud/core.dart' as core; import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
/// The home page of Neon. /// The home page of Neon.
@ -35,7 +36,7 @@ class _HomePageState extends State<HomePage> {
late global_options.GlobalOptions _globalOptions; late global_options.GlobalOptions _globalOptions;
late AccountsBloc _accountsBloc; late AccountsBloc _accountsBloc;
late AppsBloc _appsBloc; late AppsBloc _appsBloc;
late StreamSubscription<Map<String, String?>> _versionCheckSubscription; late StreamSubscription<Map<String, VersionCheck>> _versionCheckSubscription;
@override @override
void initState() { void initState() {
@ -45,23 +46,19 @@ class _HomePageState extends State<HomePage> {
_account = _accountsBloc.activeAccount.value!; _account = _accountsBloc.activeAccount.value!;
_appsBloc = _accountsBloc.activeAppsBloc; _appsBloc = _accountsBloc.activeAppsBloc;
_versionCheckSubscription = _appsBloc.appVersions.listen((final values) { _versionCheckSubscription = _appsBloc.appVersionChecks.listen((final values) {
if (!mounted) { if (!mounted) {
return; return;
} }
final l10n = NeonLocalizations.of(context); final l10n = NeonLocalizations.of(context);
final buffer = StringBuffer()..writeln(); final buffer = StringBuffer()..writeln();
for (final error in values.entries) { for (final entry in values.entries) {
final appId = error.key; final versionCheck = entry.value;
final minVersion = error.value; final appName = l10n.appImplementationName(entry.key);
final appName = l10n.appImplementationName(appId);
if (appName.isNotEmpty && minVersion != null) { buffer.writeln('- $appName >=${versionCheck.minimumVersion} <${versionCheck.maximumMajor + 1}.0.0');
buffer.writeln('- $appName $minVersion');
}
} }
final message = l10n.errorUnsupportedAppVersions(buffer.toString()); final message = l10n.errorUnsupportedAppVersions(buffer.toString());

5
packages/neon/neon/lib/src/pages/login_check_server_status.dart

@ -60,7 +60,8 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
child: ResultBuilder.behaviorSubject( child: ResultBuilder.behaviorSubject(
subject: bloc.state, subject: bloc.state,
builder: (final context, final state) { builder: (final context, final state) {
final success = state.hasData && state.requireData.isSupported && !state.requireData.maintenance; final success =
state.hasData && state.requireData.versionCheck.isSupported && !state.requireData.maintenance;
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -121,7 +122,7 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
); );
} }
if (result.requireData.isSupported) { if (result.requireData.versionCheck.isSupported) {
return NeonValidationTile( return NeonValidationTile(
title: NeonLocalizations.of(context).loginSupportedServerVersion(result.requireData.versionstring), title: NeonLocalizations.of(context).loginSupportedServerVersion(result.requireData.versionstring),
state: ValidationState.success, state: ValidationState.success,

1
packages/neon/neon/pubspec.yaml

@ -56,6 +56,7 @@ dependencies:
universal_io: ^2.0.0 universal_io: ^2.0.0
url_launcher: ^6.1.0 url_launcher: ^6.1.0
vector_graphics: ^1.0.0 vector_graphics: ^1.0.0
version: ^3.0.0
window_manager: ^0.3.0 window_manager: ^0.3.0
xml: ^6.0.0 xml: ^6.0.0

4
packages/neon/neon_news/lib/neon_news.dart

@ -109,9 +109,9 @@ class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
BehaviorSubject<int> getUnreadCounter(final NewsBloc bloc) => bloc.unreadCounter; BehaviorSubject<int> getUnreadCounter(final NewsBloc bloc) => bloc.unreadCounter;
@override @override
Future<VersionSupported<String>> isSupported( Future<VersionCheck> getVersionCheck(
final Account account, final Account account,
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities, final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) => ) =>
account.client.news.isSupported(); account.client.news.getVersionCheck();
} }

8
packages/neon/neon_notes/lib/neon_notes.dart

@ -95,11 +95,9 @@ class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
final RouteBase route = $notesAppRoute; final RouteBase route = $notesAppRoute;
@override @override
VersionSupported<String> isSupported( VersionCheck getVersionCheck(
final Account account, final Account account,
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities, final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities,
) { ) =>
final result = account.client.notes.isSupported(capabilities); account.client.notes.getVersionCheck(capabilities);
return (isSupported: result.isSupported, minimumVersion: result.minimumVersion.toString());
}
} }

Loading…
Cancel
Save