Skip to content

Commit

Permalink
Add new option disableOptionalUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedLSayed9 committed Oct 30, 2024
1 parent 54e4869 commit 85f1cb6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down
9 changes: 9 additions & 0 deletions lib/src/upgrade_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class UpgraderState {
this.languageCodeOverride,
this.messages,
this.minAppVersion,
this.disableOptionalUpdates = false,
this.packageInfo,
required this.upgraderDevice,
required this.upgraderOS,
Expand Down Expand Up @@ -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;

Expand All @@ -87,6 +93,7 @@ class UpgraderState {
String? languageCodeOverride,
UpgraderMessages? messages,
Version? minAppVersion,
bool? disableOptionalUpdates,
PackageInfo? packageInfo,
UpgraderDevice? upgraderDevice,
UpgraderOS? upgraderOS,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/upgrader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Upgrader with WidgetsBindingObserver {
String? languageCode,
UpgraderMessages? messages,
String? minAppVersion,
bool disableOptionalUpdates = false,
UpgraderStoreController? storeController,
UpgraderDevice? upgraderDevice,
UpgraderOS? upgraderOS,
Expand All @@ -71,6 +72,7 @@ class Upgrader with WidgetsBindingObserver {
messages: messages,
minAppVersion:
parseVersion(minAppVersion, 'minAppVersion', debugLogging),
disableOptionalUpdates: disableOptionalUpdates,
upgraderDevice: upgraderDevice ?? UpgraderDevice(),
upgraderOS: upgraderOS ?? UpgraderOS(),
),
Expand Down Expand Up @@ -303,7 +305,7 @@ class Upgrader with WidgetsBindingObserver {
rv = false;
} else if (isBlocked) {
rv = true;
} else if (isTooSoon() || alreadyIgnoredThisVersion()) {
} else if (state.disableOptionalUpdates || isTooSoon() || alreadyIgnoredThisVersion()) {
rv = false;
}
if (state.debugLogging) {
Expand Down

0 comments on commit 85f1cb6

Please sign in to comment.