Convert to async/await.

This commit is contained in:
Brent Simmons committed 2025-11-10 12:02:01 -08:00
1 parent 143e5e1da8
commit 1b2e2d0513
6 files changed
+46 -33

No files matched your search

@@ -57,8 +57,7 @@ final class AddFeedWindowController : NSWindowController {
guard let window else {
return
}
hostWindow.beginSheet(window) { (returnCode: NSApplication.ModalResponse) -> Void in
}
hostWindow.beginSheet(window)
}
override func windowDidLoad() {
@@ -29,9 +29,10 @@ final class AddFolderWindowController : NSWindowController {
}
self.hostWindow = hostWindow
hostWindow.beginSheet(window) { (returnCode: NSApplication.ModalResponse) -> Void in
if returnCode == NSApplication.ModalResponse.OK {
self.addFolderIfNeeded()
Task { @MainActor in
let response = await hostWindow.beginSheet(window)
if response == .OK {
addFolderIfNeeded()
}
}
}
@@ -10,7 +10,6 @@ import Foundation
import Account
final class AccountsAddCloudKitWindowController: NSWindowController {
private weak var hostWindow: NSWindow?
convenience init() {
@@ -19,14 +18,14 @@ final class AccountsAddCloudKitWindowController: NSWindowController {
// MARK: - API
func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) {
func runSheetOnWindow(_ hostWindow: NSWindow) async -> NSApplication.ModalResponse? {
assert(window != nil)
guard let window else {
return
return nil
}
self.hostWindow = hostWindow
hostWindow.beginSheet(window, completionHandler: completion)
return await hostWindow.beginSheet(window)
}
// MARK: - Actions
@@ -10,7 +10,6 @@ import AppKit
import Account
final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate {
@IBOutlet weak var typeLabel: NSTextField!
@IBOutlet weak var nameTextField: NSTextField!
@IBOutlet weak var activeButton: NSButtonCell!
@@ -63,31 +62,35 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
}
@IBAction func credentials(_ sender: Any) {
guard let account = account else { return }
guard let account else {
return
}
guard let window = view.window else {
return
}
switch account.type {
case .feedbin:
let accountsFeedbinWindowController = AccountsFeedbinWindowController()
accountsFeedbinWindowController.account = account
accountsFeedbinWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsFeedbinWindowController
accountsFeedbinWindowController.account = account
accountsFeedbinWindowController.runSheetOnWindow(window)
case .inoreader, .bazQux, .theOldReader, .freshRSS:
let accountsReaderAPIWindowController = AccountsReaderAPIWindowController()
accountsWindowController = accountsReaderAPIWindowController
accountsReaderAPIWindowController.accountType = account.type
accountsReaderAPIWindowController.account = account
accountsReaderAPIWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsReaderAPIWindowController
break
accountsReaderAPIWindowController.runSheetOnWindow(window)
case .newsBlur:
let accountsNewsBlurWindowController = AccountsNewsBlurWindowController()
accountsNewsBlurWindowController.account = account
accountsNewsBlurWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsNewsBlurWindowController
accountsNewsBlurWindowController.account = account
accountsNewsBlurWindowController.runSheetOnWindow(window)
default:
break
}
}
}
@@ -49,13 +49,13 @@ final class AccountsFeedbinWindowController: NSWindowController {
// MARK: API
func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) {
func runSheetOnWindow(_ hostWindow: NSWindow) {
guard let window else {
return
}
self.hostWindow = hostWindow
hostWindow.beginSheet(window, completionHandler: completion)
hostWindow.beginSheet(window)
}
// MARK: - Actions
@@ -152,39 +152,50 @@ extension AccountsPreferencesViewController: NSTableViewDelegate {
}
extension AccountsPreferencesViewController: AccountsPreferencesAddAccountDelegate {
func presentSheetForAccount(_ accountType: AccountType) {
guard let window = view.window else {
return
}
switch accountType {
case .onMyMac:
let accountsAddLocalWindowController = AccountsAddLocalWindowController()
accountsAddLocalWindowController.runSheetOnWindow(self.view.window!)
addAccountWindowController = accountsAddLocalWindowController
accountsAddLocalWindowController.runSheetOnWindow(window)
case .cloudKit:
let accountsAddCloudKitWindowController = AccountsAddCloudKitWindowController()
accountsAddCloudKitWindowController.runSheetOnWindow(self.view.window!) { response in
if response == NSApplication.ModalResponse.OK {
self.tableView.reloadData()
addAccountWindowController = accountsAddCloudKitWindowController
Task { @MainActor in
if let response = await accountsAddCloudKitWindowController.runSheetOnWindow(window),
response == .OK {
tableView.reloadData()
}
}
addAccountWindowController = accountsAddCloudKitWindowController
case .feedbin:
let accountsFeedbinWindowController = AccountsFeedbinWindowController()
accountsFeedbinWindowController.runSheetOnWindow(self.view.window!)
addAccountWindowController = accountsFeedbinWindowController
accountsFeedbinWindowController.runSheetOnWindow(window)
case .freshRSS, .inoreader, .bazQux, .theOldReader:
let accountsReaderAPIWindowController = AccountsReaderAPIWindowController()
accountsReaderAPIWindowController.accountType = accountType
accountsReaderAPIWindowController.runSheetOnWindow(self.view.window!)
addAccountWindowController = accountsReaderAPIWindowController
accountsReaderAPIWindowController.accountType = accountType
accountsReaderAPIWindowController.runSheetOnWindow(window)
case .feedly:
let addAccount = OAuthAccountAuthorizationOperation(accountType: .feedly)
addAccount.delegate = self
addAccount.presentationAnchor = self.view.window!
addAccount.presentationAnchor = window
runAwaitingFeedlyLoginAlertModal(forLifetimeOf: addAccount)
MainThreadOperationQueue.shared.add(addAccount)
case .newsBlur:
let accountsNewsBlurWindowController = AccountsNewsBlurWindowController()
accountsNewsBlurWindowController.runSheetOnWindow(self.view.window!)
addAccountWindowController = accountsNewsBlurWindowController
accountsNewsBlurWindowController.runSheetOnWindow(window)
}
}