From 3d91a6b38d728c7f0a240a1d94115d9e78ceb18e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 5 May 2024 18:02:46 -0700 Subject: [PATCH] Convert some functions to async instead of completion-based. --- Mac/MainWindow/AddFeed/AddFeedWindowController.swift | 3 +-- .../Accounts/AccountsDetailViewController.swift | 10 ++++++---- .../Accounts/AccountsFeedbinWindowController.swift | 8 +++++--- .../Accounts/AccountsNewsBlurWindowController.swift | 6 ++++-- .../Accounts/AccountsPreferencesViewController.swift | 12 ++++++++++-- .../Accounts/AccountsReaderAPIWindowController.swift | 6 ++++-- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Mac/MainWindow/AddFeed/AddFeedWindowController.swift b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift index a46d816a1..be5146f9d 100644 --- a/Mac/MainWindow/AddFeed/AddFeedWindowController.swift +++ b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift @@ -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() { diff --git a/Mac/Preferences/Accounts/AccountsDetailViewController.swift b/Mac/Preferences/Accounts/AccountsDetailViewController.swift index 5386dd67e..ac8b7135d 100644 --- a/Mac/Preferences/Accounts/AccountsDetailViewController.swift +++ b/Mac/Preferences/Accounts/AccountsDetailViewController.swift @@ -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 } - } - } diff --git a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift index cb230f2ce..ef7f62d54 100644 --- a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift @@ -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 diff --git a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift index 0cf4d9aeb..4da7c9905 100644 --- a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift @@ -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 diff --git a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift index 0b7591905..fa42a2753 100644 --- a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift +++ b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift @@ -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 diff --git a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift index 9d62d5bbe..7edb797ff 100644 --- a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift @@ -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