refactor: version presentation
This commit is contained in:
7
Makefile
7
Makefile
@@ -21,6 +21,7 @@ else
|
||||
FLAVOR=dev
|
||||
endif
|
||||
TARGET=lib/main_$(FLAVOR).dart
|
||||
DISTRIBUTOR_ARGS=$(DISTRIBUTOR_ARGS)
|
||||
|
||||
get:
|
||||
flutter pub get
|
||||
@@ -40,13 +41,13 @@ android-aab-release:
|
||||
flutter build appbundle --target $(TARGET) --dart-define release=google-play
|
||||
|
||||
windows-release:
|
||||
flutter_distributor package --platform windows --targets exe --skip-clean --build-target $(TARGET)
|
||||
flutter_distributor package --platform windows --targets exe $(DISTRIBUTOR_ARGS)
|
||||
|
||||
linux-release:
|
||||
flutter_distributor package --platform linux --targets appimage --skip-clean --build-target $(TARGET)
|
||||
flutter_distributor package --platform linux --targets appimage $(DISTRIBUTOR_ARGS)
|
||||
|
||||
macos-release:
|
||||
flutter_distributor package --platform macos --targets dmg --skip-clean --build-target $(TARGET)
|
||||
flutter_distributor package --platform macos --targets dmg $(DISTRIBUTOR_ARGS)
|
||||
|
||||
ios-release: #not tested
|
||||
flutter_distributor package --platform ios --targets ipa --build-export-options-plist ios/exportOptions.plist --build-target $(TARGET)
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class AboutPage extends HookConsumerWidget {
|
||||
switch (next) {
|
||||
case AsyncData(value: final remoteVersion?):
|
||||
await NewVersionDialog(
|
||||
appInfo.version,
|
||||
appInfo.presentVersion,
|
||||
remoteVersion,
|
||||
canIgnore: false,
|
||||
).show(context);
|
||||
@@ -59,7 +59,7 @@ class AboutPage extends HookConsumerWidget {
|
||||
),
|
||||
const Gap(4),
|
||||
Text(
|
||||
"${t.about.version} ${appInfo.version}",
|
||||
"${t.about.version} ${appInfo.presentVersion}",
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -29,8 +29,7 @@ class AppUpdateNotifier extends _$AppUpdateNotifier with AppLogger {
|
||||
throw l;
|
||||
},
|
||||
(remote) {
|
||||
if (remote.version.replaceAll(".dev", "").compareTo(currentVersion) >
|
||||
0) {
|
||||
if (remote.version.compareTo(currentVersion) > 0) {
|
||||
loggy.info("new version available: $remote");
|
||||
return remote;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class NewVersionDialog extends HookConsumerWidget {
|
||||
style: theme.textTheme.bodySmall,
|
||||
),
|
||||
TextSpan(
|
||||
text: newVersion.fullVersion,
|
||||
text: newVersion.presentVersion,
|
||||
style: theme.textTheme.labelMedium,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:hiddify/core/core_providers.dart';
|
||||
import 'package:hiddify/core/router/router.dart';
|
||||
import 'package:hiddify/domain/environment.dart';
|
||||
import 'package:hiddify/domain/failures.dart';
|
||||
import 'package:hiddify/features/common/active_profile/active_profile_notifier.dart';
|
||||
import 'package:hiddify/features/common/active_profile/has_any_profile_notifier.dart';
|
||||
@@ -88,11 +87,7 @@ class AppVersionLabel extends HookConsumerWidget {
|
||||
final t = ref.watch(translationsProvider);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
final appInfo = ref.watch(appInfoProvider);
|
||||
final version = appInfo.version +
|
||||
(appInfo.environment == Environment.prod
|
||||
? ""
|
||||
: " ${appInfo.environment.name}");
|
||||
final version = ref.watch(appInfoProvider).presentVersion;
|
||||
if (version.isBlank) return const SizedBox();
|
||||
|
||||
return Semantics(
|
||||
|
||||
Reference in New Issue
Block a user