diff --git a/Makefile b/Makefile index abce864e..1ec11c33 100644 --- a/Makefile +++ b/Makefile @@ -33,11 +33,11 @@ translate: android-release: android-apk-release -android-apk-release: +android-apk-release: flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi --target $(TARGET) android-aab-release: - flutter build appbundle --target $(TARGET) + flutter build appbundle --target $(TARGET) --dart-define release=google-play windows-release: flutter_distributor package --platform windows --targets exe --skip-clean --build-target $(TARGET) diff --git a/lib/data/repository/app_repository_impl.dart b/lib/data/repository/app_repository_impl.dart index ad937964..e599ac3f 100644 --- a/lib/data/repository/app_repository_impl.dart +++ b/lib/data/repository/app_repository_impl.dart @@ -22,20 +22,25 @@ class AppRepositoryImpl name: packageInfo.appName, version: packageInfo.version, buildNumber: packageInfo.buildNumber, + release: Release.read(), installerMedia: packageInfo.installerStore, operatingSystem: Platform.operatingSystem, environment: environment, ); } + // TODO add market-specific update checking @override TaskEither getLatestVersion({ bool includePreReleases = false, + Release release = Release.general, }) { return exceptionHandler( () async { + if (!release.allowCustomUpdateChecker) { + throw Exception("custom update checkers are not supported"); + } final response = await dio.get(Constants.githubReleasesApiUrl); - if (response.statusCode != 200 || response.data == null) { loggy.warning("failed to fetch latest version info"); return left(const AppFailure.unexpected()); diff --git a/lib/domain/app/app_info.dart b/lib/domain/app/app_info.dart index db7e3233..2ab036a4 100644 --- a/lib/domain/app/app_info.dart +++ b/lib/domain/app/app_info.dart @@ -13,6 +13,7 @@ class AppInfo with _$AppInfo { required String name, required String version, required String buildNumber, + required Release release, String? installerMedia, required String operatingSystem, required Environment environment, diff --git a/lib/domain/environment.dart b/lib/domain/environment.dart index c223ad53..27b5b4c1 100644 --- a/lib/domain/environment.dart +++ b/lib/domain/environment.dart @@ -1,4 +1,23 @@ +import 'package:dartx/dartx.dart'; + enum Environment { prod, dev; } + +enum Release { + general("general"), + googlePlay("google-play"); + + const Release(this.key); + + final String key; + + bool get allowCustomUpdateChecker => this == general; + + static Release read() => + Release.values.firstOrNullWhere( + (e) => e.key == const String.fromEnvironment("release"), + ) ?? + Release.general; +} diff --git a/lib/features/about/view/about_page.dart b/lib/features/about/view/about_page.dart index 0c327088..56f26f5c 100644 --- a/lib/features/about/view/about_page.dart +++ b/lib/features/about/view/about_page.dart @@ -88,19 +88,20 @@ class AboutPage extends HookConsumerWidget { ); }, ), - ListTile( - title: Text(t.about.checkForUpdate), - trailing: appUpdate.isLoading - ? const SizedBox( - width: 24, - height: 24, - child: CircularProgressIndicator(), - ) - : const Icon(Icons.update), - onTap: () { - ref.invalidate(appUpdateNotifierProvider); - }, - ), + if (appInfo.release.allowCustomUpdateChecker) + ListTile( + title: Text(t.about.checkForUpdate), + trailing: appUpdate.isLoading + ? const SizedBox( + width: 24, + height: 24, + child: CircularProgressIndicator(), + ) + : const Icon(Icons.update), + onTap: () { + ref.invalidate(appUpdateNotifierProvider); + }, + ), ListTile( title: Text(t.settings.general.openWorkingDir), trailing: const Icon(Icons.arrow_outward_outlined), diff --git a/lib/features/common/app_update_notifier.dart b/lib/features/common/app_update_notifier.dart index 5f4abd5b..39bb7e3b 100644 --- a/lib/features/common/app_update_notifier.dart +++ b/lib/features/common/app_update_notifier.dart @@ -11,7 +11,15 @@ class AppUpdateNotifier extends _$AppUpdateNotifier with AppLogger { @override Future build() async { loggy.debug("checking for update"); - final currentVersion = ref.watch(appInfoProvider).version; + final appInfo = ref.watch(appInfoProvider); + // TODO use market-specific update checkers + if (!appInfo.release.allowCustomUpdateChecker) { + loggy.debug( + "custom update checkers are not allowed for [${appInfo.release.name}] release", + ); + return null; + } + final currentVersion = appInfo.version; return ref .watch(appRepositoryProvider) .getLatestVersion(includePreReleases: true) @@ -27,7 +35,8 @@ class AppUpdateNotifier extends _$AppUpdateNotifier with AppLogger { return remote; } loggy.info( - "already using latest version[$currentVersion], remote: $remote"); + "already using latest version[$currentVersion], remote: $remote", + ); return null; }, ).run();