Convert some functions to async instead of completion-based.

This commit is contained in:
Brent Simmons 2024-05-05 18:02:46 -07:00
parent cd7f4f7052
commit 3d91a6b38d
6 changed files with 30 additions and 15 deletions

View File

@ -54,8 +54,7 @@ class AddFeedWindowController : NSWindowController {
}
func runSheetOnWindow(_ hostWindow: NSWindow) {
hostWindow.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in
}
hostWindow.beginSheet(window!, completionHandler: nil)
}
override func windowDidLoad() {

View File

@ -64,14 +64,16 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
@IBAction func credentials(_ sender: Any) {
guard let account = account else { return }
guard let account else { return }
switch account.type {
case .feedbin:
let accountsFeedbinWindowController = AccountsFeedbinWindowController()
accountsFeedbinWindowController.account = account
accountsFeedbinWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsFeedbinWindowController
case .inoreader, .bazQux, .theOldReader, .freshRSS:
let accountsReaderAPIWindowController = AccountsReaderAPIWindowController()
accountsReaderAPIWindowController.accountType = account.type
@ -79,15 +81,15 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
accountsReaderAPIWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsReaderAPIWindowController
break
case .newsBlur:
let accountsNewsBlurWindowController = AccountsNewsBlurWindowController()
accountsNewsBlurWindowController.account = account
accountsNewsBlurWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsNewsBlurWindowController
default:
break
}
}
}

View File

@ -11,7 +11,7 @@ import Account
import Web
import Secrets
class AccountsFeedbinWindowController: NSWindowController {
final class AccountsFeedbinWindowController: NSWindowController {
@IBOutlet weak var signInTextField: NSTextField!
@IBOutlet weak var noAccountTextField: NSTextField!
@ -49,9 +49,11 @@ class AccountsFeedbinWindowController: NSWindowController {
// MARK: API
func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) {
func runSheetOnWindow(_ hostWindow: NSWindow) {
self.hostWindow = hostWindow
hostWindow.beginSheet(window!, completionHandler: completion)
Task { @MainActor in
await hostWindow.beginSheet(window!)
}
}
// MARK: Actions

View File

@ -47,9 +47,11 @@ class AccountsNewsBlurWindowController: NSWindowController {
// MARK: API
func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) {
func runSheetOnWindow(_ hostWindow: NSWindow) {
self.hostWindow = hostWindow
hostWindow.beginSheet(window!, completionHandler: completion)
Task { @MainActor in
await hostWindow.beginSheet(window!)
}
}
// MARK: Actions

View File

@ -151,12 +151,16 @@ extension AccountsPreferencesViewController: NSTableViewDelegate {
}
extension AccountsPreferencesViewController: AccountsPreferencesAddAccountDelegate {
func presentSheetForAccount(_ accountType: AccountType) {
switch accountType {
case .onMyMac:
let accountsAddLocalWindowController = AccountsAddLocalWindowController()
accountsAddLocalWindowController.runSheetOnWindow(self.view.window!)
addAccountWindowController = accountsAddLocalWindowController
case .cloudKit:
let accountsAddCloudKitWindowController = AccountsAddCloudKitWindowController()
@ -166,30 +170,34 @@ extension AccountsPreferencesViewController: AccountsPreferencesAddAccountDelega
self.tableView.reloadData()
}
}
addAccountWindowController = accountsAddCloudKitWindowController
case .feedbin:
let accountsFeedbinWindowController = AccountsFeedbinWindowController()
accountsFeedbinWindowController.runSheetOnWindow(self.view.window!)
addAccountWindowController = accountsFeedbinWindowController
case .freshRSS, .inoreader, .bazQux, .theOldReader:
let accountsReaderAPIWindowController = AccountsReaderAPIWindowController()
accountsReaderAPIWindowController.accountType = accountType
accountsReaderAPIWindowController.runSheetOnWindow(self.view.window!)
addAccountWindowController = accountsReaderAPIWindowController
case .feedly:
let addAccount = FeedlyOAuthAccountAuthorizationOperation(accountType: .feedly, secretsProvider: Secrets())
addAccount.delegate = self
addAccount.presentationAnchor = self.view.window!
runAwaitingFeedlyLoginAlertModal(forLifetimeOf: addAccount)
MainThreadOperationQueue.shared.add(addAccount)
case .newsBlur:
let accountsNewsBlurWindowController = AccountsNewsBlurWindowController()
accountsNewsBlurWindowController.runSheetOnWindow(self.view.window!)
addAccountWindowController = accountsNewsBlurWindowController
}
}
private func runAwaitingFeedlyLoginAlertModal(forLifetimeOf operation: FeedlyOAuthAccountAuthorizationOperation) {
let alert = NSAlert()
alert.alertStyle = .informational

View File

@ -79,9 +79,11 @@ class AccountsReaderAPIWindowController: NSWindowController {
// MARK: API
func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) {
func runSheetOnWindow(_ hostWindow: NSWindow) {
self.hostWindow = hostWindow
hostWindow.beginSheet(window!, completionHandler: completion)
Task { @MainActor in
await hostWindow.beginSheet(window!)
}
}
// MARK: Actions