diff --git a/Makefile b/Makefile index 1ec11c33..d3a7ec37 100644 --- a/Makefile +++ b/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) diff --git a/lib/domain/app/app_info.dart b/lib/domain/app/app_info.dart index 2ab036a4..8410b5d5 100644 --- a/lib/domain/app/app_info.dart +++ b/lib/domain/app/app_info.dart @@ -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 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 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, ); } } diff --git a/lib/features/about/view/about_page.dart b/lib/features/about/view/about_page.dart index 56f26f5c..98fbe248 100644 --- a/lib/features/about/view/about_page.dart +++ b/lib/features/about/view/about_page.dart @@ -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}", ), ], ), diff --git a/lib/features/common/app_update_notifier.dart b/lib/features/common/app_update_notifier.dart index 39bb7e3b..83038007 100644 --- a/lib/features/common/app_update_notifier.dart +++ b/lib/features/common/app_update_notifier.dart @@ -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; } diff --git a/lib/features/common/new_version_dialog.dart b/lib/features/common/new_version_dialog.dart index 6e04a066..5c46de47 100644 --- a/lib/features/common/new_version_dialog.dart +++ b/lib/features/common/new_version_dialog.dart @@ -62,7 +62,7 @@ class NewVersionDialog extends HookConsumerWidget { style: theme.textTheme.bodySmall, ), TextSpan( - text: newVersion.fullVersion, + text: newVersion.presentVersion, style: theme.textTheme.labelMedium, ), ], diff --git a/lib/features/home/view/home_page.dart b/lib/features/home/view/home_page.dart index 771abd23..ee9dceee 100644 --- a/lib/features/home/view/home_page.dart +++ b/lib/features/home/view/home_page.dart @@ -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(