Fix some concurrency warnings in AppleScript support.

This commit is contained in:
Brent Simmons 2024-04-16 20:53:33 -07:00
parent 57de8acfc5
commit 112e2d3724
7 changed files with 39 additions and 34 deletions

View File

@ -113,7 +113,7 @@ class NetNewsWireCreateElementCommand : NSCreateCommand {
is ambiguity about whether specifiers are lists or single objects, the code switches
based on which it is.
*/
class NetNewsWireDeleteCommand : NSDeleteCommand {
final class NetNewsWireDeleteCommand : NSDeleteCommand {
/*
delete(objectToDelete:, from container:)
@ -122,13 +122,16 @@ class NetNewsWireDeleteCommand : NSDeleteCommand {
ultimately calling container.deleteElement(element) for each element to delete
*/
func delete(objectToDelete:Any, from container:ScriptingObjectContainer) {
if let objectList = objectToDelete as? [Any] {
for nthObject in objectList {
self.delete(objectToDelete:nthObject, from:container)
}
} else if let element = objectToDelete as? ScriptingObject {
container.deleteElement(element)
}
MainActor.assumeIsolated {
if let objectList = objectToDelete as? [Any] {
for nthObject in objectList {
self.delete(objectToDelete:nthObject, from:container)
}
} else if let element = objectToDelete as? ScriptingObject {
container.deleteElement(element)
}
}
}
/*

View File

@ -11,11 +11,11 @@ import Account
import Articles
@objc(ScriptableArticle)
class ScriptableArticle: NSObject, UniqueIDScriptingObject, ScriptingObjectContainer {
@MainActor class ScriptableArticle: NSObject, UniqueIDScriptingObject, ScriptingObjectContainer {
let article: Article
let container: ScriptingObjectContainer
let article:Article
let container:ScriptingObjectContainer
init (_ article:Article, container:ScriptingObjectContainer) {
self.article = article
self.container = container

View File

@ -11,7 +11,7 @@ import Account
import Articles
@objc(ScriptableAuthor)
class ScriptableAuthor: NSObject, UniqueIDScriptingObject {
@MainActor final class ScriptableAuthor: NSObject, UniqueIDScriptingObject {
let author:Author
let container:ScriptingObjectContainer

View File

@ -12,7 +12,7 @@ import Account
import Articles
@objc(ScriptableFeed)
@objcMembers class ScriptableFeed: NSObject, UniqueIDScriptingObject, ScriptingObjectContainer {
@MainActor @objcMembers class ScriptableFeed: NSObject, UniqueIDScriptingObject, ScriptingObjectContainer {
let feed:Feed
let container:ScriptingObjectContainer
@ -23,7 +23,7 @@ import Articles
}
@objc(objectSpecifier)
override var objectSpecifier: NSScriptObjectSpecifier? {
override var objectSpecifier: NSScriptObjectSpecifier? {
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject:self)
return (scriptObjectSpecifier)
}
@ -44,7 +44,7 @@ import Articles
// I am not sure if account should prefer to be specified by name or by ID
// but in either case it seems like the accountID would be used as the keydata, so I chose ID
@objc(uniqueID)
@MainActor var scriptingUniqueID:Any {
var scriptingUniqueID:Any {
return feed.feedID
}
@ -71,7 +71,7 @@ import Articles
return url
}
@MainActor class func scriptableFeed(_ feed:Feed, account:Account, folder:Folder?) -> ScriptableFeed {
class func scriptableFeed(_ feed:Feed, account:Account, folder:Folder?) -> ScriptableFeed {
let scriptableAccount = ScriptableAccount(account)
if let folder = folder {
let scriptableFolder = ScriptableFolder(folder, container:scriptableAccount)
@ -81,7 +81,7 @@ import Articles
}
}
@MainActor class func handleCreateElement(command:NSCreateCommand) -> Any? {
class func handleCreateElement(command:NSCreateCommand) -> Any? {
guard command.isCreateCommand(forClass:"Feed") else { return nil }
guard let arguments = command.arguments else {return nil}
let titleFromArgs = command.property(forKey:"name") as? String
@ -120,27 +120,27 @@ import Articles
// MARK: --- Scriptable properties ---
@objc(url)
@MainActor var url:String {
var url:String {
return self.feed.url
}
@objc(name)
@MainActor var name:String {
var name:String {
return self.feed.name ?? ""
}
@objc(homePageURL)
@MainActor var homePageURL:String {
var homePageURL:String {
return self.feed.homePageURL ?? ""
}
@objc(iconURL)
@MainActor var iconURL:String {
var iconURL:String {
return self.feed.iconURL ?? ""
}
@objc(faviconURL)
@MainActor var faviconURL:String {
var faviconURL:String {
return self.feed.faviconURL ?? ""
}
@ -152,13 +152,13 @@ import Articles
// MARK: --- scriptable elements ---
@objc(authors)
@MainActor var authors:NSArray {
var authors:NSArray {
let feedAuthors = feed.authors ?? []
return feedAuthors.map { ScriptableAuthor($0, container:self) } as NSArray
}
@objc(valueInAuthorsWithUniqueID:)
@MainActor func valueInAuthors(withUniqueID id:String) -> ScriptableAuthor? {
func valueInAuthors(withUniqueID id:String) -> ScriptableAuthor? {
guard let author = feed.authors?.first(where:{$0.authorID == id}) else { return nil }
return ScriptableAuthor(author, container:self)
}

View File

@ -23,9 +23,11 @@ import Core
}
@objc(objectSpecifier)
override var objectSpecifier: NSScriptObjectSpecifier? {
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject:self)
return (scriptObjectSpecifier)
nonisolated override var objectSpecifier: NSScriptObjectSpecifier? {
MainActor.assumeIsolated {
let scriptObjectSpecifier = self.container.makeFormUniqueIDScriptObjectSpecifier(forObject:self)
return (scriptObjectSpecifier)
}
}
// MARK: --- ScriptingObject protocol ---

View File

@ -10,7 +10,7 @@ import Foundation
protocol ScriptingObject {
var objectSpecifier: NSScriptObjectSpecifier? { get }
var scriptingKey: String { get }
@MainActor var scriptingKey: String { get }
}
protocol NamedScriptingObject: ScriptingObject {
@ -18,5 +18,5 @@ protocol NamedScriptingObject: ScriptingObject {
}
protocol UniqueIDScriptingObject: ScriptingObject {
var scriptingUniqueID:Any { get }
@MainActor var scriptingUniqueID:Any { get }
}

View File

@ -10,13 +10,13 @@ import AppKit
import Account
protocol ScriptingObjectContainer: ScriptingObject {
var scriptingClassDescription:NSScriptClassDescription { get }
func deleteElement(_ element:ScriptingObject)
@MainActor var scriptingClassDescription:NSScriptClassDescription { get }
@MainActor func deleteElement(_ element:ScriptingObject)
}
extension ScriptingObjectContainer {
func makeFormNameScriptObjectSpecifier(forObject object:NamedScriptingObject) -> NSScriptObjectSpecifier? {
@MainActor func makeFormNameScriptObjectSpecifier(forObject object:NamedScriptingObject) -> NSScriptObjectSpecifier? {
let containerClassDescription = self.scriptingClassDescription
let containerScriptObjectSpecifier = self.objectSpecifier
let scriptingKey = object.scriptingKey
@ -26,7 +26,7 @@ extension ScriptingObjectContainer {
return specifier
}
func makeFormUniqueIDScriptObjectSpecifier(forObject object:UniqueIDScriptingObject) -> NSScriptObjectSpecifier? {
@MainActor func makeFormUniqueIDScriptObjectSpecifier(forObject object:UniqueIDScriptingObject) -> NSScriptObjectSpecifier? {
let containerClassDescription = self.scriptingClassDescription
let containerScriptObjectSpecifier = self.objectSpecifier
let scriptingKey = object.scriptingKey