recoverPendingInstall method

Future<void> recoverPendingInstall()

Recovers a pending native install marker from the app-owned store.

Implementation

Future<void> recoverPendingInstall() async {
  final store = recoveryStore;
  if (store == null) {
    return;
  }

  final UpdateInstallRecoveryMarker? marker;
  try {
    marker = await store.readPendingInstall(channel: channel);
  } on Object catch (error) {
    _diagnosticsRecorder.record(
      stage: UpdateDiagnosticStage.install,
      level: UpdateDiagnosticLevel.warning,
      message: "Recovery marker read failed.",
      error: error,
    );
    notifyListeners();
    return;
  }

  if (marker == null) {
    return;
  }

  _diagnosticsRecorder
    ..clear()
    ..record(
      stage: UpdateDiagnosticStage.install,
      level: UpdateDiagnosticLevel.warning,
      message: "Pending install marker found for "
          "${marker.updateVersion ?? "unknown update"}.",
    );

  final DesktopVersionInfo? currentVersion;
  try {
    currentVersion = await currentVersionInfo();
  } on Object catch (error) {
    _failRecoveredInstall(
      marker,
      StateError("Could not verify completed install after relaunch."),
      message: "Could not verify completed install after relaunch.",
      appVersion: marker.appVersion,
      error: error,
    );
    return;
  }

  if (currentVersion == null) {
    _failRecoveredInstall(
      marker,
      StateError("Could not verify completed install after relaunch."),
      message: "Could not verify completed install after relaunch.",
      appVersion: marker.appVersion,
    );
    return;
  }

  final currentAppVersion = _formatVersionInfo(currentVersion);
  _currentAppVersion = currentAppVersion ?? marker.appVersion;
  if (_matchesRecoveredTarget(currentVersion, marker)) {
    await _clearPendingRecoveryMarker();
    _state = const UpdateIdle();
    notifyListeners();
    return;
  }

  _failRecoveredInstall(
    marker,
    StateError("Pending install did not complete after relaunch."),
    message: "Pending install did not complete after relaunch.",
    appVersion: _currentAppVersion,
  );
}