Skip to content

Commit

Permalink
refactor(neon_framework): Cleanup version checks
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed May 13, 2024
1 parent 8320f4a commit f699c8f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
33 changes: 20 additions & 13 deletions packages/neon_framework/lib/src/blocs/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:neon_framework/src/models/notifications_interface.dart';
import 'package:neon_framework/src/utils/account_options.dart';
import 'package:neon_framework/src/utils/findable.dart';
import 'package:neon_framework/src/utils/request_manager.dart';
import 'package:neon_framework/src/utils/server_version.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -50,9 +49,12 @@ abstract class AppsBloc implements InteractiveBloc {
/// A subject emitting an event when the notifications page should be opened.
BehaviorSubject<void> get openNotifications;

/// A collection of unsupported apps and their minimum required version.
/// A collection of apps and their version checks.
BehaviorSubject<BuiltMap<String, VersionCheck>> get appVersionChecks;

/// A collection of unsupported apps and their minimum required version.
BehaviorSubject<BuiltMap<String, VersionCheck>> get unsupportedApps;

/// Returns the active [Bloc] for the given [appImplementation].
///
/// If no bloc exists yet a new one will be instantiated and cached in [AppImplementation.blocsCache].
Expand Down Expand Up @@ -99,6 +101,14 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
}
});

appVersionChecks.listen((checks) {
unsupportedApps.add(
checks.rebuild((b) {
b.removeWhere((app, check) => check.isSupported);
}),
);
});

unawaited(refresh());
}

Expand Down Expand Up @@ -172,12 +182,9 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
return;
}

final notSupported = MapBuilder<String, VersionCheck>();
final checks = MapBuilder<String, VersionCheck>();

final coreCheck = account.client.core.getVersionCheck(capabilities.requireData);
if (!coreCheck.isSupported && !isDevelopmentServerVersion(capabilities.requireData.version.string)) {
notSupported['core'] = coreCheck;
}
checks['core'] = account.client.core.getVersionCheck(capabilities.requireData);

for (final app in apps.requireData) {
try {
Expand All @@ -187,9 +194,7 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
continue;
}

if (!check.isSupported) {
notSupported[app.id] = check;
}
checks[app.id] = check;
} on Exception catch (error, stackTrace) {
log.warning(
'An Exception occurred while checking the installed version of $app.',
Expand All @@ -199,9 +204,7 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
}
}

if (notSupported.isNotEmpty) {
appVersionChecks.add(notSupported.build());
}
appVersionChecks.add(checks.build());
}

T? findAppImplementation<T extends AppImplementation>(String id) {
Expand Down Expand Up @@ -234,6 +237,7 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
unawaited(activeApp.close());
unawaited(openNotifications.close());
unawaited(appVersionChecks.close());
unawaited(unsupportedApps.close());

super.dispose();
}
Expand All @@ -253,6 +257,9 @@ class _AppsBloc extends InteractiveBloc implements AppsBloc {
@override
final appVersionChecks = BehaviorSubject();

@override
final unsupportedApps = BehaviorSubject();

@override
Future<void> refresh() async {
await RequestManager.instance.wrapNextcloud(
Expand Down
4 changes: 2 additions & 2 deletions packages/neon_framework/lib/src/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class _HomePageState extends State<HomePage> {
_appsBloc = _accountsBloc.getAppsBlocFor(widget.account);
final maintenanceModeBloc = _accountsBloc.getMaintenanceModeBlocFor(widget.account);

_versionCheckSubscription = _appsBloc.appVersionChecks.listen((values) {
_versionCheckSubscription = _appsBloc.unsupportedApps.listen((unsupportedChecks) {
if (!mounted) {
return;
}

final l10n = NeonLocalizations.of(context);
final buffer = StringBuffer()..writeln();

for (final entry in values.entries) {
for (final entry in unsupportedChecks.entries) {
final versionCheck = entry.value;
final appName = l10n.appImplementationName(entry.key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import 'package:neon_framework/src/bloc/result.dart';
import 'package:neon_framework/src/blocs/login_check_server_status.dart';
import 'package:neon_framework/src/router.dart';
import 'package:neon_framework/src/theme/dialog.dart';
import 'package:neon_framework/src/utils/server_version.dart';
import 'package:neon_framework/src/widgets/error.dart';
import 'package:neon_framework/src/widgets/validation_tile.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:nextcloud/core.dart';

@internal
class LoginCheckServerStatusPage extends StatefulWidget {
Expand Down Expand Up @@ -65,7 +65,7 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
subject: bloc.state,
builder: (context, state) {
final success =
state.hasData && _isServerVersionAllowed(state.requireData) && !state.requireData.maintenance;
state.hasData && state.requireData.versionCheck.isSupported && !state.requireData.maintenance;

return Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down Expand Up @@ -111,9 +111,6 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
}
}

bool _isServerVersionAllowed(core.Status status) =>
status.versionCheck.isSupported || isDevelopmentServerVersion(status.versionstring);

Widget _buildServerVersionTile(Result<core.Status> result) {
if (result.hasError) {
return NeonValidationTile(
Expand All @@ -129,7 +126,7 @@ class _LoginCheckServerStatusPageState extends State<LoginCheckServerStatusPage>
);
}

if (_isServerVersionAllowed(result.requireData)) {
if (result.requireData.versionCheck.isSupported) {
return NeonValidationTile(
title: NeonLocalizations.of(context).loginSupportedServerVersion(result.requireData.versionstring),
state: ValidationState.success,
Expand Down
4 changes: 0 additions & 4 deletions packages/neon_framework/lib/src/utils/server_version.dart

This file was deleted.

0 comments on commit f699c8f

Please sign in to comment.