2020-04-09 03:22:13 +02:00
|
|
|
//
|
|
|
|
// ExtensionPointIdentifer.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 4/8/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2020-04-16 18:15:39 +02:00
|
|
|
import Account
|
2020-04-09 03:22:13 +02:00
|
|
|
import RSCore
|
|
|
|
|
|
|
|
enum ExtensionPointIdentifer: Hashable {
|
2020-04-16 15:25:40 +02:00
|
|
|
#if os(macOS)
|
2020-04-09 03:22:13 +02:00
|
|
|
case marsEdit
|
|
|
|
case microblog
|
2020-04-16 15:25:40 +02:00
|
|
|
#endif
|
2020-04-17 01:19:49 +02:00
|
|
|
case twitter(String)
|
2020-05-03 02:38:57 +02:00
|
|
|
case reddit(String)
|
|
|
|
|
2020-04-15 06:03:08 +02:00
|
|
|
var extensionPointType: ExtensionPoint.Type {
|
2020-04-09 03:22:13 +02:00
|
|
|
switch self {
|
2020-04-16 15:25:40 +02:00
|
|
|
#if os(macOS)
|
2020-04-09 03:22:13 +02:00
|
|
|
case .marsEdit:
|
2020-04-14 23:47:05 +02:00
|
|
|
return SendToMarsEditCommand.self
|
2020-04-09 03:22:13 +02:00
|
|
|
case .microblog:
|
2020-04-14 23:47:05 +02:00
|
|
|
return SendToMicroBlogCommand.self
|
2020-04-16 15:25:40 +02:00
|
|
|
#endif
|
2020-04-09 03:22:13 +02:00
|
|
|
case .twitter:
|
2020-04-14 23:47:05 +02:00
|
|
|
return TwitterFeedProvider.self
|
2020-05-03 02:38:57 +02:00
|
|
|
case .reddit:
|
|
|
|
return RedditFeedProvider.self
|
2020-04-09 03:22:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public var userInfo: [AnyHashable: AnyHashable] {
|
|
|
|
switch self {
|
2020-04-16 15:25:40 +02:00
|
|
|
#if os(macOS)
|
2020-04-09 03:22:13 +02:00
|
|
|
case .marsEdit:
|
|
|
|
return [
|
|
|
|
"type": "marsEdit"
|
|
|
|
]
|
|
|
|
case .microblog:
|
|
|
|
return [
|
|
|
|
"type": "microblog"
|
|
|
|
]
|
2020-04-16 15:25:40 +02:00
|
|
|
#endif
|
2020-04-17 01:19:49 +02:00
|
|
|
case .twitter(let screenName):
|
2020-04-09 03:22:13 +02:00
|
|
|
return [
|
2020-04-15 06:03:08 +02:00
|
|
|
"type": "twitter",
|
|
|
|
"screenName": screenName
|
2020-04-09 03:22:13 +02:00
|
|
|
]
|
2020-05-03 02:38:57 +02:00
|
|
|
case .reddit(let username):
|
|
|
|
return [
|
|
|
|
"type": "reddit",
|
|
|
|
"screenName": username
|
|
|
|
]
|
2020-04-09 03:22:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public init?(userInfo: [AnyHashable: AnyHashable]) {
|
|
|
|
guard let type = userInfo["type"] as? String else { return nil }
|
|
|
|
|
|
|
|
switch type {
|
2020-04-16 15:25:40 +02:00
|
|
|
#if os(macOS)
|
2020-04-09 03:22:13 +02:00
|
|
|
case "marsEdit":
|
|
|
|
self = ExtensionPointIdentifer.marsEdit
|
|
|
|
case "microblog":
|
|
|
|
self = ExtensionPointIdentifer.microblog
|
2020-04-16 15:25:40 +02:00
|
|
|
#endif
|
2020-04-09 03:22:13 +02:00
|
|
|
case "twitter":
|
2020-04-17 01:19:49 +02:00
|
|
|
guard let screenName = userInfo["screenName"] as? String else { return nil }
|
|
|
|
self = ExtensionPointIdentifer.twitter(screenName)
|
2020-05-03 02:38:57 +02:00
|
|
|
case "reddit":
|
|
|
|
guard let username = userInfo["username"] as? String else { return nil }
|
|
|
|
self = ExtensionPointIdentifer.twitter(username)
|
2020-04-09 03:22:13 +02:00
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public func hash(into hasher: inout Hasher) {
|
|
|
|
switch self {
|
2020-04-16 15:25:40 +02:00
|
|
|
#if os(macOS)
|
2020-04-09 03:22:13 +02:00
|
|
|
case .marsEdit:
|
|
|
|
hasher.combine("marsEdit")
|
|
|
|
case .microblog:
|
|
|
|
hasher.combine("microblog")
|
2020-04-16 15:25:40 +02:00
|
|
|
#endif
|
2020-04-17 01:19:49 +02:00
|
|
|
case .twitter(let screenName):
|
2020-04-09 03:22:13 +02:00
|
|
|
hasher.combine("twitter")
|
2020-04-15 06:03:08 +02:00
|
|
|
hasher.combine(screenName)
|
2020-05-03 02:38:57 +02:00
|
|
|
case .reddit(let username):
|
|
|
|
hasher.combine("reddit")
|
|
|
|
hasher.combine(username)
|
2020-04-09 03:22:13 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-15 06:03:08 +02:00
|
|
|
|
2020-04-09 03:22:13 +02:00
|
|
|
}
|