mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Add basic ExtensionPoint support.
This commit is contained in:
20
Shared/ExtensionPoints/ExtensionPoint.swift
Normal file
20
Shared/ExtensionPoints/ExtensionPoint.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// ExtensionPoint.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 4/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RSCore
|
||||
|
||||
protocol ExtensionPoint {
|
||||
|
||||
/// The title of the command.
|
||||
var title: String { get }
|
||||
|
||||
/// The template image for the command.
|
||||
var templateImage: RSImage { get }
|
||||
|
||||
}
|
||||
49
Shared/ExtensionPoints/ExtensionPointManager.swift
Normal file
49
Shared/ExtensionPoints/ExtensionPointManager.swift
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// ExtensionPointManager.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 4/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import FeedProvider
|
||||
import RSCore
|
||||
|
||||
struct ExtensionPointManager {
|
||||
|
||||
static let shared = ExtensionPointManager()
|
||||
|
||||
let marsEdit = SendToMarsEditCommand()
|
||||
let microblog = SendToMicroBlogCommand()
|
||||
let twitter = TwitterFeedProvider()
|
||||
|
||||
let availableExtensionPoints: [ExtensionPoint]
|
||||
let activeSendToCommands: [SendToCommand]
|
||||
let activeFeedProviders: [FeedProvider]
|
||||
|
||||
init() {
|
||||
#if os(macOS)
|
||||
#if DEBUG
|
||||
availableExtensionPoints = [marsEdit, microblog, twitter]
|
||||
activeSendToCommands = [marsEdit, microblog]
|
||||
activeFeedProviders = [twitter]
|
||||
#else
|
||||
availableExtensionPoints = [marsEdit, microblog, twitter]
|
||||
activeSendToCommands = [marsEdit, microblog]
|
||||
activeFeedProviders = [twitter]
|
||||
#endif
|
||||
#else
|
||||
#if DEBUG
|
||||
availableExtensionPoints = [twitter]
|
||||
activeSendToCommands = []()
|
||||
activeFeedProviders = [twitter]
|
||||
#else
|
||||
availableExtensionPoints = [twitter]
|
||||
activeSendToCommands = []()
|
||||
activeFeedProviders = [twitter]
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
14
Shared/ExtensionPoints/ExtensionPointType.swift
Normal file
14
Shared/ExtensionPoints/ExtensionPointType.swift
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// ExtensionPointType.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 4/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum ExtensionPoint: Int, Codable {
|
||||
case sentToCommand = 1
|
||||
case feedProvider = 2
|
||||
}
|
||||
@@ -10,14 +10,16 @@ import AppKit
|
||||
import RSCore
|
||||
import Articles
|
||||
|
||||
final class SendToMarsEditCommand: SendToCommand {
|
||||
final class SendToMarsEditCommand: ExtensionPoint, SendToCommand {
|
||||
|
||||
let title = "MarsEdit"
|
||||
let title = NSLocalizedString("MarsEdit", comment: "MarsEdit")
|
||||
let templateImage = AppAssets.extensionPointMarsEdit
|
||||
|
||||
var image: NSImage? {
|
||||
return appToUse()?.icon ?? nil
|
||||
}
|
||||
|
||||
|
||||
private let marsEditApps = [UserApp(bundleID: "com.red-sweater.marsedit4"), UserApp(bundleID: "com.red-sweater.marsedit")]
|
||||
|
||||
func canSendObject(_ object: Any?, selectedText: String?) -> Bool {
|
||||
@@ -12,9 +12,10 @@ import RSCore
|
||||
|
||||
// Not undoable.
|
||||
|
||||
final class SendToMicroBlogCommand: SendToCommand {
|
||||
final class SendToMicroBlogCommand: ExtensionPoint, SendToCommand {
|
||||
|
||||
let title = "Micro.blog"
|
||||
let title = NSLocalizedString("Micro.blog", comment: "Micro.blog")
|
||||
let templateImage = AppAssets.extensionPointMicroblog
|
||||
|
||||
var image: NSImage? {
|
||||
return microBlogApp.icon
|
||||
23
Shared/ExtensionPoints/TwitterFeedProvider+Extensions.swift
Normal file
23
Shared/ExtensionPoints/TwitterFeedProvider+Extensions.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// TwitterFeedProvider+Extensions.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 4/7/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import FeedProvider
|
||||
import RSCore
|
||||
|
||||
extension TwitterFeedProvider: ExtensionPoint {
|
||||
|
||||
var title: String {
|
||||
return NSLocalizedString("Twitter", comment: "Twitter")
|
||||
}
|
||||
|
||||
var templateImage: RSImage {
|
||||
return AppAssets.extensionPointTwitter
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user