From cd7f4f705298b8da7155cb2d008955b2bdb6a1eb Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 5 May 2024 17:23:54 -0700 Subject: [PATCH] Convert runSheetOnWindow to async. --- .../Accounts/AccountsAddCloudKitWindowController.swift | 7 +++---- .../Accounts/AccountsPreferencesViewController.swift | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift b/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift index 388e7af20..fdb0797d8 100644 --- a/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift @@ -17,7 +17,7 @@ enum AccountsAddCloudKitWindowControllerError: LocalizedError { } } -class AccountsAddCloudKitWindowController: NSWindowController { +final class AccountsAddCloudKitWindowController: NSWindowController { private weak var hostWindow: NSWindow? @@ -31,9 +31,9 @@ class AccountsAddCloudKitWindowController: NSWindowController { // MARK: API - func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) { + func runSheetOnWindow(_ hostWindow: NSWindow) async -> NSApplication.ModalResponse { self.hostWindow = hostWindow - hostWindow.beginSheet(window!, completionHandler: completion) + return await hostWindow.beginSheet(window!) } // MARK: Actions @@ -51,5 +51,4 @@ class AccountsAddCloudKitWindowController: NSWindowController { let _ = AccountManager.shared.createAccount(type: .cloudKit) hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) } - } diff --git a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift index d2b449b2f..0b7591905 100644 --- a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift +++ b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift @@ -159,11 +159,14 @@ extension AccountsPreferencesViewController: AccountsPreferencesAddAccountDelega addAccountWindowController = accountsAddLocalWindowController case .cloudKit: let accountsAddCloudKitWindowController = AccountsAddCloudKitWindowController() - accountsAddCloudKitWindowController.runSheetOnWindow(self.view.window!) { response in + + Task { @MainActor in + let response = await accountsAddCloudKitWindowController.runSheetOnWindow(self.view.window!) if response == NSApplication.ModalResponse.OK { self.tableView.reloadData() } } + addAccountWindowController = accountsAddCloudKitWindowController case .feedbin: let accountsFeedbinWindowController = AccountsFeedbinWindowController()