From f90275d648ab61529c7d23ad9791622dd34b3e80 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 25 Sep 2022 01:46:50 +0200 Subject: [PATCH] neon: Implement better extended version checking for apps --- packages/neon/lib/l10n/en.arb | 9 ++- packages/neon/lib/l10n/localizations.dart | 12 ++- packages/neon/lib/l10n/localizations_en.dart | 7 +- packages/neon/lib/src/blocs/apps.dart | 2 +- packages/neon/lib/src/pages/home/home.dart | 77 +++++++++++++++----- 5 files changed, 77 insertions(+), 30 deletions(-) diff --git a/packages/neon/lib/l10n/en.arb b/packages/neon/lib/l10n/en.arb index 76e1ccf5..251c5bba 100644 --- a/packages/neon/lib/l10n/en.arb +++ b/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", diff --git a/packages/neon/lib/l10n/localizations.dart b/packages/neon/lib/l10n/localizations.dart index 606eb57e..24c1e57d 100644 --- a/packages/neon/lib/l10n/localizations.dart +++ b/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: diff --git a/packages/neon/lib/l10n/localizations_en.dart b/packages/neon/lib/l10n/localizations_en.dart index 6ca3f67a..d4497969 100644 --- a/packages/neon/lib/l10n/localizations_en.dart +++ b/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'; diff --git a/packages/neon/lib/src/blocs/apps.dart b/packages/neon/lib/src/blocs/apps.dart index d5f0173d..a8b9e1e5 100644 --- a/packages/neon/lib/src/blocs/apps.dart +++ b/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>).data)), + ResultCached(_filteredAppImplementations((result as ResultCached>).data)), ); } diff --git a/packages/neon/lib/src/pages/home/home.dart b/packages/neon/lib/src/pages/home/home.dart index b062e2d1..55083d6b 100644 --- a/packages/neon/lib/src/pages/home/home.dart +++ b/packages/neon/lib/src/pages/home/home.dart @@ -54,26 +54,43 @@ class _HomePageState extends State 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 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();