From 45f68ac1fee117febfd838bd540854191bcbe36b Mon Sep 17 00:00:00 2001 From: Ahmed Elsayed Date: Thu, 31 Oct 2024 01:58:45 +0300 Subject: [PATCH] Add new option `disableOptionalUpdates` --- README.md | 2 ++ lib/src/upgrade_state.dart | 9 +++++++++ lib/src/upgrader.dart | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 983ab974..36d55efd 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,8 @@ The `Upgrader` class can be customized by setting parameters in the constructor, * languageCode: the language code that will override the system locale, which defaults to ```null``` * messages: optional localized messages used for display in `upgrader` * minAppVersion: the minimum app version supported by this app. Earlier versions of this app will be forced to update to the current version. It should be a valid version string like this: ```2.0.13```. Overrides any minimum app version from UpgraderStore. Defaults to ```null```. +* disableOptionalUpdates: If set to `true`, this flag will disable optional app updates for the current version. + When disabled, only mandatory updates (those below minimum app version) will be prompted to the user. Defaults to `false`. * storeController: a controller that provides the store details for each platform, defaults to `UpgraderStoreController()`. * upgraderDevice: an abstraction of the device_info details which is used for the OS version, defaults to `UpgraderDevice()`. * upgraderOS: information on which OS this code is running on, defaults to `UpgraderOS()`. diff --git a/lib/src/upgrade_state.dart b/lib/src/upgrade_state.dart index 75a5e282..ca32a255 100644 --- a/lib/src/upgrade_state.dart +++ b/lib/src/upgrade_state.dart @@ -23,6 +23,7 @@ class UpgraderState { this.languageCodeOverride, this.messages, this.minAppVersion, + this.disableOptionalUpdates = false, this.packageInfo, required this.upgraderDevice, required this.upgraderOS, @@ -62,6 +63,11 @@ class UpgraderState { /// app version from UpgraderStore. Optional. final Version? minAppVersion; + /// If set to `true`, this flag will disable optional app updates for the current version. + /// When disabled, only mandatory updates (those below minimum app version) will be + /// prompted to the user. Defaults to `false`. + final bool disableOptionalUpdates; + /// The app package metadata information. final PackageInfo? packageInfo; @@ -87,6 +93,7 @@ class UpgraderState { String? languageCodeOverride, UpgraderMessages? messages, Version? minAppVersion, + bool? disableOptionalUpdates, PackageInfo? packageInfo, UpgraderDevice? upgraderDevice, UpgraderOS? upgraderOS, @@ -104,6 +111,7 @@ class UpgraderState { languageCodeOverride: languageCodeOverride ?? this.languageCodeOverride, messages: messages ?? this.messages, minAppVersion: minAppVersion ?? this.minAppVersion, + disableOptionalUpdates: disableOptionalUpdates ?? this.disableOptionalUpdates, packageInfo: packageInfo ?? this.packageInfo, upgraderDevice: upgraderDevice ?? this.upgraderDevice, upgraderOS: upgraderOS ?? this.upgraderOS, @@ -134,6 +142,7 @@ class UpgraderState { languageCodeOverride == true ? null : this.languageCodeOverride, messages: messages == true ? null : this.messages, minAppVersion: minAppVersion == true ? null : this.minAppVersion, + disableOptionalUpdates: disableOptionalUpdates, packageInfo: packageInfo == true ? null : this.packageInfo, upgraderDevice: upgraderDevice, upgraderOS: upgraderOS, diff --git a/lib/src/upgrader.dart b/lib/src/upgrader.dart index 27dfbbf0..c254964a 100644 --- a/lib/src/upgrader.dart +++ b/lib/src/upgrader.dart @@ -55,6 +55,7 @@ class Upgrader with WidgetsBindingObserver { String? languageCode, UpgraderMessages? messages, String? minAppVersion, + bool disableOptionalUpdates = false, UpgraderStoreController? storeController, UpgraderDevice? upgraderDevice, UpgraderOS? upgraderOS, @@ -71,6 +72,7 @@ class Upgrader with WidgetsBindingObserver { messages: messages, minAppVersion: parseVersion(minAppVersion, 'minAppVersion', debugLogging), + disableOptionalUpdates: disableOptionalUpdates, upgraderDevice: upgraderDevice ?? UpgraderDevice(), upgraderOS: upgraderOS ?? UpgraderOS(), ), @@ -299,7 +301,7 @@ class Upgrader with WidgetsBindingObserver { bool rv = true; if (state.debugDisplayAlways || (state.debugDisplayOnce && !_hasAlerted)) { rv = true; - } else if (!isUpdateAvailable()) { + } else if (!isUpdateAvailable() || state.disableOptionalUpdates) { rv = false; } else if (isBlocked) { rv = true;