Correctly save Twitter ExtensionPoints
This commit is contained in:
parent
df79da291f
commit
9e0248c494
|
@ -26,9 +26,9 @@ public struct TwitterFeedProvider {
|
|||
// TODO: save credentials here
|
||||
}
|
||||
|
||||
public init(username: String) {
|
||||
self.userID = username
|
||||
self.screenName = "Stored Somewhere"
|
||||
public init(userID: String, screenName: String) {
|
||||
self.userID = userID
|
||||
self.screenName = screenName
|
||||
|
||||
// TODO: load credentials here
|
||||
}
|
||||
|
|
|
@ -120,12 +120,8 @@ private extension ExtensionPointEnableWindowController {
|
|||
|
||||
switch result {
|
||||
case .success(let tokenSuccess):
|
||||
|
||||
ExtensionPointManager.shared.activateExtensionPoint(extensionPointType, tokenSuccess: tokenSuccess)
|
||||
let screenName = tokenSuccess.parameters["screen_name"] as? String ?? ""
|
||||
print("******************* \(screenName)")
|
||||
self.hostWindow!.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
|
||||
|
||||
case .failure(let oauthSwiftError):
|
||||
NSApplication.shared.presentError(oauthSwiftError)
|
||||
}
|
||||
|
|
|
@ -24,11 +24,11 @@ protocol ExtensionPoint {
|
|||
extension ExtensionPoint {
|
||||
|
||||
var templateImage: RSImage {
|
||||
return extensionPointID.type.templateImage
|
||||
return extensionPointID.extensionPointType.templateImage
|
||||
}
|
||||
|
||||
var description: NSAttributedString {
|
||||
return extensionPointID.type.description
|
||||
return extensionPointID.extensionPointType.description
|
||||
}
|
||||
|
||||
static func makeAttrString(_ text: String) -> NSMutableAttributedString {
|
||||
|
|
|
@ -10,13 +10,12 @@ import Foundation
|
|||
import FeedProvider
|
||||
import RSCore
|
||||
|
||||
|
||||
enum ExtensionPointIdentifer: Hashable {
|
||||
case marsEdit
|
||||
case microblog
|
||||
case twitter(String)
|
||||
case twitter(String, String)
|
||||
|
||||
var type: ExtensionPoint.Type {
|
||||
var extensionPointType: ExtensionPoint.Type {
|
||||
switch self {
|
||||
case .marsEdit:
|
||||
return SendToMarsEditCommand.self
|
||||
|
@ -37,10 +36,11 @@ enum ExtensionPointIdentifer: Hashable {
|
|||
return [
|
||||
"type": "microblog"
|
||||
]
|
||||
case .twitter(let username):
|
||||
case .twitter(let userID, let screenName):
|
||||
return [
|
||||
"type": "feed",
|
||||
"username": username
|
||||
"type": "twitter",
|
||||
"userID": userID,
|
||||
"screenName": screenName
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ enum ExtensionPointIdentifer: Hashable {
|
|||
case "microblog":
|
||||
self = ExtensionPointIdentifer.microblog
|
||||
case "twitter":
|
||||
guard let username = userInfo["username"] as? String else { return nil }
|
||||
self = ExtensionPointIdentifer.twitter(username)
|
||||
guard let userID = userInfo["userID"] as? String, let screenName = userInfo["screenName"] as? String else { return nil }
|
||||
self = ExtensionPointIdentifer.twitter(userID, screenName)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
@ -67,9 +67,11 @@ enum ExtensionPointIdentifer: Hashable {
|
|||
hasher.combine("marsEdit")
|
||||
case .microblog:
|
||||
hasher.combine("microblog")
|
||||
case .twitter(let username):
|
||||
case .twitter(let userID, let screenName):
|
||||
hasher.combine("twitter")
|
||||
hasher.combine(username)
|
||||
hasher.combine(userID)
|
||||
hasher.combine(screenName)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ final class ExtensionPointManager {
|
|||
let possibleExtensionPointTypes: [ExtensionPoint.Type]
|
||||
var availableExtensionPointTypes: [ExtensionPoint.Type] {
|
||||
|
||||
let activeExtensionPointTypes = activeExtensionPoints.keys.compactMap({ ObjectIdentifier($0.type) })
|
||||
let activeExtensionPointTypes = activeExtensionPoints.keys.compactMap({ ObjectIdentifier($0.extensionPointType) })
|
||||
var available = [ExtensionPoint.Type]()
|
||||
for possibleExtensionPointType in possibleExtensionPointTypes {
|
||||
if possibleExtensionPointType.isSinglton {
|
||||
|
@ -118,8 +118,8 @@ private extension ExtensionPointManager {
|
|||
return SendToMarsEditCommand()
|
||||
case .microblog:
|
||||
return SendToMicroBlogCommand()
|
||||
case .twitter(let username):
|
||||
return TwitterFeedProvider(username: username)
|
||||
case .twitter(let userID, let screenName):
|
||||
return TwitterFeedProvider(userID: userID, screenName: screenName)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ final class SendToMarsEditCommand: ExtensionPoint, SendToCommand {
|
|||
let extensionPointID = ExtensionPointIdentifer.marsEdit
|
||||
|
||||
var title: String {
|
||||
return extensionPointID.type.title
|
||||
return extensionPointID.extensionPointType.title
|
||||
}
|
||||
|
||||
var image: NSImage? {
|
||||
|
|
|
@ -31,7 +31,7 @@ final class SendToMicroBlogCommand: ExtensionPoint, SendToCommand {
|
|||
let extensionPointID = ExtensionPointIdentifer.microblog
|
||||
|
||||
var title: String {
|
||||
return extensionPointID.type.title
|
||||
return extensionPointID.extensionPointType.title
|
||||
}
|
||||
|
||||
var image: NSImage? {
|
||||
|
|
|
@ -28,7 +28,7 @@ extension TwitterFeedProvider: ExtensionPoint {
|
|||
}()
|
||||
|
||||
var extensionPointID: ExtensionPointIdentifer {
|
||||
return ExtensionPointIdentifer.twitter(userID)
|
||||
return ExtensionPointIdentifer.twitter(userID, screenName)
|
||||
}
|
||||
|
||||
var title: String {
|
||||
|
|
Loading…
Reference in New Issue