Correctly save Twitter ExtensionPoints

This commit is contained in:
Maurice Parker 2020-04-14 23:03:08 -05:00
parent df79da291f
commit 9e0248c494
8 changed files with 23 additions and 25 deletions

View File

@ -26,9 +26,9 @@ public struct TwitterFeedProvider {
// TODO: save credentials here // TODO: save credentials here
} }
public init(username: String) { public init(userID: String, screenName: String) {
self.userID = username self.userID = userID
self.screenName = "Stored Somewhere" self.screenName = screenName
// TODO: load credentials here // TODO: load credentials here
} }

View File

@ -120,12 +120,8 @@ private extension ExtensionPointEnableWindowController {
switch result { switch result {
case .success(let tokenSuccess): case .success(let tokenSuccess):
ExtensionPointManager.shared.activateExtensionPoint(extensionPointType, tokenSuccess: 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) self.hostWindow!.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
case .failure(let oauthSwiftError): case .failure(let oauthSwiftError):
NSApplication.shared.presentError(oauthSwiftError) NSApplication.shared.presentError(oauthSwiftError)
} }

View File

@ -24,11 +24,11 @@ protocol ExtensionPoint {
extension ExtensionPoint { extension ExtensionPoint {
var templateImage: RSImage { var templateImage: RSImage {
return extensionPointID.type.templateImage return extensionPointID.extensionPointType.templateImage
} }
var description: NSAttributedString { var description: NSAttributedString {
return extensionPointID.type.description return extensionPointID.extensionPointType.description
} }
static func makeAttrString(_ text: String) -> NSMutableAttributedString { static func makeAttrString(_ text: String) -> NSMutableAttributedString {

View File

@ -10,13 +10,12 @@ import Foundation
import FeedProvider import FeedProvider
import RSCore import RSCore
enum ExtensionPointIdentifer: Hashable { enum ExtensionPointIdentifer: Hashable {
case marsEdit case marsEdit
case microblog case microblog
case twitter(String) case twitter(String, String)
var type: ExtensionPoint.Type { var extensionPointType: ExtensionPoint.Type {
switch self { switch self {
case .marsEdit: case .marsEdit:
return SendToMarsEditCommand.self return SendToMarsEditCommand.self
@ -37,10 +36,11 @@ enum ExtensionPointIdentifer: Hashable {
return [ return [
"type": "microblog" "type": "microblog"
] ]
case .twitter(let username): case .twitter(let userID, let screenName):
return [ return [
"type": "feed", "type": "twitter",
"username": username "userID": userID,
"screenName": screenName
] ]
} }
} }
@ -54,8 +54,8 @@ enum ExtensionPointIdentifer: Hashable {
case "microblog": case "microblog":
self = ExtensionPointIdentifer.microblog self = ExtensionPointIdentifer.microblog
case "twitter": case "twitter":
guard let username = userInfo["username"] as? String else { return nil } guard let userID = userInfo["userID"] as? String, let screenName = userInfo["screenName"] as? String else { return nil }
self = ExtensionPointIdentifer.twitter(username) self = ExtensionPointIdentifer.twitter(userID, screenName)
default: default:
return nil return nil
} }
@ -67,9 +67,11 @@ enum ExtensionPointIdentifer: Hashable {
hasher.combine("marsEdit") hasher.combine("marsEdit")
case .microblog: case .microblog:
hasher.combine("microblog") hasher.combine("microblog")
case .twitter(let username): case .twitter(let userID, let screenName):
hasher.combine("twitter") hasher.combine("twitter")
hasher.combine(username) hasher.combine(userID)
hasher.combine(screenName)
} }
} }
} }

View File

@ -23,7 +23,7 @@ final class ExtensionPointManager {
let possibleExtensionPointTypes: [ExtensionPoint.Type] let possibleExtensionPointTypes: [ExtensionPoint.Type]
var availableExtensionPointTypes: [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]() var available = [ExtensionPoint.Type]()
for possibleExtensionPointType in possibleExtensionPointTypes { for possibleExtensionPointType in possibleExtensionPointTypes {
if possibleExtensionPointType.isSinglton { if possibleExtensionPointType.isSinglton {
@ -118,8 +118,8 @@ private extension ExtensionPointManager {
return SendToMarsEditCommand() return SendToMarsEditCommand()
case .microblog: case .microblog:
return SendToMicroBlogCommand() return SendToMicroBlogCommand()
case .twitter(let username): case .twitter(let userID, let screenName):
return TwitterFeedProvider(username: username) return TwitterFeedProvider(userID: userID, screenName: screenName)
} }
} }

View File

@ -28,7 +28,7 @@ final class SendToMarsEditCommand: ExtensionPoint, SendToCommand {
let extensionPointID = ExtensionPointIdentifer.marsEdit let extensionPointID = ExtensionPointIdentifer.marsEdit
var title: String { var title: String {
return extensionPointID.type.title return extensionPointID.extensionPointType.title
} }
var image: NSImage? { var image: NSImage? {

View File

@ -31,7 +31,7 @@ final class SendToMicroBlogCommand: ExtensionPoint, SendToCommand {
let extensionPointID = ExtensionPointIdentifer.microblog let extensionPointID = ExtensionPointIdentifer.microblog
var title: String { var title: String {
return extensionPointID.type.title return extensionPointID.extensionPointType.title
} }
var image: NSImage? { var image: NSImage? {

View File

@ -28,7 +28,7 @@ extension TwitterFeedProvider: ExtensionPoint {
}() }()
var extensionPointID: ExtensionPointIdentifer { var extensionPointID: ExtensionPointIdentifer {
return ExtensionPointIdentifer.twitter(userID) return ExtensionPointIdentifer.twitter(userID, screenName)
} }
var title: String { var title: String {