retryInstallAfterMacOSHelperApproval method

Future<void> retryInstallAfterMacOSHelperApproval()

Recovers an approval-denied macOS handoff, stages a fresh verified artifact, and retries the install.

The retry proceeds only when the authenticated helper confirms that the prior transaction is absent or ended without activating the update.

Implementation

Future<void> retryInstallAfterMacOSHelperApproval() async {
  _beginInstallAttempt();
  try {
    final transactionId = _approvalRetryTransactionId;
    if (transactionId == null) {
      throw StateError("No macOS approval retry is pending.");
    }
    final marker = await recoveryStore.readPendingInstall(channel: channel);
    if (marker == null || marker.transactionId != transactionId) {
      throw StateError("The pending install receipt changed.");
    }
    final recovery = DesktopUpdaterPlatform.instance.nativeInstallRecovery;
    if (recovery is! QueryAndRecoverNativeInstallRecovery) {
      throw StateError("Authenticated native install status is unavailable.");
    }
    final status = await recovery.queryInstallTransaction(transactionId);
    if (!_isAuthenticatedSafeRetryStatus(status, transactionId)) {
      throw StateError(
        "The previous install transaction is not verified as inactive.",
      );
    }
    if (!await _cleanupRecoveredOwnedStage(marker)) {
      throw StateError("The previous install stage could not be cleaned.");
    }
    await _clearRetryReceipt(marker);
    _approvalRetryTransactionId = null;

    await _checkVersion(duringApprovalRetry: true);
    if (_activeDescriptor == null || _activeCheckResult == null) {
      throw StateError("No update is available to retry.");
    }
    await _downloadUpdate(duringApprovalRetry: true);
    await _restartApp();
  } on Object catch (error) {
    if (_approvalRetryTransactionId == null) {
      _state = UpdateFailed(
        error,
        report: _buildProblemReport(
          error,
          updateVersion: _activeDescriptor?.version,
        ),
      );
      notifyListeners();
    }
    rethrow;
  } finally {
    _endInstallAttempt();
  }
}