From 1bef45e1afc44a75be19cf5d0c460b6ac405918e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 25 Jun 2023 16:48:37 -0700 Subject: [PATCH] Remove ExtensionPoint code. --- Mac/AppAssets.swift | 8 +- Mac/AppDefaults.swift | 10 -- .../SharingServicePickerDelegate.swift | 5 +- .../Contents.json | 0 .../MarsEdit4Icon24.png | Bin .../MarsEdit4Icon48.png | Bin .../Contents.json | 0 .../micro.blog.24.png | Bin .../micro.blog.48.png | Bin NetNewsWire.xcodeproj/project.pbxproj | 24 ---- Shared/ExtensionPoints/ExtensionPoint.swift | 60 --------- .../ExtensionPointIdentifer.swift | 70 ---------- .../ExtensionPointManager.swift | 125 ------------------ .../SendToMarsEditCommand.swift | 35 +---- .../SendToMicroBlogCommand.swift | 30 +---- 15 files changed, 16 insertions(+), 351 deletions(-) rename Mac/Resources/Assets.xcassets/{extensionPointMarsEdit.imageset => MarsEditIcon.imageset}/Contents.json (100%) rename Mac/Resources/Assets.xcassets/{extensionPointMarsEdit.imageset => MarsEditIcon.imageset}/MarsEdit4Icon24.png (100%) rename Mac/Resources/Assets.xcassets/{extensionPointMarsEdit.imageset => MarsEditIcon.imageset}/MarsEdit4Icon48.png (100%) rename Mac/Resources/Assets.xcassets/{extensionPointMicroblog.imageset => MicroblogIcon.imageset}/Contents.json (100%) rename Mac/Resources/Assets.xcassets/{extensionPointMicroblog.imageset => MicroblogIcon.imageset}/micro.blog.24.png (100%) rename Mac/Resources/Assets.xcassets/{extensionPointMicroblog.imageset => MicroblogIcon.imageset}/micro.blog.48.png (100%) delete mode 100644 Shared/ExtensionPoints/ExtensionPoint.swift delete mode 100644 Shared/ExtensionPoints/ExtensionPointIdentifer.swift delete mode 100644 Shared/ExtensionPoints/ExtensionPointManager.swift diff --git a/Mac/AppAssets.swift b/Mac/AppAssets.swift index 50b446a03..94725f96d 100644 --- a/Mac/AppAssets.swift +++ b/Mac/AppAssets.swift @@ -79,12 +79,12 @@ struct AppAssets { return NSImage(systemSymbolName: "wind", accessibilityDescription: nil)! }() - static var extensionPointMarsEdit: RSImage = { - return RSImage(named: "extensionPointMarsEdit")! + static var marsEditIcon: RSImage = { + return RSImage(named: "MarsEditIcon")! }() - static var extensionPointMicroblog: RSImage = { - return RSImage(named: "extensionPointMicroblog")! + static var microblogIcon: RSImage = { + return RSImage(named: "MicroblogIcon")! }() static var faviconTemplateImage: RSImage = { diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index 7c910ca42..0b071f0b2 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -24,7 +24,6 @@ final class AppDefaults { struct Key { static let firstRunDate = "firstRunDate" static let windowState = "windowState" - static let activeExtensionPointIDs = "activeExtensionPointIDs" static let lastImageCacheFlushDate = "lastImageCacheFlushDate" static let sidebarFontSize = "sidebarFontSize" static let timelineFontSize = "timelineFontSize" @@ -85,15 +84,6 @@ final class AppDefaults { } } - var activeExtensionPointIDs: [[AnyHashable : AnyHashable]]? { - get { - return UserDefaults.standard.object(forKey: Key.activeExtensionPointIDs) as? [[AnyHashable : AnyHashable]] - } - set { - UserDefaults.standard.set(newValue, forKey: Key.activeExtensionPointIDs) - } - } - var lastImageCacheFlushDate: Date? { get { return AppDefaults.date(for: Key.lastImageCacheFlushDate) diff --git a/Mac/MainWindow/SharingServicePickerDelegate.swift b/Mac/MainWindow/SharingServicePickerDelegate.swift index 13c989460..b95793e2e 100644 --- a/Mac/MainWindow/SharingServicePickerDelegate.swift +++ b/Mac/MainWindow/SharingServicePickerDelegate.swift @@ -27,7 +27,9 @@ import RSCore } static func customSharingServices(for items: [Any]) -> [NSSharingService] { - let customServices = ExtensionPointManager.shared.activeSendToCommands.compactMap { (sendToCommand) -> NSSharingService? in + let customServices: [SendToCommand] = [SendToMarsEditCommand(), SendToMicroBlogCommand()] + + return customServices.compactMap { (sendToCommand) -> NSSharingService? in guard let object = items.first else { return nil @@ -42,6 +44,5 @@ import RSCore sendToCommand.sendObject(object, selectedText: nil) } } - return customServices } } diff --git a/Mac/Resources/Assets.xcassets/extensionPointMarsEdit.imageset/Contents.json b/Mac/Resources/Assets.xcassets/MarsEditIcon.imageset/Contents.json similarity index 100% rename from Mac/Resources/Assets.xcassets/extensionPointMarsEdit.imageset/Contents.json rename to Mac/Resources/Assets.xcassets/MarsEditIcon.imageset/Contents.json diff --git a/Mac/Resources/Assets.xcassets/extensionPointMarsEdit.imageset/MarsEdit4Icon24.png b/Mac/Resources/Assets.xcassets/MarsEditIcon.imageset/MarsEdit4Icon24.png similarity index 100% rename from Mac/Resources/Assets.xcassets/extensionPointMarsEdit.imageset/MarsEdit4Icon24.png rename to Mac/Resources/Assets.xcassets/MarsEditIcon.imageset/MarsEdit4Icon24.png diff --git a/Mac/Resources/Assets.xcassets/extensionPointMarsEdit.imageset/MarsEdit4Icon48.png b/Mac/Resources/Assets.xcassets/MarsEditIcon.imageset/MarsEdit4Icon48.png similarity index 100% rename from Mac/Resources/Assets.xcassets/extensionPointMarsEdit.imageset/MarsEdit4Icon48.png rename to Mac/Resources/Assets.xcassets/MarsEditIcon.imageset/MarsEdit4Icon48.png diff --git a/Mac/Resources/Assets.xcassets/extensionPointMicroblog.imageset/Contents.json b/Mac/Resources/Assets.xcassets/MicroblogIcon.imageset/Contents.json similarity index 100% rename from Mac/Resources/Assets.xcassets/extensionPointMicroblog.imageset/Contents.json rename to Mac/Resources/Assets.xcassets/MicroblogIcon.imageset/Contents.json diff --git a/Mac/Resources/Assets.xcassets/extensionPointMicroblog.imageset/micro.blog.24.png b/Mac/Resources/Assets.xcassets/MicroblogIcon.imageset/micro.blog.24.png similarity index 100% rename from Mac/Resources/Assets.xcassets/extensionPointMicroblog.imageset/micro.blog.24.png rename to Mac/Resources/Assets.xcassets/MicroblogIcon.imageset/micro.blog.24.png diff --git a/Mac/Resources/Assets.xcassets/extensionPointMicroblog.imageset/micro.blog.48.png b/Mac/Resources/Assets.xcassets/MicroblogIcon.imageset/micro.blog.48.png similarity index 100% rename from Mac/Resources/Assets.xcassets/extensionPointMicroblog.imageset/micro.blog.48.png rename to Mac/Resources/Assets.xcassets/MicroblogIcon.imageset/micro.blog.48.png diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index ce64acfbe..7b1109b52 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -102,8 +102,6 @@ 510C418424E5D1B4008226FD /* ExtensionFeedAddRequestFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51B5C8BF23F3866C00032075 /* ExtensionFeedAddRequestFile.swift */; }; 510C418524E5D1B4008226FD /* ExtensionContainers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51B5C87623F22B8200032075 /* ExtensionContainers.swift */; }; 510C418624E5D1B4008226FD /* ExtensionFeedAddRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51B5C87A23F2317700032075 /* ExtensionFeedAddRequest.swift */; }; - 510C43F7243D035C009F70C3 /* ExtensionPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 510C43F6243D035C009F70C3 /* ExtensionPoint.swift */; }; - 510C43F8243D035C009F70C3 /* ExtensionPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 510C43F6243D035C009F70C3 /* ExtensionPoint.swift */; }; 510FFAB326EEA22C00F32265 /* ArticleThemesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 510FFAB226EEA22C00F32265 /* ArticleThemesTableViewController.swift */; }; 51102165233A7D6C0007A5F7 /* ArticleExtractorButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51102164233A7D6C0007A5F7 /* ArticleExtractorButton.swift */; }; 5110C37D2373A8D100A9C04F /* InspectorIconHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5110C37C2373A8D100A9C04F /* InspectorIconHeaderView.swift */; }; @@ -211,13 +209,6 @@ 514C16DF24D2EF15009A3AFA /* RSTree in Embed Frameworks */ = {isa = PBXBuildFile; productRef = 514C16DD24D2EF15009A3AFA /* RSTree */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 514C16E124D2EF38009A3AFA /* RSCoreResources in Frameworks */ = {isa = PBXBuildFile; productRef = 514C16E024D2EF38009A3AFA /* RSCoreResources */; }; 5154368B229404D1005E1CDF /* FaviconGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EF0F76227716200050506E /* FaviconGenerator.swift */; }; - 515A50E6243D07A90089E588 /* ExtensionPointManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 515A50E5243D07A90089E588 /* ExtensionPointManager.swift */; }; - 515A50E7243D07A90089E588 /* ExtensionPointManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 515A50E5243D07A90089E588 /* ExtensionPointManager.swift */; }; - 515A5177243E90200089E588 /* ExtensionPointIdentifer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 515A5176243E90200089E588 /* ExtensionPointIdentifer.swift */; }; - 515A5178243E90200089E588 /* ExtensionPointIdentifer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 515A5176243E90200089E588 /* ExtensionPointIdentifer.swift */; }; - 515A517B243E90260089E588 /* ExtensionPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 510C43F6243D035C009F70C3 /* ExtensionPoint.swift */; }; - 515A517C243E90260089E588 /* ExtensionPointManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 515A50E5243D07A90089E588 /* ExtensionPointManager.swift */; }; - 515A5181243E90260089E588 /* ExtensionPointIdentifer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 515A5176243E90200089E588 /* ExtensionPointIdentifer.swift */; }; 515D4FCA23257CB500EE1167 /* Node-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97971ED9EFAA007D329B /* Node-Extensions.swift */; }; 515D4FCC2325815A00EE1167 /* SafariExt.js in Resources */ = {isa = PBXBuildFile; fileRef = 515D4FCB2325815A00EE1167 /* SafariExt.js */; }; 516244E3241E19F000B61C47 /* ColorPaletteTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 516244E2241E19F000B61C47 /* ColorPaletteTableViewController.swift */; }; @@ -1153,7 +1144,6 @@ 510C416524E5CDE3008226FD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 510C416624E5CDE3008226FD /* ShareExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ShareExtension.entitlements; sourceTree = ""; }; 510C418724E5D2E3008226FD /* NetNewsWire_shareextension_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetNewsWire_shareextension_target.xcconfig; sourceTree = ""; }; - 510C43F6243D035C009F70C3 /* ExtensionPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionPoint.swift; sourceTree = ""; }; 510FFAB226EEA22C00F32265 /* ArticleThemesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleThemesTableViewController.swift; sourceTree = ""; }; 51102164233A7D6C0007A5F7 /* ArticleExtractorButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleExtractorButton.swift; sourceTree = ""; }; 5110C37C2373A8D100A9C04F /* InspectorIconHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectorIconHeaderView.swift; sourceTree = ""; }; @@ -1204,8 +1194,6 @@ 5148F44A2336DB4700F8CD8B /* MasterTimelineTitleView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MasterTimelineTitleView.xib; sourceTree = ""; }; 5148F4542336DB7000F8CD8B /* MasterTimelineTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterTimelineTitleView.swift; sourceTree = ""; }; 514B7C8223205EFB00BAC947 /* RootSplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootSplitViewController.swift; sourceTree = ""; }; - 515A50E5243D07A90089E588 /* ExtensionPointManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionPointManager.swift; sourceTree = ""; }; - 515A5176243E90200089E588 /* ExtensionPointIdentifer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionPointIdentifer.swift; sourceTree = ""; }; 515D4FCB2325815A00EE1167 /* SafariExt.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = SafariExt.js; sourceTree = ""; }; 515D4FCD2325909200EE1167 /* NetNewsWire_iOS_ShareExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NetNewsWire_iOS_ShareExtension.entitlements; sourceTree = ""; }; 515D4FCE2325B3D000EE1167 /* NetNewsWire_iOSshareextension_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetNewsWire_iOSshareextension_target.xcconfig; sourceTree = ""; }; @@ -1798,9 +1786,6 @@ 510C43F5243D0325009F70C3 /* ExtensionPoints */ = { isa = PBXGroup; children = ( - 510C43F6243D035C009F70C3 /* ExtensionPoint.swift */, - 515A5176243E90200089E588 /* ExtensionPointIdentifer.swift */, - 515A50E5243D07A90089E588 /* ExtensionPointManager.swift */, 84A1500420048DDF0046AD9A /* SendToMarsEditCommand.swift */, 84A14FF220048CA70046AD9A /* SendToMicroBlogCommand.swift */, ); @@ -3823,7 +3808,6 @@ 65ED3FC8235DEF6C0081F399 /* SidebarCellLayout.swift in Sources */, 65ED3FC9235DEF6C0081F399 /* SmartFeedPasteboardWriter.swift in Sources */, 65ED3FCA235DEF6C0081F399 /* SmartFeedsController.swift in Sources */, - 515A5178243E90200089E588 /* ExtensionPointIdentifer.swift in Sources */, 65ED3FCB235DEF6C0081F399 /* SidebarViewController.swift in Sources */, 51BC4B00247277E0000A6ED8 /* URL-Extensions.swift in Sources */, 65ED3FCD235DEF6C0081F399 /* SidebarOutlineView.swift in Sources */, @@ -3870,7 +3854,6 @@ 65ED3FF0235DEF6C0081F399 /* ArticleThemesManager.swift in Sources */, 65ED3FF1235DEF6C0081F399 /* DetailContainerView.swift in Sources */, 65ED3FF2235DEF6C0081F399 /* SharingServiceDelegate.swift in Sources */, - 515A50E7243D07A90089E588 /* ExtensionPointManager.swift in Sources */, 65ED3FF3235DEF6C0081F399 /* ArticleSorter.swift in Sources */, 65ED3FF4235DEF6C0081F399 /* TimelineViewController+ContextualMenus.swift in Sources */, 65ED3FF5235DEF6C0081F399 /* ArticleStringFormatter.swift in Sources */, @@ -3908,7 +3891,6 @@ 65ED4012235DEF6C0081F399 /* TimelineContainerViewController.swift in Sources */, 65ED4013235DEF6C0081F399 /* MainWIndowKeyboardHandler.swift in Sources */, 65ED4014235DEF6C0081F399 /* PasteboardWebFeed.swift in Sources */, - 510C43F8243D035C009F70C3 /* ExtensionPoint.swift in Sources */, 510C417B24E5D1AE008226FD /* ExtensionContainersFile.swift in Sources */, 65ED4015235DEF6C0081F399 /* AccountsDetailViewController.swift in Sources */, 65ED4016235DEF6C0081F399 /* DetailViewController.swift in Sources */, @@ -4088,7 +4070,6 @@ 5108F6D42375EEEF001ABC45 /* TimelinePreviewTableViewController.swift in Sources */, 84CAFCA522BC8C08007694F0 /* FetchRequestQueue.swift in Sources */, 512392BE24E33A3C00F11704 /* RedditSelectAccountTableViewController.swift in Sources */, - 515A517B243E90260089E588 /* ExtensionPoint.swift in Sources */, 51C4529C22650A1000C03939 /* SingleFaviconDownloader.swift in Sources */, 17D643B226F8A436008D4C05 /* ArticleThemeDownloader.swift in Sources */, 51E595A6228CC36500FCC42B /* ArticleStatusSyncTimer.swift in Sources */, @@ -4096,7 +4077,6 @@ 512392C524E3451400F11704 /* TwitterEnterDetailTableViewController.swift in Sources */, 512AF9C2236ED52C0066F8BE /* ImageHeaderView.swift in Sources */, 512392C124E33A3C00F11704 /* RedditSelectTypeTableViewController.swift in Sources */, - 515A5181243E90260089E588 /* ExtensionPointIdentifer.swift in Sources */, 51A1699F235E10D700EB091F /* AboutViewController.swift in Sources */, 51C45290226509C100C03939 /* PseudoFeed.swift in Sources */, 512392C624E3451400F11704 /* TwitterSelectAccountTableViewController.swift in Sources */, @@ -4149,7 +4129,6 @@ 51C4528D2265095F00C03939 /* AddFolderViewController.swift in Sources */, 51C452782265091600C03939 /* MasterTimelineCellData.swift in Sources */, 5148F4552336DB7000F8CD8B /* MasterTimelineTitleView.swift in Sources */, - 515A517C243E90260089E588 /* ExtensionPointManager.swift in Sources */, 51627A6723861DA3007B3B4B /* MasterFeedViewController+Drag.swift in Sources */, 51FFF0C4235EE8E5002762AA /* VibrantButton.swift in Sources */, 51C45259226508D300C03939 /* AppDefaults.swift in Sources */, @@ -4206,9 +4185,7 @@ D5907D7F2004AC00005947E5 /* NSApplication+Scriptability.swift in Sources */, 8405DD9C22153BD7008CE1BF /* NSView-Extensions.swift in Sources */, 849A979F1ED9F130007D329B /* SidebarCell.swift in Sources */, - 515A50E6243D07A90089E588 /* ExtensionPointManager.swift in Sources */, 51E595A5228CC36500FCC42B /* ArticleStatusSyncTimer.swift in Sources */, - 515A5177243E90200089E588 /* ExtensionPointIdentifer.swift in Sources */, 849A97651ED9EB96007D329B /* WebFeedTreeControllerDelegate.swift in Sources */, 849A97671ED9EB96007D329B /* UnreadCountView.swift in Sources */, 510C418024E5D1AE008226FD /* ExtensionFeedAddRequestFile.swift in Sources */, @@ -4323,7 +4300,6 @@ 179C39EB26F76B3800D4E741 /* ArticleThemePlist.swift in Sources */, 849A97A31ED9F180007D329B /* FolderTreeControllerDelegate.swift in Sources */, 51126DA4225FDE2F00722696 /* RSImage-Extensions.swift in Sources */, - 510C43F7243D035C009F70C3 /* ExtensionPoint.swift in Sources */, 845A29091FC74B8E007B49E3 /* SingleFaviconDownloader.swift in Sources */, D5F4EDB720074D6500B9E363 /* WebFeed+Scriptability.swift in Sources */, 84E850861FCB60CE0072EA88 /* AuthorAvatarDownloader.swift in Sources */, diff --git a/Shared/ExtensionPoints/ExtensionPoint.swift b/Shared/ExtensionPoints/ExtensionPoint.swift deleted file mode 100644 index cbc2ef645..000000000 --- a/Shared/ExtensionPoints/ExtensionPoint.swift +++ /dev/null @@ -1,60 +0,0 @@ -// -// ExtensionPoint.swift -// NetNewsWire -// -// Created by Maurice Parker on 4/7/20. -// Copyright © 2020 Ranchero Software. All rights reserved. -// - -#if os(macOS) -import AppKit -#else -import UIKit -#endif -import RSCore - -protocol ExtensionPoint { - - static var isSinglton: Bool { get } - static var isDeveloperBuildRestricted: Bool { get } - static var title: String { get } - static var image: RSImage { get } - static var description: NSAttributedString { get } - - var title: String { get } - var extensionPointID: ExtensionPointIdentifer { get } - -} - -extension ExtensionPoint { - - var image: RSImage { - return extensionPointID.extensionPointType.image - } - - var description: NSAttributedString { - return extensionPointID.extensionPointType.description - } - - static func makeAttrString(_ text: String) -> NSMutableAttributedString { - let paragraphStyle = NSMutableParagraphStyle() - paragraphStyle.alignment = .center - - #if os(macOS) - let attrs = [ - NSAttributedString.Key.paragraphStyle: paragraphStyle, - NSAttributedString.Key.font: NSFont.systemFont(ofSize: NSFont.systemFontSize), - NSAttributedString.Key.foregroundColor: NSColor.textColor - ] - #else - let attrs = [ - NSAttributedString.Key.paragraphStyle: paragraphStyle, - NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .body), - NSAttributedString.Key.foregroundColor: UIColor.label - ] - #endif - - return NSMutableAttributedString(string: text, attributes: attrs) - } - -} diff --git a/Shared/ExtensionPoints/ExtensionPointIdentifer.swift b/Shared/ExtensionPoints/ExtensionPointIdentifer.swift deleted file mode 100644 index 2548d1220..000000000 --- a/Shared/ExtensionPoints/ExtensionPointIdentifer.swift +++ /dev/null @@ -1,70 +0,0 @@ -// -// ExtensionPointIdentifer.swift -// NetNewsWire -// -// Created by Maurice Parker on 4/8/20. -// Copyright © 2020 Ranchero Software. All rights reserved. -// - -import Foundation -import Account -import RSCore - -enum ExtensionPointIdentifer: Hashable { -#if os(macOS) - case marsEdit - case microblog -#endif - - var extensionPointType: ExtensionPoint.Type { - switch self { -#if os(macOS) - case .marsEdit: - return SendToMarsEditCommand.self - case .microblog: - return SendToMicroBlogCommand.self -#endif - } - } - - public var userInfo: [AnyHashable: AnyHashable] { - switch self { -#if os(macOS) - case .marsEdit: - return [ - "type": "marsEdit" - ] - case .microblog: - return [ - "type": "microblog" - ] -#endif - } - } - - public init?(userInfo: [AnyHashable: AnyHashable]) { - guard let type = userInfo["type"] as? String else { return nil } - - switch type { -#if os(macOS) - case "marsEdit": - self = ExtensionPointIdentifer.marsEdit - case "microblog": - self = ExtensionPointIdentifer.microblog -#endif - default: - return nil - } - } - - public func hash(into hasher: inout Hasher) { - switch self { -#if os(macOS) - case .marsEdit: - hasher.combine("marsEdit") - case .microblog: - hasher.combine("microblog") -#endif - } - } -} diff --git a/Shared/ExtensionPoints/ExtensionPointManager.swift b/Shared/ExtensionPoints/ExtensionPointManager.swift deleted file mode 100644 index 964d7aaa7..000000000 --- a/Shared/ExtensionPoints/ExtensionPointManager.swift +++ /dev/null @@ -1,125 +0,0 @@ -// -// ExtensionPointManager.swift -// NetNewsWire -// -// Created by Maurice Parker on 4/7/20. -// Copyright © 2020 Ranchero Software. All rights reserved. -// - -import Foundation -import Account -import RSCore -import OAuthSwift - -public extension Notification.Name { - static let ActiveExtensionPointsDidChange = Notification.Name(rawValue: "ActiveExtensionPointsDidChange") -} - -public enum ExtensionPointManagerError: LocalizedError { - case unableToCreate - - public var localizedDescription: String { - switch self { - case .unableToCreate: - return NSLocalizedString("Unable to create extension.", comment: "Unable to create extension") - } - } -} - - -final class ExtensionPointManager { - - static let shared = ExtensionPointManager() - - var activeExtensionPoints = [ExtensionPointIdentifer: ExtensionPoint]() - let possibleExtensionPointTypes: [ExtensionPoint.Type] - var availableExtensionPointTypes: [ExtensionPoint.Type] { - - let activeExtensionPointTypes = activeExtensionPoints.keys.compactMap({ ObjectIdentifier($0.extensionPointType) }) - var available = [ExtensionPoint.Type]() - for possibleExtensionPointType in possibleExtensionPointTypes { - if !(AppDefaults.shared.isDeveloperBuild && possibleExtensionPointType.isDeveloperBuildRestricted) { - if possibleExtensionPointType.isSinglton { - if !activeExtensionPointTypes.contains(ObjectIdentifier(possibleExtensionPointType)) { - available.append(possibleExtensionPointType) - } - } else { - available.append(possibleExtensionPointType) - } - } - } - - return available - - } - - var activeSendToCommands: [SendToCommand] { - var commands = activeExtensionPoints.values.compactMap({ return $0 as? SendToCommand }) - - // These two SendToCommands don't need logins and are always active - #if os(macOS) - commands.append(SendToMarsEditCommand()) - commands.append(SendToMicroBlogCommand()) - #endif - - return commands - } - - init() { - possibleExtensionPointTypes = [] - loadExtensionPoints() - } - - func activateExtensionPoint(_ extensionPointType: ExtensionPoint.Type, tokenSuccess: OAuthSwift.TokenSuccess? = nil, completion: @escaping (Result) -> Void) { - self.extensionPoint(for: extensionPointType, tokenSuccess: tokenSuccess) { result in - switch result { - case .success(let extensionPoint): - self.activeExtensionPoints[extensionPoint.extensionPointID] = extensionPoint - self.saveExtensionPointIDs() - completion(.success(())) - case .failure(let error): - completion(.failure(error)) - } - } - } - - func deactivateExtensionPoint(_ extensionPointID: ExtensionPointIdentifer) { - activeExtensionPoints[extensionPointID] = nil - saveExtensionPointIDs() - } - -} - -private extension ExtensionPointManager { - - func loadExtensionPoints() { - if let extensionPointUserInfos = AppDefaults.shared.activeExtensionPointIDs { - for extensionPointUserInfo in extensionPointUserInfos { - if let extensionPointID = ExtensionPointIdentifer(userInfo: extensionPointUserInfo) { - activeExtensionPoints[extensionPointID] = extensionPoint(for: extensionPointID) - } - } - } - } - - func saveExtensionPointIDs() { - AppDefaults.shared.activeExtensionPointIDs = activeExtensionPoints.keys.map({ $0.userInfo }) - NotificationCenter.default.post(name: .ActiveExtensionPointsDidChange, object: nil, userInfo: nil) - } - - func extensionPoint(for extensionPointType: ExtensionPoint.Type, tokenSuccess: OAuthSwift.TokenSuccess?, completion: @escaping (Result) -> Void) { - switch extensionPointType { - default: - break - } - } - - func extensionPoint(for extensionPointID: ExtensionPointIdentifer) -> ExtensionPoint? { - switch extensionPointID { - #if os(macOS) - default: - return nil - #endif - } - } -} diff --git a/Shared/ExtensionPoints/SendToMarsEditCommand.swift b/Shared/ExtensionPoints/SendToMarsEditCommand.swift index c921d71c3..b86a661d1 100644 --- a/Shared/ExtensionPoints/SendToMarsEditCommand.swift +++ b/Shared/ExtensionPoints/SendToMarsEditCommand.swift @@ -10,40 +10,15 @@ import AppKit import RSCore import Articles -final class SendToMarsEditCommand: ExtensionPoint, SendToCommand { - - static var isSinglton = true - static var isDeveloperBuildRestricted = false - static var title = NSLocalizedString("MarsEdit", comment: "MarsEdit") - static var image = AppAssets.extensionPointMarsEdit - static var description: NSAttributedString = { - let attrString = SendToMarsEditCommand.makeAttrString("This extension enables share menu functionality to send selected article text to MarsEdit. You need the MarsEdit application for this to work.") - let range = NSRange(location: 81, length: 8) - attrString.beginEditing() - attrString.addAttribute(NSAttributedString.Key.link, value: "https://red-sweater.com/marsedit/", range: range) - attrString.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.systemBlue, range: range) - attrString.endEditing() - return attrString - }() - - let extensionPointID = ExtensionPointIdentifer.marsEdit - - var title: String { - return extensionPointID.extensionPointType.title - } - - var image: NSImage? { - return appToUse()?.icon ?? nil - } +final class SendToMarsEditCommand: SendToCommand { + + let title = "MarsEdit" + let image: RSImage? = AppAssets.marsEditIcon private let marsEditApps = [UserApp(bundleID: "com.red-sweater.marsedit4"), UserApp(bundleID: "com.red-sweater.marsedit")] func canSendObject(_ object: Any?, selectedText: String?) -> Bool { - - if let _ = appToUse() { - return true - } - return false + appToUse() != nil } func sendObject(_ object: Any?, selectedText: String?) { diff --git a/Shared/ExtensionPoints/SendToMicroBlogCommand.swift b/Shared/ExtensionPoints/SendToMicroBlogCommand.swift index 1c8bc031b..bd5d000d2 100644 --- a/Shared/ExtensionPoints/SendToMicroBlogCommand.swift +++ b/Shared/ExtensionPoints/SendToMicroBlogCommand.swift @@ -12,32 +12,10 @@ import RSCore // Not undoable. -final class SendToMicroBlogCommand: ExtensionPoint, SendToCommand { - - static var isSinglton = true - static var isDeveloperBuildRestricted = false - static var title: String = NSLocalizedString("Micro.blog", comment: "Micro.blog") - static var image = AppAssets.extensionPointMicroblog - static var description: NSAttributedString = { - let attrString = SendToMicroBlogCommand.makeAttrString("This extension enables share menu functionality to send selected article text to Micro.blog. You need the Micro.blog application for this to work.") - let range = NSRange(location: 81, length: 10) - attrString.beginEditing() - attrString.addAttribute(NSAttributedString.Key.link, value: "https://micro.blog", range: range) - attrString.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.systemBlue, range: range) - attrString.endEditing() - return attrString - - }() - - let extensionPointID = ExtensionPointIdentifer.microblog - - var title: String { - return extensionPointID.extensionPointType.title - } - - var image: NSImage? { - return microBlogApp.icon - } +final class SendToMicroBlogCommand: SendToCommand { + + let title = "Micro.blog" + let image: RSImage? = AppAssets.microblogIcon private let microBlogApp = UserApp(bundleID: "blog.micro.mac")