checkForUpdate method

FutureOr<Release?> checkForUpdate({
  1. OnRelease? onNewRelease,
  2. Release? currentRelease,
})

Checks if there's a new version to update and returns it, otherwise returns null.

  • onNewRelease is called when a new release is available.

Implementation

FutureOr<Release?> checkForUpdate(
    {OnRelease? onNewRelease, Release? currentRelease}) async {
  final realCurrentRelease = await this.currentRelease;

  if (currentRelease == null) {
    currentRelease = realCurrentRelease;
  } else if (realCurrentRelease == null ||
      currentRelease.compareTo(realCurrentRelease) > 0) {
    currentRelease = realCurrentRelease;
  }

  var lastRelease = await this.lastRelease;
  if (lastRelease == null) return null;

  var newRelease =
      currentRelease == null || lastRelease.compareTo(currentRelease) > 0;

  if (newRelease) {
    if (onNewRelease != null) {
      try {
        onNewRelease(lastRelease);
      } catch (e, s) {
        print(e);
        print(s);
      }
    }

    return lastRelease;
  } else {
    return null;
  }
}