-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1157 from nextcloud/refactor/nextcloud/version-check
- Loading branch information
Showing
17 changed files
with
228 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,42 @@ | ||
/// The result of a version check. | ||
typedef VersionSupported<T> = ({bool isSupported, T minimumVersion}); | ||
import 'package:meta/meta.dart'; | ||
import 'package:version/version.dart'; | ||
|
||
/// Holds the [versions], [minimumVersion] and [maximumMajor] of an app. | ||
@immutable | ||
class VersionCheck { | ||
/// Creates a new [VersionCheck]. | ||
/// | ||
/// If the [maximumMajor] is `null` the compatibility of the major of the [minimumVersion] is checked. | ||
VersionCheck({ | ||
required this.versions, | ||
required this.minimumVersion, | ||
required final int? maximumMajor, | ||
}) : maximumMajor = maximumMajor ?? minimumVersion.major; | ||
|
||
/// Current version of the app. | ||
final List<Version>? versions; | ||
|
||
/// Minimum version of the app. | ||
final Version minimumVersion; | ||
|
||
/// Maximum major version of the app. | ||
late final int maximumMajor; | ||
|
||
/// Whether the [versions] is allowed by the [minimumVersion] and [maximumMajor]. | ||
/// | ||
/// If [versions] is `null` or empty it is assumed that the app is supported. | ||
/// Only one of the [versions] has to be supported to return `true`. | ||
bool get isSupported { | ||
if (versions == null || versions!.isEmpty) { | ||
return true; | ||
} | ||
|
||
for (final version in versions!) { | ||
if (version >= minimumVersion && version.major <= maximumMajor) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:nextcloud/src/api/core.openapi.dart' as core; | ||
import 'package:nextcloud/src/api/notes.openapi.dart' as notes; | ||
import 'package:nextcloud/src/helpers/common.dart'; | ||
import 'package:version/version.dart'; | ||
|
||
/// API version of the notes app supported | ||
const supportedVersion = 1; | ||
/// Minimum API version of the notes app supported | ||
final minVersion = Version(1, 3, 0); | ||
|
||
// ignore: public_member_api_docs | ||
extension NotesVersionSupported on notes.Client { | ||
extension NotesVersionCheck on notes.Client { | ||
/// Check if the notes app version is supported by this client | ||
/// | ||
/// Also returns the supported API version number | ||
VersionSupported<int> isSupported( | ||
final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities, | ||
) => | ||
( | ||
isSupported: capabilities.capabilities.notesCapabilities?.notes.apiVersion | ||
?.map(Version.parse) | ||
.firstWhereOrNull((final version) => version.major == supportedVersion) != | ||
null, | ||
minimumVersion: supportedVersion, | ||
); | ||
VersionCheck getVersionCheck(final core.OcsGetCapabilitiesResponseApplicationJson_Ocs_Data capabilities) { | ||
final versions = capabilities.capabilities.notesCapabilities?.notes.apiVersion; | ||
return VersionCheck( | ||
versions: versions?.map(Version.parse).toList(), | ||
minimumVersion: minVersion, | ||
maximumMajor: null, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.