immich/mobile/lib/utils/semver.dart
Brandon Wees 23a34bee6f
feat: improved update messaging on app bar server info (#22938)
* feat: improved update messaging on app bar server info

* chore: message improvements

* chore: failed to fetch version error message

* feat: open latest release when tapping "Update" on server out of date message

* fix: text alignment states

* chore: code review updates

* Apply suggestion from @alextran1502

Co-authored-by: Alex <alex.tran1502@gmail.com>

* Apply suggestion from @alextran1502

Co-authored-by: Alex <alex.tran1502@gmail.com>

* chore: lots of rework of the version checking code to be cleaner

Added a semver utility class to simplify comparisons, broke the update notification logic into own widget, reworked view construction and colors.

* fix: show warnign without having to tap on app bar icon

* chore: colors

---------

Co-authored-by: Alex <alex.tran1502@gmail.com>
2025-10-20 21:13:31 +00:00

60 lines
1.4 KiB
Dart

class SemVer {
final int major;
final int minor;
final int patch;
const SemVer({required this.major, required this.minor, required this.patch});
@override
String toString() {
return '$major.$minor.$patch';
}
SemVer copyWith({int? major, int? minor, int? patch}) {
return SemVer(major: major ?? this.major, minor: minor ?? this.minor, patch: patch ?? this.patch);
}
factory SemVer.fromString(String version) {
final parts = version.split('.');
return SemVer(major: int.parse(parts[0]), minor: int.parse(parts[1]), patch: int.parse(parts[2]));
}
bool operator >(SemVer other) {
if (major != other.major) {
return major > other.major;
}
if (minor != other.minor) {
return minor > other.minor;
}
return patch > other.patch;
}
bool operator <(SemVer other) {
if (major != other.major) {
return major < other.major;
}
if (minor != other.minor) {
return minor < other.minor;
}
return patch < other.patch;
}
bool operator >=(SemVer other) {
return this > other || this == other;
}
bool operator <=(SemVer other) {
return this < other || this == other;
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is SemVer && other.major == major && other.minor == minor && other.patch == patch;
}
@override
int get hashCode => major.hashCode ^ minor.hashCode ^ patch.hashCode;
}