From 718204e4d8dddbd8801cd4b02555500d5e0780f2 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 16 Sep 2025 11:02:41 -0700 Subject: [PATCH] =?UTF-8?q?Make=20sure=20window=20is=20non-nil=20before=20?= =?UTF-8?q?using=20it=20=E2=80=94=C2=A0don=E2=80=99t=20force-unwrap=20it.?= =?UTF-8?q?=20Fix=20#3827.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AddFeed/AddWebFeedWindowController.swift | 11 +++++++---- .../AddFolder/AddFolderWindowController.swift | 10 ++++++---- Mac/MainWindow/OPML/ExportOPMLWindowController.swift | 8 +++++--- Mac/MainWindow/OPML/ImportOPMLWindowController.swift | 8 +++++--- .../AccountsAddCloudKitWindowController.swift | 6 +++++- .../Accounts/AccountsAddLocalWindowController.swift | 6 +++++- .../Accounts/AccountsFeedbinWindowController.swift | 6 +++++- .../Accounts/AccountsNewsBlurWindowController.swift | 6 +++++- .../Accounts/AccountsReaderAPIWindowController.swift | 6 +++++- 9 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Mac/MainWindow/AddFeed/AddWebFeedWindowController.swift b/Mac/MainWindow/AddFeed/AddWebFeedWindowController.swift index 6100cbc56..6ca31a78d 100644 --- a/Mac/MainWindow/AddFeed/AddWebFeedWindowController.swift +++ b/Mac/MainWindow/AddFeed/AddWebFeedWindowController.swift @@ -13,7 +13,7 @@ import Articles import Account final class AddWebFeedWindowController : NSWindowController, AddFeedWindowController { - + @IBOutlet var urlTextField: NSTextField! @IBOutlet var nameTextField: NSTextField! @IBOutlet var addButton: NSButton! @@ -47,10 +47,13 @@ final class AddWebFeedWindowController : NSWindowController, AddFeedWindowContro self.folderTreeController = folderTreeController } - func runSheetOnWindow(_ hostWindow: NSWindow) { - hostWindow.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in + func runSheetOnWindow(_ hostWindow: NSWindow) { + guard let window else { + return } - } + hostWindow.beginSheet(window) { (returnCode: NSApplication.ModalResponse) -> Void in + } + } override func windowDidLoad() { if let urlString = urlString { diff --git a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift index 3e650fe69..876af326c 100644 --- a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift +++ b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift @@ -23,10 +23,12 @@ final class AddFolderWindowController : NSWindowController { // MARK: - API - func runSheetOnWindow(_ w: NSWindow) { - hostWindow = w - hostWindow!.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in - + func runSheetOnWindow(_ hostWindow: NSWindow) { + guard let window else { + return + } + + hostWindow.beginSheet(window) { (returnCode: NSApplication.ModalResponse) -> Void in if returnCode == NSApplication.ModalResponse.OK { self.addFolderIfNeeded() } diff --git a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift index ea00eec19..3cc6faa8f 100644 --- a/Mac/MainWindow/OPML/ExportOPMLWindowController.swift +++ b/Mac/MainWindow/OPML/ExportOPMLWindowController.swift @@ -42,16 +42,18 @@ final class ExportOPMLWindowController: NSWindowController { // MARK: API func runSheetOnWindow(_ hostWindow: NSWindow) { - + guard let window else { + return + } + self.hostWindow = hostWindow if AccountManager.shared.accounts.count == 1 { let account = AccountManager.shared.accounts.first! exportOPML(account: account) } else { - hostWindow.beginSheet(window!) + hostWindow.beginSheet(window) } - } // MARK: Actions diff --git a/Mac/MainWindow/OPML/ImportOPMLWindowController.swift b/Mac/MainWindow/OPML/ImportOPMLWindowController.swift index f822999ac..b2f8cf610 100644 --- a/Mac/MainWindow/OPML/ImportOPMLWindowController.swift +++ b/Mac/MainWindow/OPML/ImportOPMLWindowController.swift @@ -46,16 +46,18 @@ final class ImportOPMLWindowController: NSWindowController { // MARK: API func runSheetOnWindow(_ hostWindow: NSWindow) { - + guard let window else { + return + } + self.hostWindow = hostWindow if AccountManager.shared.activeAccounts.count == 1 { let account = AccountManager.shared.activeAccounts.first! importOPML(account: account) } else { - hostWindow.beginSheet(window!) + hostWindow.beginSheet(window) } - } // MARK: Actions diff --git a/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift b/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift index 0b00b76c1..b91eb13ac 100644 --- a/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsAddCloudKitWindowController.swift @@ -32,8 +32,12 @@ final class AccountsAddCloudKitWindowController: NSWindowController { // MARK: API func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) { + guard let window else { + return + } + self.hostWindow = hostWindow - hostWindow.beginSheet(window!, completionHandler: completion) + hostWindow.beginSheet(window, completionHandler: completion) } // MARK: Actions diff --git a/Mac/Preferences/Accounts/AccountsAddLocalWindowController.swift b/Mac/Preferences/Accounts/AccountsAddLocalWindowController.swift index 7275dc3d1..e6c385ca3 100644 --- a/Mac/Preferences/Accounts/AccountsAddLocalWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsAddLocalWindowController.swift @@ -29,8 +29,12 @@ final class AccountsAddLocalWindowController: NSWindowController { // MARK: API func runSheetOnWindow(_ hostWindow: NSWindow) { + guard let window else { + return + } + self.hostWindow = hostWindow - hostWindow.beginSheet(window!) + hostWindow.beginSheet(window) } // MARK: Actions diff --git a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift index 2b5c56449..aae789a46 100644 --- a/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsFeedbinWindowController.swift @@ -50,8 +50,12 @@ final class AccountsFeedbinWindowController: NSWindowController { // MARK: API func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) { + guard let window else { + return + } + self.hostWindow = hostWindow - hostWindow.beginSheet(window!, completionHandler: completion) + hostWindow.beginSheet(window, completionHandler: completion) } // MARK: Actions diff --git a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift index 94d964bd0..9cccfb115 100644 --- a/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsNewsBlurWindowController.swift @@ -48,8 +48,12 @@ final class AccountsNewsBlurWindowController: NSWindowController { // MARK: API func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) { + guard let window else { + return + } + self.hostWindow = hostWindow - hostWindow.beginSheet(window!, completionHandler: completion) + hostWindow.beginSheet(window, completionHandler: completion) } // MARK: Actions diff --git a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift index f0b5625cc..26e42cc3c 100644 --- a/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift +++ b/Mac/Preferences/Accounts/AccountsReaderAPIWindowController.swift @@ -79,8 +79,12 @@ final class AccountsReaderAPIWindowController: NSWindowController { // MARK: API func runSheetOnWindow(_ hostWindow: NSWindow, completion: ((NSApplication.ModalResponse) -> Void)? = nil) { + guard let window else { + return + } + self.hostWindow = hostWindow - hostWindow.beginSheet(window!, completionHandler: completion) + hostWindow.beginSheet(window, completionHandler: completion) } // MARK: Actions