From 93e3b50b178c05e29a4faa01f1a21b245e1cde37 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 17 May 2023 18:29:14 +0200 Subject: [PATCH 1/2] nextcloud: Expose the supported versions --- .../nextcloud/lib/src/version_supported.dart | 59 +++++++++++++------ packages/nextcloud/test/core.dart | 12 ++-- packages/nextcloud/test/news.dart | 4 +- packages/nextcloud/test/notes.dart | 4 +- 4 files changed, 51 insertions(+), 28 deletions(-) diff --git a/packages/nextcloud/lib/src/version_supported.dart b/packages/nextcloud/lib/src/version_supported.dart index 5ed050c5..6403f8c9 100644 --- a/packages/nextcloud/lib/src/version_supported.dart +++ b/packages/nextcloud/lib/src/version_supported.dart @@ -1,33 +1,56 @@ part of '../nextcloud.dart'; +/// Version of core/Server supported +const coreSupportedVersion = 26; + +/// API version of the news app supported +const newsSupportedVersion = 'v1-3'; + +/// API version of the notes app supported +const notesSupportedVersion = 1; + // ignore: public_member_api_docs extension CoreVersionSupported on NextcloudCoreClient { - /// Checks if the app on the server is supported by the client - Future isSupported([final NextcloudCoreServerCapabilities_Ocs_Data? capabilities]) async => - (capabilities ?? (await getCapabilities()).ocs.data).version.major == 26; + /// Check if the core/Server version is supported by this client + /// + /// Also returns the supported version number + Future<(bool, int)> isSupported([ + final NextcloudCoreServerCapabilities_Ocs_Data? capabilities, + ]) async => + ( + (capabilities ?? (await getCapabilities()).ocs.data).version.major == coreSupportedVersion, + coreSupportedVersion, + ); } // ignore: public_member_api_docs extension NewsVersionSupported on NextcloudNewsClient { - /// Checks if the app on the server is supported by the client - Future isSupported() async { + /// Check if the news app version is supported by this client + /// + /// Also returns the supported API version number + Future<(bool, String)> isSupported() async { final versions = await getSupportedApiVersions(); - return versions.apiLevels!.contains('v1-3'); + return ( + versions.apiLevels!.contains(newsSupportedVersion), + newsSupportedVersion, + ); } } // ignore: public_member_api_docs extension NotesVersionSupported on NextcloudNotesClient { - /// Checks if the app on the server is supported by the client - Future isSupported([final NextcloudCoreServerCapabilities_Ocs_Data? capabilities]) async => - (capabilities ?? (await rootClient.core.getCapabilities()).ocs.data) - .capabilities - .notes - ?.apiVersion - ?.map(Version.parse) - .where((final version) => version.major == 1) - .isNotEmpty ?? - false; + /// Check if the notes app version is supported by this client + /// + /// Also returns the supported API version number + Future<(bool, int)> isSupported([final NextcloudCoreServerCapabilities_Ocs_Data? capabilities]) async => ( + (capabilities ?? (await rootClient.core.getCapabilities()).ocs.data) + .capabilities + .notes + ?.apiVersion + ?.map(Version.parse) + .where((final version) => version.major == notesSupportedVersion) + .isNotEmpty ?? + false, + notesSupportedVersion, + ); } - -// Notifications, ProvisioningApi, UserStatus and Webdav are shipped with the Nextcloud server, so their supported versions depend on the major version of the Nextcloud instance. diff --git a/packages/nextcloud/test/core.dart b/packages/nextcloud/test/core.dart index 12e52c74..2520e413 100644 --- a/packages/nextcloud/test/core.dart +++ b/packages/nextcloud/test/core.dart @@ -18,8 +18,8 @@ Future run(final DockerImage image) async { tearDown(() => container.destroy()); test('Is supported', () async { - final response = await client.core.isSupported(); - expect(response, isTrue); + final (supported, _) = await client.core.isSupported(); + expect(supported, isTrue); }); test('Get status', () async { @@ -27,8 +27,8 @@ Future run(final DockerImage image) async { expect(status.installed, true); expect(status.maintenance, false); expect(status.needsDbUpgrade, false); - expect(status.version, startsWith('26.0.1')); - expect(status.versionstring, '26.0.1'); + expect(status.version, startsWith('$coreSupportedVersion.')); + expect(status.versionstring, startsWith('$coreSupportedVersion.')); expect(status.edition, ''); expect(status.productname, 'Nextcloud'); expect(status.extendedSupport, false); @@ -36,8 +36,8 @@ Future run(final DockerImage image) async { test('Get capabilities', () async { final capabilities = await client.core.getCapabilities(); - expect(capabilities.ocs.data.version.major.toString(), '26'); - expect(capabilities.ocs.data.version.string, '26.0.1'); + expect(capabilities.ocs.data.version.major, coreSupportedVersion); + expect(capabilities.ocs.data.version.string, startsWith('$coreSupportedVersion.')); expect(capabilities.ocs.data.capabilities.theming!.name, 'Nextcloud'); expect(capabilities.ocs.data.capabilities.theming!.url, 'https://nextcloud.com'); expect(capabilities.ocs.data.capabilities.theming!.slogan, 'a safe home for all your data'); diff --git a/packages/nextcloud/test/news.dart b/packages/nextcloud/test/news.dart index 7a2b3c7c..9c7fdbb8 100644 --- a/packages/nextcloud/test/news.dart +++ b/packages/nextcloud/test/news.dart @@ -30,8 +30,8 @@ Future run(final DockerImage image) async { ); test('Is supported', () async { - final response = await client.news.isSupported(); - expect(response, isTrue); + final (supported, _) = await client.news.isSupported(); + expect(supported, isTrue); }); test('Add feed', () async { diff --git a/packages/nextcloud/test/notes.dart b/packages/nextcloud/test/notes.dart index a686899c..6d564a6b 100644 --- a/packages/nextcloud/test/notes.dart +++ b/packages/nextcloud/test/notes.dart @@ -18,8 +18,8 @@ Future run(final DockerImage image) async { tearDown(() => container.destroy()); test('Is supported', () async { - final response = await client.notes.isSupported(); - expect(response, isTrue); + final (supported, _) = await client.notes.isSupported(); + expect(supported, isTrue); }); test('Create note favorite', () async { From db8a9b095b569ad81af4e96bce0de3372d0c4437 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 17 May 2023 18:30:08 +0200 Subject: [PATCH 2/2] neon: Refactor version checks --- packages/neon/neon/lib/src/pages/home.dart | 36 +++++++++------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/packages/neon/neon/lib/src/pages/home.dart b/packages/neon/neon/lib/src/pages/home.dart index 114fa770..fbfc6e84 100644 --- a/packages/neon/neon/lib/src/pages/home.dart +++ b/packages/neon/neon/lib/src/pages/home.dart @@ -60,30 +60,22 @@ class _HomePageState extends State { ...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; + final (supported, _) = switch (id) { + 'core' => await widget.account.client.core.isSupported(result.data), + 'news' => await widget.account.client.news.isSupported(), + 'notes' => await widget.account.client.notes.isSupported(result.data), + _ => (true, null), + }; + if (supported || !mounted) { + return; } - if (!(supported ?? true)) { - if (!mounted) { - return; - } - var name = AppLocalizations.of(context).appImplementationName(id); - if (name == '') { - name = id; - } - await _showProblem( - AppLocalizations.of(context).errorUnsupportedVersion(name), - ); + var name = AppLocalizations.of(context).appImplementationName(id); + if (name == '') { + name = id; } + await _showProblem( + AppLocalizations.of(context).errorUnsupportedVersion(name), + ); } catch (e, s) { debugPrint(e.toString()); debugPrint(s.toString());