From 1b2e2d051392f89216d01d2891c9a83da33ba41e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 10 Nov 2025 12:02:01 -0800 Subject: [PATCH] Convert to async/await. --- .../AddFeed/AddFeedWindowController.swift | 3 +- .../AddFolder/AddFolderWindowController.swift | 7 +++-- .../AccountsAddCloudKitWindowController.swift | 7 ++--- .../AccountsDetailViewController.swift | 27 +++++++++------- .../AccountsFeedbinWindowController.swift | 4 +-- .../AccountsPreferencesViewController.swift | 31 +++++++++++++------ 6 files changed, 46 insertions(+), 33 deletions(-) diff --git a/Mac/MainWindow/AddFeed/AddFeedWindowController.swift b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift index 9ea239ce0..c98c8b3fa 100644 --- a/Mac/MainWindow/AddFeed/AddFeedWindowController.swift +++ b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift @@ -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() { diff --git a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift index d67783f62..c1bedf634 100644 --- a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift +++ b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift @@ -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() } } } diff --git a/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift b/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift index 23f8372f5..d2bcb6b63 100644 --- a/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift @@ -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 diff --git a/Mac/Preferences/Accounts/AccountsDetailViewController.swift b/Mac/Preferences/Accounts/AccountsDetailViewController.swift index ebd839911..c1404687f 100644 --- a/Mac/Preferences/Accounts/AccountsDetailViewController.swift +++ b/Mac/Preferences/Accounts/AccountsDetailViewController.swift @@ -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 } - } - } diff --git a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift index 323570277..f7cc8c62d 100644 --- a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift @@ -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 diff --git a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift index d0bc1502a..e741982d2 100644 --- a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift +++ b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift @@ -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) } }