diff --git a/AltStoreCore/Extensions/AltStore+Async.swift b/AltStoreCore/Extensions/AltStore+Async.swift index 5e247b2b..4a66c1c6 100644 --- a/AltStoreCore/Extensions/AltStore+Async.swift +++ b/AltStoreCore/Extensions/AltStore+Async.swift @@ -59,3 +59,39 @@ public extension NSManagedObjectContext return result } } + +public extension UIViewController +{ + @MainActor + func presentAlert(title: String, message: String, action: UIAlertAction? = nil) async + { + let action = action ?? .ok + + await withCheckedContinuation { (continuation: CheckedContinuation) in + let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: action.title, style: action.style) { _ in + continuation.resume() + }) + + self.present(alertController, animated: true) + } + } + + @MainActor + func presentConfirmationAlert(title: String, message: String, primaryAction: UIAlertAction, cancelAction: UIAlertAction? = nil) async throws + { + let cancelAction = cancelAction ?? .cancel + + try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: cancelAction.title, style: cancelAction.style) { _ in + continuation.resume(throwing: CancellationError()) + }) + alertController.addAction(UIAlertAction(title: primaryAction.title, style: primaryAction.style) { _ in + continuation.resume() + }) + + self.present(alertController, animated: true) + } + } +}