diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index f0e48837b..33c7041ac 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -115,7 +115,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat addFolderWindowController!.runSheetOnWindow(window) } - func showAddFeedSheetOnWindow(_ window: NSWindow, urlString: String?, name: String?, account: Account?, folder: Folder?) { + @MainActor func showAddFeedSheetOnWindow(_ window: NSWindow, urlString: String?, name: String?, account: Account?, folder: Folder?) { addFeedController = AddFeedController(hostWindow: window) addFeedController?.showAddFeedSheet(urlString, name, account, folder) } @@ -455,7 +455,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat } // MARK: Add Feed - func addFeed(_ urlString: String?, name: String? = nil, account: Account? = nil, folder: Folder? = nil) { + @MainActor func addFeed(_ urlString: String?, name: String? = nil, account: Account? = nil, folder: Folder? = nil) { createAndShowMainWindowIfNecessary() if mainWindowController!.isDisplayingSheet { diff --git a/Mac/MainWindow/AddFeed/AddFeedController.swift b/Mac/MainWindow/AddFeed/AddFeedController.swift index 5ed845738..75bbd1153 100644 --- a/Mac/MainWindow/AddFeed/AddFeedController.swift +++ b/Mac/MainWindow/AddFeed/AddFeedController.swift @@ -33,7 +33,7 @@ final class AddFeedController: AddFeedWindowControllerDelegate { self.hostWindow = hostWindow } - func showAddFeedSheet(_ urlString: String? = nil, _ name: String? = nil, _ account: Account? = nil, _ folder: Folder? = nil) { + @MainActor func showAddFeedSheet(_ urlString: String? = nil, _ name: String? = nil, _ account: Account? = nil, _ folder: Folder? = nil) { let folderTreeControllerDelegate = FolderTreeControllerDelegate() let folderTreeController = TreeController(delegate: folderTreeControllerDelegate) diff --git a/Mac/MainWindow/AddFeed/FolderTreeMenu.swift b/Mac/MainWindow/AddFeed/FolderTreeMenu.swift index c18ff05bc..18d287d6d 100644 --- a/Mac/MainWindow/AddFeed/FolderTreeMenu.swift +++ b/Mac/MainWindow/AddFeed/FolderTreeMenu.swift @@ -13,7 +13,7 @@ import Account final class FolderTreeMenu { - static func createFolderPopupMenu(with rootNode: Node, restrictToSpecialAccounts: Bool = false) -> NSMenu { + @MainActor static func createFolderPopupMenu(with rootNode: Node, restrictToSpecialAccounts: Bool = false) -> NSMenu { let menu = NSMenu(title: "Folders") menu.autoenablesItems = false @@ -60,7 +60,7 @@ final class FolderTreeMenu { } } - private static func addFolderItemsToMenuWithNodes(menu: NSMenu, nodes: [Node], indentationLevel: Int) { + @MainActor private static func addFolderItemsToMenuWithNodes(menu: NSMenu, nodes: [Node], indentationLevel: Int) { nodes.forEach { (oneNode) in diff --git a/Mac/MainWindow/Sidebar/SidebarDeleteItemsAlert.swift b/Mac/MainWindow/Sidebar/SidebarDeleteItemsAlert.swift index b4e7d48bd..106f9337a 100644 --- a/Mac/MainWindow/Sidebar/SidebarDeleteItemsAlert.swift +++ b/Mac/MainWindow/Sidebar/SidebarDeleteItemsAlert.swift @@ -13,7 +13,7 @@ import Account enum SidebarDeleteItemsAlert { /// Builds a delete confirmation dialog for the supplied nodes - static func build(_ nodes: [Node]) -> NSAlert { + @MainActor static func build(_ nodes: [Node]) -> NSAlert { let alert = NSAlert() alert.alertStyle = .warning diff --git a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift index 5e73078ae..fdecf464f 100644 --- a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift +++ b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift @@ -12,7 +12,7 @@ import Articles import RSCore import Account -@objc final class SidebarOutlineDataSource: NSObject, NSOutlineViewDataSource { +@objc @MainActor final class SidebarOutlineDataSource: NSObject, NSOutlineViewDataSource { let treeController: TreeController static let dragOperationNone = NSDragOperation(rawValue: 0) @@ -199,7 +199,7 @@ private extension SidebarOutlineDataSource { return .copy } - func validateSingleLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardFeed, _ parentNode: Node, _ index: Int) -> NSDragOperation { + @MainActor func validateSingleLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardFeed, _ parentNode: Node, _ index: Int) -> NSDragOperation { // A local feed should always drag on to an Account or Folder node, and we can provide an index. guard let dropTargetNode = ancestorThatCanAcceptLocalFeed(parentNode) else { return SidebarOutlineDataSource.dragOperationNone diff --git a/Modules/Account/Sources/Account/SidebarItemIdentifier.swift b/Modules/Account/Sources/Account/SidebarItemIdentifier.swift index 051a76e1b..aebd6943b 100644 --- a/Modules/Account/Sources/Account/SidebarItemIdentifier.swift +++ b/Modules/Account/Sources/Account/SidebarItemIdentifier.swift @@ -12,7 +12,7 @@ public protocol SidebarItemIdentifiable { var sidebarItemID: SidebarItemIdentifier? { get } } -public enum SidebarItemIdentifier: CustomStringConvertible, Hashable, Equatable { +public enum SidebarItemIdentifier: CustomStringConvertible, Hashable, Equatable, Sendable { case smartFeed(String) // String is a unique identifier case script(String) // String is a unique identifier diff --git a/Modules/RSCore/Sources/RSCore/Shared/UndoableCommand.swift b/Modules/RSCore/Sources/RSCore/Shared/UndoableCommand.swift index cd9b7da57..6d4cb3292 100644 --- a/Modules/RSCore/Sources/RSCore/Shared/UndoableCommand.swift +++ b/Modules/RSCore/Sources/RSCore/Shared/UndoableCommand.swift @@ -41,27 +41,27 @@ extension UndoableCommand { public protocol UndoableCommandRunner: AnyObject { - var undoableCommands: [UndoableCommand] { get set } - var undoManager: UndoManager? { get } + @MainActor var undoableCommands: [UndoableCommand] { get set } + @MainActor var undoManager: UndoManager? { get } - func runCommand(_ undoableCommand: UndoableCommand) - func clearUndoableCommands() + @MainActor func runCommand(_ undoableCommand: UndoableCommand) + @MainActor func clearUndoableCommands() } public extension UndoableCommandRunner { - func runCommand(_ undoableCommand: UndoableCommand) { + @MainActor func runCommand(_ undoableCommand: UndoableCommand) { pushUndoableCommand(undoableCommand) undoableCommand.perform() } - func pushUndoableCommand(_ undoableCommand: UndoableCommand) { + @MainActor func pushUndoableCommand(_ undoableCommand: UndoableCommand) { undoableCommands += [undoableCommand] } - func clearUndoableCommands() { + @MainActor func clearUndoableCommands() { // Useful, for example, when timeline is reloaded and the list of articles changes. // Otherwise things like Redo Mark Read are ambiguous. diff --git a/Modules/RSTree/Package.swift b/Modules/RSTree/Package.swift index 90debb11e..27b6028a6 100644 --- a/Modules/RSTree/Package.swift +++ b/Modules/RSTree/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.10 +// swift-tools-version:6.2 import PackageDescription let package = Package( diff --git a/Modules/RSTree/Sources/RSTree/Node.swift b/Modules/RSTree/Sources/RSTree/Node.swift index 3ae17e89d..ae04a0975 100644 --- a/Modules/RSTree/Sources/RSTree/Node.swift +++ b/Modules/RSTree/Sources/RSTree/Node.swift @@ -10,7 +10,7 @@ import Foundation // Main thread only. -public final class Node: Hashable { +@MainActor public final class Node: Hashable { public weak var parent: Node? public let representedObject: AnyObject @@ -171,13 +171,13 @@ public final class Node: Hashable { // MARK: - Hashable - public func hash(into hasher: inout Hasher) { + nonisolated public func hash(into hasher: inout Hasher) { hasher.combine(uniqueID) } // MARK: - Equatable - public class func ==(lhs: Node, rhs: Node) -> Bool { + nonisolated public class func ==(lhs: Node, rhs: Node) -> Bool { return lhs === rhs } } @@ -185,7 +185,7 @@ public final class Node: Hashable { public extension Array where Element == Node { - func representedObjects() -> [AnyObject] { + @MainActor func representedObjects() -> [AnyObject] { return self.map{ $0.representedObject } } diff --git a/Modules/RSTree/Sources/RSTree/NodePath.swift b/Modules/RSTree/Sources/RSTree/NodePath.swift index 1e9fee5d9..bb280ad03 100644 --- a/Modules/RSTree/Sources/RSTree/NodePath.swift +++ b/Modules/RSTree/Sources/RSTree/NodePath.swift @@ -8,7 +8,7 @@ import Foundation -public struct NodePath { +@MainActor public struct NodePath { let components: [Node] diff --git a/Modules/RSTree/Sources/RSTree/TreeController.swift b/Modules/RSTree/Sources/RSTree/TreeController.swift index 56ae68032..3b25bc00c 100644 --- a/Modules/RSTree/Sources/RSTree/TreeController.swift +++ b/Modules/RSTree/Sources/RSTree/TreeController.swift @@ -8,14 +8,14 @@ import Foundation -public protocol TreeControllerDelegate: AnyObject { +@MainActor public protocol TreeControllerDelegate: AnyObject { func treeController(treeController: TreeController, childNodesFor: Node) -> [Node]? } public typealias NodeVisitBlock = (_ : Node) -> Void -public final class TreeController { +@MainActor public final class TreeController { private weak var delegate: TreeControllerDelegate? public let rootNode: Node diff --git a/Shared/Commands/DeleteCommand.swift b/Shared/Commands/DeleteCommand.swift index f09652160..d57e7f9a3 100644 --- a/Shared/Commands/DeleteCommand.swift +++ b/Shared/Commands/DeleteCommand.swift @@ -24,7 +24,7 @@ final class DeleteCommand: UndoableCommand { private let itemSpecifiers: [SidebarItemSpecifier] - init?(nodesToDelete: [Node], treeController: TreeController? = nil, undoManager: UndoManager, errorHandler: @escaping (Error) -> ()) { + @MainActor init?(nodesToDelete: [Node], treeController: TreeController? = nil, undoManager: UndoManager, errorHandler: @escaping (Error) -> ()) { guard DeleteCommand.canDelete(nodesToDelete) else { return nil @@ -56,10 +56,11 @@ final class DeleteCommand: UndoableCommand { } group.notify(queue: DispatchQueue.main) { - self.treeController?.rebuild() - self.registerUndo() + MainActor.assumeIsolated { + self.treeController?.rebuild() + self.registerUndo() + } } - } func undo() { @@ -67,7 +68,7 @@ final class DeleteCommand: UndoableCommand { registerRedo() } - static func canDelete(_ nodes: [Node]) -> Bool { + @MainActor static func canDelete(_ nodes: [Node]) -> Bool { // Return true if all nodes are feeds and folders. // Any other type: return false. @@ -112,7 +113,7 @@ private struct SidebarItemSpecifier { return nil } - init?(node: Node, errorHandler: @escaping (Error) -> ()) { + @MainActor init?(node: Node, errorHandler: @escaping (Error) -> ()) { var account: Account? @@ -265,7 +266,7 @@ private struct DeleteActionName { private static let deleteFolders = NSLocalizedString("Delete Folders", comment: "command") private static let deleteFeedsAndFolders = NSLocalizedString("Delete Feeds and Folders", comment: "command") - static func name(for nodes: [Node]) -> String? { + @MainActor static func name(for nodes: [Node]) -> String? { var numberOfFeeds = 0 var numberOfFolders = 0 diff --git a/Shared/Extensions/Node-Extensions.swift b/Shared/Extensions/Node-Extensions.swift index 6280583a8..df5e02621 100644 --- a/Shared/Extensions/Node-Extensions.swift +++ b/Shared/Extensions/Node-Extensions.swift @@ -11,7 +11,7 @@ import RSTree import Articles import RSCore -extension Array where Element == Node { +@MainActor extension Array where Element == Node { func sortedAlphabetically() -> [Node] { diff --git a/Shared/Tree/SidebarTreeControllerDelegate.swift b/Shared/Tree/SidebarTreeControllerDelegate.swift index 381afd2b6..4598b16e1 100644 --- a/Shared/Tree/SidebarTreeControllerDelegate.swift +++ b/Shared/Tree/SidebarTreeControllerDelegate.swift @@ -11,7 +11,7 @@ import RSTree import Articles import Account -final class SidebarTreeControllerDelegate: TreeControllerDelegate { +@MainActor final class SidebarTreeControllerDelegate: TreeControllerDelegate { private var filterExceptions = Set() var isReadFiltered = false diff --git a/iOS/MainTimeline/MarkAsReadAlertController.swift b/iOS/MainTimeline/MarkAsReadAlertController.swift index 670add4c6..90f8b8801 100644 --- a/iOS/MainTimeline/MarkAsReadAlertController.swift +++ b/iOS/MainTimeline/MarkAsReadAlertController.swift @@ -57,7 +57,9 @@ struct MarkAsReadAlertController { cancelCompletion?() } let settingsAction = UIAlertAction(title: settingsTitle, style: .default) { _ in - coordinator.showSettings(scrollToArticlesSection: true) + Task { @MainActor in + coordinator.showSettings(scrollToArticlesSection: true) + } } let markAction = UIAlertAction(title: confirmTitle, style: .default, handler: completion) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 88d359377..057a6ca49 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -25,11 +25,11 @@ enum ShowFeedName { case feed } -struct FeedNode: Hashable { - var node: Node - var sidebarItemID: SidebarItemIdentifier +struct FeedNode: Hashable, Sendable { + let node: Node + let sidebarItemID: SidebarItemIdentifier - init(_ node: Node) { + @MainActor init(_ node: Node) { self.node = node self.sidebarItemID = (node.representedObject as! SidebarItem).sidebarItemID! } @@ -39,7 +39,7 @@ struct FeedNode: Hashable { } } -final class SceneCoordinator: NSObject, UndoableCommandRunner { +@MainActor final class SceneCoordinator: NSObject, UndoableCommandRunner { var undoableCommands = [UndoableCommand]() var undoManager: UndoManager? { return rootSplitViewController.undoManager