NetNewsWire/Shared/ExtensionPoints/ExtensionPointIdentifer.swift

100 lines
2.0 KiB
Swift
Raw Normal View History

//
// 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
2020-04-17 01:19:49 +02:00
case twitter(String)
case reddit(String)
2020-04-15 06:03:08 +02:00
var extensionPointType: ExtensionPoint.Type {
switch self {
#if os(macOS)
case .marsEdit:
return SendToMarsEditCommand.self
case .microblog:
return SendToMicroBlogCommand.self
#endif
case .twitter:
return TwitterFeedProvider.self
case .reddit:
return RedditFeedProvider.self
}
}
public var userInfo: [AnyHashable: AnyHashable] {
switch self {
#if os(macOS)
case .marsEdit:
return [
"type": "marsEdit"
]
case .microblog:
return [
"type": "microblog"
]
#endif
2020-04-17 01:19:49 +02:00
case .twitter(let screenName):
return [
2020-04-15 06:03:08 +02:00
"type": "twitter",
"screenName": screenName
]
case .reddit(let username):
return [
"type": "reddit",
"screenName": username
]
}
}
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
case "twitter":
2020-04-17 01:19:49 +02:00
guard let screenName = userInfo["screenName"] as? String else { return nil }
self = ExtensionPointIdentifer.twitter(screenName)
case "reddit":
guard let username = userInfo["username"] as? String else { return nil }
self = ExtensionPointIdentifer.twitter(username)
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
2020-04-17 01:19:49 +02:00
case .twitter(let screenName):
hasher.combine("twitter")
2020-04-15 06:03:08 +02:00
hasher.combine(screenName)
case .reddit(let username):
hasher.combine("reddit")
hasher.combine(username)
}
}
2020-04-15 06:03:08 +02:00
}