Browse Source

neon: Implement better extended version checking for apps

pull/62/head
jld3103 2 years ago
parent
commit
f90275d648
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 9
      packages/neon/lib/l10n/en.arb
  2. 12
      packages/neon/lib/l10n/localizations.dart
  3. 7
      packages/neon/lib/l10n/localizations_en.dart
  4. 2
      packages/neon/lib/src/blocs/apps.dart
  5. 77
      packages/neon/lib/src/pages/home/home.dart

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

@ -29,11 +29,11 @@
}
}
},
"errorUnsupportedNextcloudVersion": "Sorry this Nextcloud instance version is not supported. You need at least version {version} of Nextcloud.",
"@errorUnsupportedNextcloudVersion" : {
"errorUnsupportedVersion": "Sorry, this Nextcloud {name} version is not supported.",
"@errorUnsupportedVersion" : {
"placeholders": {
"version": {
"type": "int"
"name": {
"type": "String"
}
}
},
@ -122,6 +122,7 @@
"accountOptionsInitialApp": "App to show initially",
"accountOptionsAutomatic": "Automatic",
"licenses": "Licenses",
"coreName": "Server",
"filesName": "Files",
"filesUploadFiles": "Upload files",
"filesUploadImages": "Upload images",

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

@ -179,11 +179,11 @@ abstract class AppLocalizations {
/// **'Permission for {name} is missing'**
String errorMissingPermission(String name);
/// No description provided for @errorUnsupportedNextcloudVersion.
/// No description provided for @errorUnsupportedVersion.
///
/// 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);
/// **'Sorry, this Nextcloud {name} version is not supported.'**
String errorUnsupportedVersion(String name);
/// No description provided for @errorEmptyField.
///
@ -533,6 +533,12 @@ abstract class AppLocalizations {
/// **'Licenses'**
String get licenses;
/// No description provided for @coreName.
///
/// In en, this message translates to:
/// **'Server'**
String get coreName;
/// No description provided for @filesName.
///
/// In en, this message translates to:

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

@ -57,8 +57,8 @@ class AppLocalizationsEn extends AppLocalizations {
}
@override
String errorUnsupportedNextcloudVersion(int version) {
return 'Sorry this Nextcloud instance version is not supported. You need at least version $version of Nextcloud.';
String errorUnsupportedVersion(String name) {
return 'Sorry, this Nextcloud $name version is not supported.';
}
@override
@ -243,6 +243,9 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get licenses => 'Licenses';
@override
String get coreName => 'Server';
@override
String get filesName => 'Files';

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

@ -54,7 +54,7 @@ class AppsBloc extends $AppsBloc {
);
} else if (result is ResultCached && result.data != null) {
_appImplementationsSubject.add(
Result.success(_filteredAppImplementations((result as ResultCached<List<NextcloudApp>>).data)),
ResultCached(_filteredAppImplementations((result as ResultCached<List<NextcloudApp>>).data)),
);
}

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

@ -54,26 +54,43 @@ class _HomePageState extends State<HomePage> with tray.TrayListener, WindowListe
// ignore cached version and prevent duplicate dialogs
if (result is ResultSuccess) {
const requiredMajorVersion = 24;
if (result.data!.version!.major! < requiredMajorVersion) {
await showDialog(
context: context,
builder: (final context) => AlertDialog(
title: Text(AppLocalizations.of(context).errorUnsupportedNextcloudVersion(requiredMajorVersion)),
actions: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
),
onPressed: () {
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context).close),
),
],
),
);
}
_appsBloc.appImplementations.listen((final appsResult) async {
// ignore cached version and prevent duplicate dialogs
if (appsResult is ResultSuccess) {
for (final id in [
'core',
...appsResult.data!.map((final a) => a.id),
]) {
try {
bool? supported;
switch (id) {
case 'core':
supported = await widget.account.client.core.isSupported(result.data!);
break;
case 'news':
supported = await widget.account.client.news.isSupported();
break;
case 'notes':
supported = await widget.account.client.notes.isSupported(result.data!);
break;
}
if (!(supported ?? true)) {
if (!mounted) {
return;
}
await _showUnsupportedVersion(
id == 'core'
? AppLocalizations.of(context).coreName
: appsResult.data!.singleWhere((final a) => a.id == id).name(context),
);
}
} catch (e, s) {
debugPrint(e.toString());
debugPrint(s.toString());
}
}
}
});
}
}
});
@ -259,6 +276,26 @@ class _HomePageState extends State<HomePage> with tray.TrayListener, WindowListe
}
}
Future _showUnsupportedVersion(final String appName) async {
await showDialog(
context: context,
builder: (final context) => AlertDialog(
title: Text(AppLocalizations.of(context).errorUnsupportedVersion(appName)),
actions: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
),
onPressed: () {
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context).close),
),
],
),
);
}
@override
void dispose() {
_capabilitiesBloc.dispose();

Loading…
Cancel
Save