checkForUpdates method

Future<ManualUpdateCheckResult> checkForUpdates()

Checks for updates for an explicit user action and returns a typed result.

Implementation

Future<ManualUpdateCheckResult> checkForUpdates() async {
  try {
    await checkVersion();
  } on Object catch (error, stackTrace) {
    _state = UpdateFailed(error, report: _reportFromStateOrBuild(error));
    notifyListeners();
    return ManualUpdateCheckFailed(error, stackTrace);
  }

  final currentState = state;
  if (currentState is UpdateAvailable) {
    return ManualUpdateCheckAvailable(
      descriptor: currentState.descriptor,
      mandatory: currentState.mandatory,
    );
  }

  if (currentState is UpdateFreshInstallRequired) {
    return ManualUpdateCheckFreshInstallRequired(
      descriptor: currentState.descriptor,
      freshInstall: currentState.freshInstall,
      mandatory: currentState.mandatory,
    );
  }

  if (currentState is UpdateBlockedBySupportPolicy) {
    return ManualUpdateCheckBlockedBySupportPolicy(
      descriptor: currentState.descriptor,
      supportPolicy: currentState.supportPolicy,
    );
  }

  if (currentState is UpdateFailed) {
    return ManualUpdateCheckFailed(currentState.error, StackTrace.current);
  }

  return const ManualUpdateCheckUpToDate();
}