Fix updater prerelease handling

This commit is contained in:
Nutcake 2023-10-12 19:17:53 +02:00
parent fca7ffda93
commit c5c4d446f3
3 changed files with 13 additions and 9 deletions

View file

@ -6,9 +6,10 @@ class GithubApi {
static const baseUrl = "https://api.github.com"; static const baseUrl = "https://api.github.com";
static Future<String> getLatestTagName() async { static Future<String> getLatestTagName() async {
final response = await http.get(Uri.parse("$baseUrl/repos/Nutcake/ReCon/releases/latest")); final response = await http.get(Uri.parse("$baseUrl/repos/Nutcake/ReCon/releases?per_page=1"));
if (response.statusCode != 200) return ""; if (response.statusCode != 200) return "";
final body = jsonDecode(response.body); final body = jsonDecode(response.body) as List;
return body["tag_name"] ?? ""; if (body.isEmpty) return "";
return body.first["tag_name"] ?? "";
} }
} }

View file

@ -1,12 +1,13 @@
class SemVer { class SemVer {
static final RegExp _versionMatcher = RegExp(r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"); static final RegExp _versionMatcher = RegExp(r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$");
static final RegExp _characterFilter = RegExp(r"[a-z]"); static final RegExp _characterFilter = RegExp(r"^[a-zA-Z]+");
final int major; final int major;
final int minor; final int minor;
final int patch; final int patch;
final String? label;
SemVer({required this.major, required this.minor, required this.patch}); SemVer({required this.major, required this.minor, required this.patch, this.label});
factory SemVer.fromString(String str) { factory SemVer.fromString(String str) {
str = str.replaceAll(_characterFilter, ""); str = str.replaceAll(_characterFilter, "");
@ -19,6 +20,7 @@ class SemVer {
major: int.parse(match.group(1)!), major: int.parse(match.group(1)!),
minor: int.parse(match.group(2) ?? "0"), minor: int.parse(match.group(2) ?? "0"),
patch: int.parse(match.group(3) ?? "0"), patch: int.parse(match.group(3) ?? "0"),
label: match.group(4),
); );
} }
@ -38,7 +40,7 @@ class SemVer {
@override @override
String toString() { String toString() {
return "$major.$minor.$patch"; return "$major.$minor.$patch${label == null ? "" : "-$label"}";
} }
@override @override
@ -48,10 +50,11 @@ class SemVer {
runtimeType == other.runtimeType && runtimeType == other.runtimeType &&
major == other.major && major == other.major &&
minor == other.minor && minor == other.minor &&
patch == other.patch; patch == other.patch &&
label == other.label;
@override @override
int get hashCode => major.hashCode ^ minor.hashCode ^ patch.hashCode; int get hashCode => major.hashCode ^ minor.hashCode ^ patch.hashCode ^ label.hashCode;
bool operator >(SemVer other) { bool operator >(SemVer other) {
if (major > other.major || (major == other.major && minor > other.minor) || (major == other.major && minor == other.minor && patch > other.patch)) { if (major > other.major || (major == other.major && minor > other.minor) || (major == other.major && minor == other.minor && patch > other.patch)) {

View file

@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts # In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix. # of the product and file versions while build-number is used as the build suffix.
version: 0.9.1+1 version: 0.9.2-beta+1
environment: environment:
sdk: '>=3.0.1' sdk: '>=3.0.1'