From 653789b913d9be501ceb55518283bf6db32fdd49 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 18 Nov 2025 10:00:50 -0800 Subject: [PATCH] Use Swift 6.2 with the app. Fix some concurrency issues. --- Mac/CrashReporter/CrashReporter.swift | 2 +- .../FeedInspectorViewController.swift | 38 +++++++++++-------- Mac/Inspector/InspectorWindowController.swift | 2 +- .../Detail/DetailWebViewController.swift | 2 +- ....swift => MainWindowKeyboardHandler.swift} | 7 +--- .../AppKit/KeyboardDelegateProtocol.swift | 4 +- xcconfig/NetNewsWire_project.xcconfig | 3 +- 7 files changed, 31 insertions(+), 27 deletions(-) rename Mac/MainWindow/Keyboard/{MainWIndowKeyboardHandler.swift => MainWindowKeyboardHandler.swift} (88%) diff --git a/Mac/CrashReporter/CrashReporter.swift b/Mac/CrashReporter/CrashReporter.swift index ba78f3e7f..8ba518ad5 100644 --- a/Mac/CrashReporter/CrashReporter.swift +++ b/Mac/CrashReporter/CrashReporter.swift @@ -17,7 +17,7 @@ import CrashReporter // At some point this code should probably move into RSCore, so Rainier and any other // future apps can use it. -struct CrashReporter { +@MainActor struct CrashReporter { struct DefaultsKey { static let sendCrashLogsAutomaticallyKey = "SendCrashLogsAutomatically" diff --git a/Mac/Inspector/FeedInspectorViewController.swift b/Mac/Inspector/FeedInspectorViewController.swift index 8731bb392..7e8c73a7c 100644 --- a/Mac/Inspector/FeedInspectorViewController.swift +++ b/Mac/Inspector/FeedInspectorViewController.swift @@ -7,9 +7,10 @@ // import AppKit +import UserNotifications +import Synchronization import Articles import Account -import UserNotifications final class FeedInspectorViewController: NSViewController, Inspector { @@ -28,7 +29,7 @@ final class FeedInspectorViewController: NSViewController, Inspector { } } - private var userNotificationSettings: UNNotificationSettings? + private var authorizationStatus: UNAuthorizationStatus? // MARK: Inspector @@ -63,7 +64,7 @@ final class FeedInspectorViewController: NSViewController, Inspector { // MARK: Actions @IBAction func isNotifyAboutNewArticlesChanged(_ sender: Any) { - guard userNotificationSettings != nil else { + guard authorizationStatus != nil else { DispatchQueue.main.async { self.isNotifyAboutNewArticlesCheckBox.setNextState() } @@ -71,7 +72,9 @@ final class FeedInspectorViewController: NSViewController, Inspector { } UNUserNotificationCenter.current().getNotificationSettings { (settings) in - self.updateNotificationSettings() + Task { @MainActor in + self.updateNotificationSettings() + } if settings.authorizationStatus == .denied { DispatchQueue.main.async { @@ -84,15 +87,17 @@ final class FeedInspectorViewController: NSViewController, Inspector { } } else { UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in - self.updateNotificationSettings() - if granted { - DispatchQueue.main.async { - self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false - NSApplication.shared.registerForRemoteNotifications() - } - } else { - DispatchQueue.main.async { - self.isNotifyAboutNewArticlesCheckBox.setNextState() + Task { @MainActor in + self.updateNotificationSettings() + if granted { + DispatchQueue.main.async { + self.feed?.isNotifyAboutNewArticles = (self.isNotifyAboutNewArticlesCheckBox?.state ?? .off) == .on ? true : false + NSApplication.shared.registerForRemoteNotifications() + } + } else { + DispatchQueue.main.async { + self.isNotifyAboutNewArticlesCheckBox.setNextState() + } } } } @@ -180,9 +185,10 @@ private extension FeedInspectorViewController { func updateNotificationSettings() { UNUserNotificationCenter.current().getNotificationSettings { (settings) in - self.userNotificationSettings = settings - if settings.authorizationStatus == .authorized { - DispatchQueue.main.async { + let authorizationStatus = settings.authorizationStatus + Task { @MainActor in + self.authorizationStatus = authorizationStatus + if self.authorizationStatus == .authorized { NSApplication.shared.registerForRemoteNotifications() } } diff --git a/Mac/Inspector/InspectorWindowController.swift b/Mac/Inspector/InspectorWindowController.swift index c8c5c4434..35ca11ebf 100644 --- a/Mac/Inspector/InspectorWindowController.swift +++ b/Mac/Inspector/InspectorWindowController.swift @@ -8,7 +8,7 @@ import AppKit -protocol Inspector: AnyObject { +@MainActor protocol Inspector: AnyObject { var objects: [Any]? { get set } var isFallbackInspector: Bool { get } // Can handle nothing-to-inspect or unexpected type of objects. diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index db4f15790..5fd87b419 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -12,7 +12,7 @@ import RSCore import RSWeb import Articles -protocol DetailWebViewControllerDelegate: AnyObject { +@MainActor protocol DetailWebViewControllerDelegate: AnyObject { func mouseDidEnter(_: DetailWebViewController, link: String) func mouseDidExit(_: DetailWebViewController) } diff --git a/Mac/MainWindow/Keyboard/MainWIndowKeyboardHandler.swift b/Mac/MainWindow/Keyboard/MainWindowKeyboardHandler.swift similarity index 88% rename from Mac/MainWindow/Keyboard/MainWIndowKeyboardHandler.swift rename to Mac/MainWindow/Keyboard/MainWindowKeyboardHandler.swift index 04483edca..0b781a7d9 100644 --- a/Mac/MainWindow/Keyboard/MainWIndowKeyboardHandler.swift +++ b/Mac/MainWindow/Keyboard/MainWindowKeyboardHandler.swift @@ -1,5 +1,5 @@ // -// MainWIndowKeyboardHandler.swift +// MainWindowKeyboardHandler.swift // NetNewsWire // // Created by Brent Simmons on 12/19/17. @@ -9,13 +9,11 @@ import AppKit import RSCore -final class MainWindowKeyboardHandler: KeyboardDelegate { - +@MainActor final class MainWindowKeyboardHandler: KeyboardDelegate { static let shared = MainWindowKeyboardHandler() let globalShortcuts: Set init() { - let f = Bundle.main.path(forResource: "GlobalKeyboardShortcuts", ofType: "plist")! let rawShortcuts = NSArray(contentsOfFile: f)! as! [[String: Any]] @@ -23,7 +21,6 @@ final class MainWindowKeyboardHandler: KeyboardDelegate { } func keydown(_ event: NSEvent, in view: NSView) -> Bool { - let key = KeyboardKey(with: event) guard let matchingShortcut = KeyboardShortcut.findMatchingShortcut(in: globalShortcuts, key: key) else { return false diff --git a/Modules/RSCore/Sources/RSCore/AppKit/KeyboardDelegateProtocol.swift b/Modules/RSCore/Sources/RSCore/AppKit/KeyboardDelegateProtocol.swift index c97676f8f..5bf60bf40 100644 --- a/Modules/RSCore/Sources/RSCore/AppKit/KeyboardDelegateProtocol.swift +++ b/Modules/RSCore/Sources/RSCore/AppKit/KeyboardDelegateProtocol.swift @@ -9,8 +9,8 @@ #if os(macOS) import AppKit -@objc public protocol KeyboardDelegate: AnyObject { +@MainActor @objc public protocol KeyboardDelegate: AnyObject { // Return true if handled. - @MainActor func keydown(_: NSEvent, in view: NSView) -> Bool + func keydown(_: NSEvent, in view: NSView) -> Bool } #endif diff --git a/xcconfig/NetNewsWire_project.xcconfig b/xcconfig/NetNewsWire_project.xcconfig index 5c8b92c38..70fc6fe66 100644 --- a/xcconfig/NetNewsWire_project.xcconfig +++ b/xcconfig/NetNewsWire_project.xcconfig @@ -51,8 +51,9 @@ IPHONEOS_DEPLOYMENT_TARGET = 26.0 //SDKROOT = macosx SWIFT_EMIT_LOC_STRINGS = YES SWIFT_SWIFT3_OBJC_INFERENCE = Off -SWIFT_VERSION = 5.10 +SWIFT_VERSION = 6.2 SWIFT_TREAT_WARNINGS_AS_ERRORS = YES +OTHER_SWIFT_FLAGS = $(inherited) -enable-upcoming-feature NonisolatedNonsendingByDefault -enable-upcoming-feature InferIsolatedConformances // https://forums.swift.org/t/swift-packages-in-multiple-targets-results-in-this-will-result-in-duplication-of-library-code-errors/34892/33 DISABLE_DIAMOND_PROBLEM_DIAGNOSTIC = YES