Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to pass in required update title, message, prompt. #446

Open
markclemonsaya opened this issue Sep 11, 2024 · 1 comment
Open

Comments

@markclemonsaya
Copy link

I would like the ability to customize the message based on an optional upgrade vs a required update.

Suggestion: update the Upgrader class to support a second UpgraderMessages param for forced updates.

class OptionalMessages extends UpgraderMessages;
class ForcedMessages extends UpgraderMessages;

Upgrader (
messages: OptionalMessages(),
forcedMessages: ForcedMessages(),
)

Update the determineMessages method to consider if the blocked method is true then return ForcedMessages.

@MoacirSchmidt
Copy link

You have to override "blocked" method

class AppUpgrader extends Upgrader {
  static final AppUpgrader _instance = AppUpgrader._internal();
  AppUpgrader._internal()
      : super(
          countryCode: 'BR',
          languageCode: 'pt',
          messages: AppUpgraderMessages(),
          durationUntilAlertAgain: const Duration(days: 1),
          debugDisplayAlways: true,
          debugLogging: true,
        );
  static AppUpgrader get instance => _instance;

  @override
  bool blocked() {
    return super.blocked() 
      || _isCriticalUpdate(AppUpgrader.instance.currentInstalledVersion, 
         AppUpgrader.instance.currentAppStoreVersion);
  }
}

and messages:

class AppUpgraderMessages extends UpgraderMessages {
  @override
  String get title => _isCriticalUpdate(
        AppUpgrader.instance.currentInstalledVersion,
        AppUpgrader.instance.currentAppStoreVersion,
      )
          ? 'Atualização Necessária'
          : 'Atualizar aplicativo?';
}

_isCriticalUpdate:

bool _isCriticalUpdate(String? currentInstalledVersion, String? currentAppStoreVersion) {
  Version installedVersion = Version.parse(currentInstalledVersion ?? '0.0.0');
  Version appStoreVersion = Version.parse(currentAppStoreVersion ?? '0.0.0');
  return (installedVersion.major != appStoreVersion.major || installedVersion.minor != appStoreVersion.minor);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants