Clean whitespace-only lines.

This commit is contained in:
Brent Simmons committed 2025-11-05 11:22:10 -08:00
1 parent 9827300a9a
commit 9efde554d4
452 files changed
+5354 -5354

No files matched your search

+18 -18
View File
@@ -13,12 +13,12 @@ import RSCore
@objc(ScriptableAccount)
final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjectContainer {
let account:Account
init (_ account:Account) {
self.account = account
}
@objc(objectSpecifier)
override var objectSpecifier: NSScriptObjectSpecifier? {
let myContainer = NSApplication.shared
@@ -47,13 +47,13 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
}
// MARK: --- ScriptingObject protocol ---
var scriptingKey: String {
return "accounts"
}
// MARK: --- UniqueIdScriptingObject protocol ---
// 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)
@@ -62,11 +62,11 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
}
// MARK: --- ScriptingObjectContainer protocol ---
var scriptingClassDescription: NSScriptClassDescription {
return self.classDescription as! NSScriptClassDescription
}
func deleteElement(_ element:ScriptingObject) {
if let scriptableFolder = element as? ScriptableFolder {
BatchUpdate.shared.perform {
@@ -93,30 +93,30 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
}
// MARK: --- Scriptable elements ---
@objc(feeds)
var feeds:NSArray {
return account.topLevelFeeds.map { ScriptableFeed($0, container:self) } as NSArray
}
@objc(countOfFeeds)
func countOfFeeds() -> Int {
return account.topLevelFeeds.count
}
@objc(objectInFeedsAtIndex:)
func objectInFeedsAtIndex(_ index: Int) -> ScriptableFeed? {
let feeds = Array(account.topLevelFeeds)
guard index >= 0 && index < feeds.count else { return nil }
return ScriptableFeed(feeds[index], container: self)
}
@objc(valueInFeedsWithUniqueID:)
func valueInFeeds(withUniqueID id:String) -> ScriptableFeed? {
guard let feed = account.existingFeed(withFeedID: id) else { return nil }
return ScriptableFeed(feed, container:self)
}
@objc(valueInFeedsWithName:)
func valueInFeeds(withName name:String) -> ScriptableFeed? {
let feeds = Array(account.flattenedFeeds())
@@ -130,12 +130,12 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
let folders = Array(foldersSet)
return folders.map { ScriptableFolder($0, container:self) } as NSArray
}
@objc(countOfFolders)
func countOfFolders() -> Int {
return account.folders?.count ?? 0
}
@objc(objectInFoldersAtIndex:)
func objectInFoldersAtIndex(_ index: Int) -> ScriptableFolder? {
let foldersSet = account.folders ?? Set<Folder>()
@@ -143,7 +143,7 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
guard index >= 0 && index < folders.count else { return nil }
return ScriptableFolder(folders[index], container: self)
}
@objc(valueInFoldersWithUniqueID:)
func valueInFolders(withUniqueID id:NSNumber) -> ScriptableFolder? {
let folderId = id.intValue
@@ -163,25 +163,25 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec
}
return scriptableFeeds as NSArray
}
@objc(countOfAllFeeds)
func countOfAllFeeds() -> Int {
return account.flattenedFeeds().count
}
@objc(objectInAllFeedsAtIndex:)
func objectInAllFeedsAtIndex(_ index: Int) -> ScriptableFeed? {
let allFeeds = Array(account.flattenedFeeds())
guard index >= 0 && index < allFeeds.count else { return nil }
return ScriptableFeed(allFeeds[index], container: self)
}
@objc(valueInAllFeedsWithUniqueID:)
func valueInAllFeeds(withUniqueID id:String) -> ScriptableFeed? {
guard let feed = account.existingFeed(withFeedID: id) else { return nil }
return ScriptableFeed(feed, container:self)
}
@objc(valueInAllFeedsWithName:)
func valueInAllFeeds(withName name:String) -> ScriptableFeed? {
let feeds = Array(account.flattenedFeeds())
@@ -31,13 +31,13 @@ protocol ScriptingAppDelegate {
}
extension AppDelegate : AppDelegateAppleEvents {
// MARK: GetURL Apple Event
func installAppleEventHandlers() {
NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(AppDelegate.getURL(_:_:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}
@objc func getURL(_ event: NSAppleEventDescriptor, _ withReplyEvent: NSAppleEventDescriptor) {
guard var urlString = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue else {
@@ -51,14 +51,14 @@ extension AppDelegate : AppDelegateAppleEvents {
let themeURLString = queryItems.first(where: { $0.name == "url" })?.value else {
return
}
if let themeURL = URL(string: themeURLString) {
let request = URLRequest(url: themeURL)
let task = URLSession.shared.downloadTask(with: request) { location, response, error in
guard let location = location else {
return
}
do {
try ArticleThemeDownloader.shared.handleFile(at: location)
} catch {
@@ -68,10 +68,10 @@ extension AppDelegate : AppDelegateAppleEvents {
task.resume()
}
return
}
// Special case URL with specific scheme handler x-netnewswire-feed: intended to ensure we open
// it regardless of which news reader may be set as the default
let nnwScheme = "x-netnewswire-feed:"
@@ -128,7 +128,7 @@ final class NetNewsWireDeleteCommand : NSDeleteCommand {
container.deleteElement(element)
}
}
/*
delete(specifier:, from container:)
At this point in handling the command, the container could be a list or a single object,
@@ -177,7 +177,7 @@ final class NetNewsWireExistsCommand : NSExistsCommand {
// must not exist. Otherwise, we return the result of the defaultImplementation
// The wrinkle is that it is possible that the direct object is a list, so we need to
// handle that case as well
override func performDefaultImplementation() -> Any? {
guard let result = super.performDefaultImplementation() else { return NSNumber(booleanLiteral:false) }
return result
@@ -15,7 +15,7 @@ final class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjec
let article:Article
let container:ScriptingObjectContainer
init (_ article:Article, container:ScriptingObjectContainer) {
self.article = article
self.container = container
@@ -44,17 +44,17 @@ final class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjec
}
// MARK: --- ScriptingObjectContainer protocol ---
var scriptingClassDescription: NSScriptClassDescription {
return self.classDescription as! NSScriptClassDescription
}
func deleteElement(_ element:ScriptingObject) {
print ("delete event not handled")
}
// MARK: --- Scriptable properties ---
@objc(url)
var url:String? {
return article.preferredLink
@@ -69,7 +69,7 @@ final class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjec
var externalUrl:String? {
return article.externalLink
}
@objc(title)
var title:String {
return article.title ?? ""
@@ -134,7 +134,7 @@ final class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjec
var imageURL:String {
return article.imageLink ?? ""
}
@objc(authors)
var authors:NSArray {
let articleAuthors = article.authors ?? []
+4 -4
View File
@@ -15,7 +15,7 @@ final class ScriptableAuthor: NSObject, UniqueIdScriptingObject {
let author:Author
let container:ScriptingObjectContainer
init (_ author:Author, container:ScriptingObjectContainer) {
self.author = author
self.container = container
@@ -44,14 +44,14 @@ final class ScriptableAuthor: NSObject, UniqueIdScriptingObject {
var scriptingUniqueId:Any {
return author.authorID
}
// MARK: --- Scriptable properties ---
@objc(url)
var url:String {
return self.author.url ?? ""
}
@objc(name)
var name:String {
return self.author.name ?? ""
+19 -19
View File
@@ -16,7 +16,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
let feed:Feed
let container:ScriptingObjectContainer
init (_ feed:Feed, container:ScriptingObjectContainer) {
self.feed = feed
self.container = container
@@ -49,11 +49,11 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
}
// MARK: --- ScriptingObjectContainer protocol ---
var scriptingClassDescription: NSScriptClassDescription {
return self.classDescription as! NSScriptClassDescription
}
func deleteElement(_ element:ScriptingObject) {
}
@@ -70,7 +70,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
}
return url
}
class func scriptableFeed(_ feed:Feed, account:Account, folder:Folder?) -> ScriptableFeed {
let scriptableAccount = ScriptableAccount(account)
if let folder = folder {
@@ -80,14 +80,14 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
return ScriptableFeed(feed, container:scriptableAccount)
}
}
class func scriptableFeed(for feed: Feed) -> ScriptableFeed? {
guard let account = feed.account else { return nil }
// Find the proper container hierarchy
let containers = account.existingContainers(withFeed: feed)
var folder: Folder? = nil
// Check if feed is in a folder
for container in containers {
if let foundFolder = container as? Folder {
@@ -95,23 +95,23 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
break
}
}
return scriptableFeed(feed, account: account, folder: folder)
}
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
let (account, folder) = command.accountAndFolderForNewChild()
guard let url = self.urlForNewFeed(arguments:arguments) else {return nil}
if let existingFeed = account.existingFeed(withURL:url) {
return scriptableFeed(existingFeed, account:account, folder:folder).objectSpecifier
}
let container: Container = folder != nil ? folder! : account
// We need to download the feed and parse it.
// RSParser does the callback for the download on the main thread.
// Because we can't wait here (on the main thread) for the callback, we have to return from this function.
@@ -119,7 +119,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
// but we don’t yet have the result of the event yet, so we prevent the Apple event from returning by calling
// suspendExecution(). When we get the callback, we supply the event result and call resumeExecution().
command.suspendExecution()
account.createFeed(url: url, name: titleFromArgs, container: container, validateFeed: true) { result in
switch result {
case .success(let feed):
@@ -131,7 +131,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
}
}
return nil
}
@@ -141,7 +141,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
var url:String {
return self.feed.url
}
@objc(name)
var name:String {
return self.feed.name ?? ""
@@ -166,7 +166,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
var opmlRepresentation:String {
return self.feed.OPMLString(indentLevel:0)
}
// MARK: --- scriptable elements ---
@objc(authors)
@@ -174,13 +174,13 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
let feedAuthors = feed.authors ?? []
return feedAuthors.map { ScriptableAuthor($0, container:self) } as NSArray
}
@objc(valueInAuthorsWithUniqueID:)
func valueInAuthors(withUniqueID id:String) -> ScriptableAuthor? {
guard let author = feed.authors?.first(where:{$0.authorID == id}) else { return nil }
return ScriptableAuthor(author, container:self)
}
@objc(articles)
var articles:NSArray {
let feedArticles = (try? feed.fetchArticles()) ?? Set<Article>()
@@ -190,7 +190,7 @@ final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectCo
})
return sortedArticles.map { ScriptableArticle($0, container:self) } as NSArray
}
@objc(valueInArticlesWithUniqueID:)
func valueInArticles(withUniqueID id:String) -> ScriptableArticle? {
let articles = (try? feed.fetchArticles()) ?? Set<Article>()
+9 -9
View File
@@ -43,13 +43,13 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject
var scriptingUniqueId:Any {
return folder.folderID
}
// MARK: --- ScriptingObjectContainer protocol ---
var scriptingClassDescription: NSScriptClassDescription {
return self.classDescription as! NSScriptClassDescription
}
func deleteElement(_ element:ScriptingObject) {
if let scriptableFeed = element as? ScriptableFeed {
BatchUpdate.shared.perform {
@@ -76,9 +76,9 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject
print("support for folders within folders is NYI");
return nil
}
command.suspendExecution()
account.addFolder(name) { result in
switch result {
case .success(let folder):
@@ -89,12 +89,12 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject
command.resumeExecution(withResult:nil)
}
}
return nil
}
// MARK: --- Scriptable elements ---
@objc(feeds)
var feeds:NSArray {
let feeds = Array(folder.topLevelFeeds)
@@ -137,7 +137,7 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject
}
// MARK: --- Scriptable properties ---
@objc(name)
var name:String {
return self.folder.name ?? ""
@@ -25,7 +25,7 @@ extension NSApplication : ScriptingObjectContainer {
var scriptingKey: String {
return "application"
}
@objc(currentArticle)
func currentArticle() -> ScriptableArticle? {
var scriptableArticle: ScriptableArticle?
@@ -51,18 +51,18 @@ extension NSApplication : ScriptingObjectContainer {
}
return scriptableArticles as NSArray
}
@objc(countOfSelectedArticles)
func countOfSelectedArticles() -> Int {
return appDelegate.scriptingSelectedArticles.count
}
@objc(objectInSelectedArticlesAtIndex:)
func objectInSelectedArticlesAtIndex(_ index: Int) -> ScriptableArticle? {
let articles = appDelegate.scriptingSelectedArticles
guard index >= 0 && index < articles.count else { return nil }
let article = articles[index]
if let feed = article.feed,
let scriptableFeed = ScriptableFeed.scriptableFeed(for: feed) {
return ScriptableArticle(article, container: scriptableFeed)
@@ -78,19 +78,19 @@ extension NSApplication : ScriptingObjectContainer {
let accounts = AccountManager.shared.accounts
return accounts.map { ScriptableAccount($0) } as NSArray
}
@objc(countOfAccounts)
func countOfAccounts() -> Int {
return AccountManager.shared.accounts.count
}
@objc(objectInAccountsAtIndex:)
func objectInAccountsAtIndex(_ index: Int) -> ScriptableAccount? {
let accounts = Array(AccountManager.shared.accounts)
guard index >= 0 && index < accounts.count else { return nil }
return ScriptableAccount(accounts[index])
}
@objc(valueInAccountsWithUniqueID:)
func valueInAccounts(withUniqueID id:String) -> ScriptableAccount? {
let accounts = AccountManager.shared.accounts
@@ -103,7 +103,7 @@ extension NSApplication : ScriptingObjectContainer {
this allows a script like 'articles of feed "The Shape of Everything"' as a shorthand
for 'articles of feed "The Shape of Everything" of account "On My Mac"'
*/
func allFeeds() -> [Feed] {
let accounts = AccountManager.shared.activeAccounts
let emptyFeeds:[Feed] = []
@@ -117,12 +117,12 @@ extension NSApplication : ScriptingObjectContainer {
func feeds() -> NSArray {
allFeeds().map { ScriptableFeed($0, container:self) } as NSArray
}
@objc(countOfFeeds)
func countOfFeeds() -> Int {
allFeeds().count
}
@objc(objectInFeedsAtIndex:)
func objectInFeedsAtIndex(_ index: Int) -> ScriptableFeed? {
let feeds = allFeeds()
@@ -18,7 +18,7 @@ extension NSScriptCommand {
}
return nil
}
func isCreateCommand(forClass whatClass:String) -> Bool {
guard let arguments = self.arguments else {return false}
guard let newObjectClass = arguments["ObjectClass"] as? Int else {return false}
@@ -44,7 +44,7 @@ extension NSScriptCommand {
} else if let subjectDescriptor = appleEvent.attributeDescriptor(forKeyword:"subj".fourCharCode) {
descriptorToConsider = subjectDescriptor
}
if let descriptorToConsider = descriptorToConsider {
guard let newContainerSpecifier = NSScriptObjectSpecifier(descriptor:descriptorToConsider) else {return (account, folder)}
let newContainer = newContainerSpecifier.objectsByEvaluatingSpecifier
@@ -25,7 +25,7 @@ extension ScriptingObjectContainer {
containerSpecifier:containerScriptObjectSpecifier, key:scriptingKey, name:name)
return specifier
}
func makeFormUniqueIDScriptObjectSpecifier(forObject object:UniqueIdScriptingObject) -> NSScriptObjectSpecifier? {
let containerClassDescription = self.scriptingClassDescription
let containerScriptObjectSpecifier = self.objectSpecifier