Browse Source

neon: Add Nextcloud version compatibility checker

pull/37/head
jld3103 2 years ago
parent
commit
649b537bac
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 8
      packages/neon/lib/l10n/en.arb
  2. 6
      packages/neon/lib/l10n/localizations.dart
  3. 5
      packages/neon/lib/l10n/localizations_en.dart
  4. 6
      packages/neon/lib/src/blocs/capabilities.dart
  5. 7
      packages/neon/lib/src/blocs/capabilities.rxb.g.dart
  6. 32
      packages/neon/lib/src/pages/home/home.dart

8
packages/neon/lib/l10n/en.arb

@ -29,6 +29,14 @@
} }
} }
}, },
"errorUnsupportedNextcloudVersion": "Sorry this Nextcloud instance version is not supported. You need at least version {version} of Nextcloud.",
"@errorUnsupportedNextcloudVersion" : {
"placeholders": {
"version": {
"type": "int"
}
}
},
"validatorEmptyField": "This field can not be empty", "validatorEmptyField": "This field can not be empty",
"validatorInvalidURL": "Invalid URL provided", "validatorInvalidURL": "Invalid URL provided",
"delete": "Delete", "delete": "Delete",

6
packages/neon/lib/l10n/localizations.dart

@ -179,6 +179,12 @@ abstract class AppLocalizations {
/// **'Permission for {name} is missing'** /// **'Permission for {name} is missing'**
String errorMissingPermission(String name); String errorMissingPermission(String name);
/// No description provided for @errorUnsupportedNextcloudVersion.
///
/// In en, this message translates to:
/// **'Sorry this Nextcloud instance version is not supported. You need at least version {version} of Nextcloud.'**
String errorUnsupportedNextcloudVersion(int version);
/// No description provided for @validatorEmptyField. /// No description provided for @validatorEmptyField.
/// ///
/// In en, this message translates to: /// In en, this message translates to:

5
packages/neon/lib/l10n/localizations_en.dart

@ -56,6 +56,11 @@ class AppLocalizationsEn extends AppLocalizations {
return 'Permission for $name is missing'; return 'Permission for $name is missing';
} }
@override
String errorUnsupportedNextcloudVersion(int version) {
return 'Sorry this Nextcloud instance version is not supported. You need at least version $version of Nextcloud.';
}
@override @override
String get validatorEmptyField => 'This field can not be empty'; String get validatorEmptyField => 'This field can not be empty';

6
packages/neon/lib/src/blocs/capabilities.dart

@ -6,7 +6,7 @@ import 'package:rxdart/rxdart.dart';
part 'capabilities.rxb.g.dart'; part 'capabilities.rxb.g.dart';
typedef Capabilities = CoreServerCapabilitiesOcsDataCapabilities; typedef Capabilities = CoreServerCapabilitiesOcsData;
typedef NextcloudTheme = CoreServerCapabilitiesOcsDataCapabilitiesTheming; typedef NextcloudTheme = CoreServerCapabilitiesOcsDataCapabilitiesTheming;
abstract class CapabilitiesBlocEvents {} abstract class CapabilitiesBlocEvents {}
@ -26,12 +26,12 @@ class CapabilitiesBloc extends $CapabilitiesBloc {
void _loadCapabilities() { void _loadCapabilities() {
_requestManager _requestManager
.wrapNextcloud<Capabilities, CoreServerCapabilities, void, NextcloudCoreClient>( .wrapNextcloud<CoreServerCapabilitiesOcsData, CoreServerCapabilities, void, NextcloudCoreClient>(
_client.id, _client.id,
_client.core, _client.core,
'capabilities', 'capabilities',
() async => (await _client.core.getCapabilities())!, () async => (await _client.core.getCapabilities())!,
(final response) => response.ocs!.data!.capabilities!, (final response) => response.ocs!.data!,
preloadCache: true, preloadCache: true,
) )
.listen(_capabilitiesSubject.add); .listen(_capabilitiesSubject.add);

7
packages/neon/lib/src/blocs/capabilities.rxb.g.dart

@ -20,13 +20,12 @@ abstract class $CapabilitiesBloc extends RxBlocBase
final _compositeSubscription = CompositeSubscription(); final _compositeSubscription = CompositeSubscription();
/// The state of [capabilities] implemented in [_mapToCapabilitiesState] /// The state of [capabilities] implemented in [_mapToCapabilitiesState]
late final BehaviorSubject<Result<CoreServerCapabilitiesOcsDataCapabilities>> _capabilitiesState = late final BehaviorSubject<Result<CoreServerCapabilitiesOcsData>> _capabilitiesState = _mapToCapabilitiesState();
_mapToCapabilitiesState();
@override @override
BehaviorSubject<Result<CoreServerCapabilitiesOcsDataCapabilities>> get capabilities => _capabilitiesState; BehaviorSubject<Result<CoreServerCapabilitiesOcsData>> get capabilities => _capabilitiesState;
BehaviorSubject<Result<CoreServerCapabilitiesOcsDataCapabilities>> _mapToCapabilitiesState(); BehaviorSubject<Result<CoreServerCapabilitiesOcsData>> _mapToCapabilitiesState();
@override @override
CapabilitiesBlocEvents get events => this; CapabilitiesBlocEvents get events => this;

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

@ -50,7 +50,31 @@ class _HomePageState extends State<HomePage> with tray.TrayListener, WindowListe
); );
_capabilitiesBloc.capabilities.listen((final result) { _capabilitiesBloc.capabilities.listen((final result) {
if (result.data != null) { if (result.data != null) {
widget.onThemeChanged(result.data!.theming!); widget.onThemeChanged(result.data!.capabilities!.theming!);
// ignore cached version and prevent duplicate dialogs
if (result is ResultSuccess) {
const requiredMajorVersion = 24;
if (result.data!.version!.major! < requiredMajorVersion) {
showDialog(
context: context,
builder: (final context) => AlertDialog(
title: Text(AppLocalizations.of(context).errorUnsupportedNextcloudVersion(requiredMajorVersion)),
actions: [
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red,
),
onPressed: () {
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context).close),
),
],
),
);
}
}
} }
}); });
_appsBloc = AppsBloc( _appsBloc = AppsBloc(
@ -410,15 +434,15 @@ class _HomePageState extends State<HomePage> with tray.TrayListener, WindowListe
children: [ children: [
if (capabilitiesData != null) ...[ if (capabilitiesData != null) ...[
Text( Text(
capabilitiesData.theming!.name!, capabilitiesData.capabilities!.theming!.name!,
style: DefaultTextStyle.of(context).style.copyWith( style: DefaultTextStyle.of(context).style.copyWith(
color: Theme.of(context).colorScheme.onPrimary, color: Theme.of(context).colorScheme.onPrimary,
), ),
), ),
if (capabilitiesData.theming!.logo != null) ...[ if (capabilitiesData.capabilities!.theming!.logo != null) ...[
Flexible( Flexible(
child: CachedURLImage( child: CachedURLImage(
url: capabilitiesData.theming!.logo!, url: capabilitiesData.capabilities!.theming!.logo!,
requestManager: _requestManager, requestManager: _requestManager,
client: widget.account.client, client: widget.account.client,
), ),

Loading…
Cancel
Save