Convert runSheetOnWindow to async.

This commit is contained in:
Brent Simmons 2024-05-05 17:23:54 -07:00
parent fba8c52b67
commit cd7f4f7052
2 changed files with 7 additions and 5 deletions

View File

@ -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)
}
}

View File

@ -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()