refactor: version presentation
This commit is contained in:
7
Makefile
7
Makefile
@@ -21,6 +21,7 @@ else
|
|||||||
FLAVOR=dev
|
FLAVOR=dev
|
||||||
endif
|
endif
|
||||||
TARGET=lib/main_$(FLAVOR).dart
|
TARGET=lib/main_$(FLAVOR).dart
|
||||||
|
DISTRIBUTOR_ARGS=$(DISTRIBUTOR_ARGS)
|
||||||
|
|
||||||
get:
|
get:
|
||||||
flutter pub get
|
flutter pub get
|
||||||
@@ -40,13 +41,13 @@ android-aab-release:
|
|||||||
flutter build appbundle --target $(TARGET) --dart-define release=google-play
|
flutter build appbundle --target $(TARGET) --dart-define release=google-play
|
||||||
|
|
||||||
windows-release:
|
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:
|
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:
|
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
|
ios-release: #not tested
|
||||||
flutter_distributor package --platform ios --targets ipa --build-export-options-plist ios/exportOptions.plist --build-target $(TARGET)
|
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 userAgent => "HiddifyNext/$version ($operatingSystem)";
|
||||||
|
|
||||||
|
String get presentVersion => environment == Environment.prod
|
||||||
|
? version
|
||||||
|
: "$version ${environment.name}";
|
||||||
|
|
||||||
factory AppInfo.fromJson(Map<String, dynamic> json) =>
|
factory AppInfo.fromJson(Map<String, dynamic> json) =>
|
||||||
_$AppInfoFromJson(json);
|
_$AppInfoFromJson(json);
|
||||||
}
|
}
|
||||||
@@ -36,17 +40,31 @@ class RemoteVersionInfo with _$RemoteVersionInfo {
|
|||||||
required String releaseTag,
|
required String releaseTag,
|
||||||
required bool preRelease,
|
required bool preRelease,
|
||||||
required DateTime publishedAt,
|
required DateTime publishedAt,
|
||||||
|
required Environment flavor,
|
||||||
}) = _RemoteVersionInfo;
|
}) = _RemoteVersionInfo;
|
||||||
|
|
||||||
String get fullVersion =>
|
String get presentVersion =>
|
||||||
buildNumber.isBlank ? version : "$version+$buildNumber";
|
flavor == Environment.prod ? version : "$version ${flavor.name}";
|
||||||
|
|
||||||
// ignore: prefer_constructors_over_static_methods
|
// ignore: prefer_constructors_over_static_methods
|
||||||
static RemoteVersionInfo fromJson(Map<String, dynamic> json) {
|
static RemoteVersionInfo fromJson(Map<String, dynamic> json) {
|
||||||
final fullTag = json['tag_name'] as String;
|
final fullTag = json['tag_name'] as String;
|
||||||
final fullVersion = fullTag.removePrefix("v").split("-").first.split("+");
|
final fullVersion = fullTag.removePrefix("v").split("-").first.split("+");
|
||||||
final version = fullVersion.first;
|
var version = fullVersion.first;
|
||||||
final buildNumber = fullVersion.elementAtOrElse(1, (index) => "");
|
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 preRelease = json["prerelease"] as bool;
|
||||||
final publishedAt = DateTime.parse(json["published_at"] as String);
|
final publishedAt = DateTime.parse(json["published_at"] as String);
|
||||||
return RemoteVersionInfo(
|
return RemoteVersionInfo(
|
||||||
@@ -55,6 +73,7 @@ class RemoteVersionInfo with _$RemoteVersionInfo {
|
|||||||
releaseTag: fullTag,
|
releaseTag: fullTag,
|
||||||
preRelease: preRelease,
|
preRelease: preRelease,
|
||||||
publishedAt: publishedAt,
|
publishedAt: publishedAt,
|
||||||
|
flavor: flavor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class AboutPage extends HookConsumerWidget {
|
|||||||
switch (next) {
|
switch (next) {
|
||||||
case AsyncData(value: final remoteVersion?):
|
case AsyncData(value: final remoteVersion?):
|
||||||
await NewVersionDialog(
|
await NewVersionDialog(
|
||||||
appInfo.version,
|
appInfo.presentVersion,
|
||||||
remoteVersion,
|
remoteVersion,
|
||||||
canIgnore: false,
|
canIgnore: false,
|
||||||
).show(context);
|
).show(context);
|
||||||
@@ -59,7 +59,7 @@ class AboutPage extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
const Gap(4),
|
const Gap(4),
|
||||||
Text(
|
Text(
|
||||||
"${t.about.version} ${appInfo.version}",
|
"${t.about.version} ${appInfo.presentVersion}",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ class AppUpdateNotifier extends _$AppUpdateNotifier with AppLogger {
|
|||||||
throw l;
|
throw l;
|
||||||
},
|
},
|
||||||
(remote) {
|
(remote) {
|
||||||
if (remote.version.replaceAll(".dev", "").compareTo(currentVersion) >
|
if (remote.version.compareTo(currentVersion) > 0) {
|
||||||
0) {
|
|
||||||
loggy.info("new version available: $remote");
|
loggy.info("new version available: $remote");
|
||||||
return remote;
|
return remote;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class NewVersionDialog extends HookConsumerWidget {
|
|||||||
style: theme.textTheme.bodySmall,
|
style: theme.textTheme.bodySmall,
|
||||||
),
|
),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: newVersion.fullVersion,
|
text: newVersion.presentVersion,
|
||||||
style: theme.textTheme.labelMedium,
|
style: theme.textTheme.labelMedium,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:hiddify/core/core_providers.dart';
|
import 'package:hiddify/core/core_providers.dart';
|
||||||
import 'package:hiddify/core/router/router.dart';
|
import 'package:hiddify/core/router/router.dart';
|
||||||
import 'package:hiddify/domain/environment.dart';
|
|
||||||
import 'package:hiddify/domain/failures.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/active_profile_notifier.dart';
|
||||||
import 'package:hiddify/features/common/active_profile/has_any_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 t = ref.watch(translationsProvider);
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
final appInfo = ref.watch(appInfoProvider);
|
final version = ref.watch(appInfoProvider).presentVersion;
|
||||||
final version = appInfo.version +
|
|
||||||
(appInfo.environment == Environment.prod
|
|
||||||
? ""
|
|
||||||
: " ${appInfo.environment.name}");
|
|
||||||
if (version.isBlank) return const SizedBox();
|
if (version.isBlank) return const SizedBox();
|
||||||
|
|
||||||
return Semantics(
|
return Semantics(
|
||||||
|
|||||||
Reference in New Issue
Block a user