refactor: version presentation
This commit is contained in:
@@ -21,6 +21,10 @@ class AppInfo with _$AppInfo {
|
||||
|
||||
String get userAgent => "HiddifyNext/$version ($operatingSystem)";
|
||||
|
||||
String get presentVersion => environment == Environment.prod
|
||||
? version
|
||||
: "$version ${environment.name}";
|
||||
|
||||
factory AppInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$AppInfoFromJson(json);
|
||||
}
|
||||
@@ -36,17 +40,31 @@ class RemoteVersionInfo with _$RemoteVersionInfo {
|
||||
required String releaseTag,
|
||||
required bool preRelease,
|
||||
required DateTime publishedAt,
|
||||
required Environment flavor,
|
||||
}) = _RemoteVersionInfo;
|
||||
|
||||
String get fullVersion =>
|
||||
buildNumber.isBlank ? version : "$version+$buildNumber";
|
||||
String get presentVersion =>
|
||||
flavor == Environment.prod ? version : "$version ${flavor.name}";
|
||||
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static RemoteVersionInfo fromJson(Map<String, dynamic> json) {
|
||||
final fullTag = json['tag_name'] as String;
|
||||
final fullVersion = fullTag.removePrefix("v").split("-").first.split("+");
|
||||
final version = fullVersion.first;
|
||||
final buildNumber = fullVersion.elementAtOrElse(1, (index) => "");
|
||||
var version = fullVersion.first;
|
||||
var buildNumber = fullVersion.elementAtOrElse(1, (index) => "");
|
||||
var flavor = Environment.prod;
|
||||
for (final env in Environment.values) {
|
||||
final suffix = ".${env.name}";
|
||||
if (version.endsWith(suffix)) {
|
||||
version = version.removeSuffix(suffix);
|
||||
flavor = env;
|
||||
break;
|
||||
} else if (buildNumber.endsWith(suffix)) {
|
||||
buildNumber = buildNumber.removeSuffix(suffix);
|
||||
flavor = env;
|
||||
break;
|
||||
}
|
||||
}
|
||||
final preRelease = json["prerelease"] as bool;
|
||||
final publishedAt = DateTime.parse(json["published_at"] as String);
|
||||
return RemoteVersionInfo(
|
||||
@@ -55,6 +73,7 @@ class RemoteVersionInfo with _$RemoteVersionInfo {
|
||||
releaseTag: fullTag,
|
||||
preRelease: preRelease,
|
||||
publishedAt: publishedAt,
|
||||
flavor: flavor,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user