Normalize URLs when initing PasteboardFeed. Pull URL and String data from a pasteboard item when richer data is not available.
This commit is contained in:
parent
7d443955e8
commit
819b661898
@ -34,9 +34,9 @@ struct PasteboardFeed: Hashable {
|
|||||||
let accountID: String?
|
let accountID: String?
|
||||||
|
|
||||||
init(url: String, feedID: String?, homePageURL: String?, name: String?, editedName: String?, accountID: String?) {
|
init(url: String, feedID: String?, homePageURL: String?, name: String?, editedName: String?, accountID: String?) {
|
||||||
self.url = url
|
self.url = url.rs_normalizedURL()
|
||||||
self.feedID = feedID
|
self.feedID = feedID
|
||||||
self.homePageURL = homePageURL
|
self.homePageURL = homePageURL?.rs_normalizedURL()
|
||||||
self.name = name
|
self.name = name
|
||||||
self.editedName = editedName
|
self.editedName = editedName
|
||||||
self.accountID = accountID
|
self.accountID = accountID
|
||||||
@ -59,7 +59,6 @@ struct PasteboardFeed: Hashable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init?(pasteboardItem: NSPasteboardItem) {
|
init?(pasteboardItem: NSPasteboardItem) {
|
||||||
// TODO: This needs to handle strings and URLs also.
|
|
||||||
var pasteboardType: NSPasteboard.PasteboardType?
|
var pasteboardType: NSPasteboard.PasteboardType?
|
||||||
if pasteboardItem.types.contains(FeedPasteboardWriter.feedUTIInternalType) {
|
if pasteboardItem.types.contains(FeedPasteboardWriter.feedUTIInternalType) {
|
||||||
pasteboardType = FeedPasteboardWriter.feedUTIInternalType
|
pasteboardType = FeedPasteboardWriter.feedUTIInternalType
|
||||||
@ -67,15 +66,31 @@ struct PasteboardFeed: Hashable {
|
|||||||
else if pasteboardItem.types.contains(FeedPasteboardWriter.feedUTIType) {
|
else if pasteboardItem.types.contains(FeedPasteboardWriter.feedUTIType) {
|
||||||
pasteboardType = FeedPasteboardWriter.feedUTIType
|
pasteboardType = FeedPasteboardWriter.feedUTIType
|
||||||
}
|
}
|
||||||
guard let foundType = pasteboardType else {
|
if let foundType = pasteboardType {
|
||||||
|
if let feedDictionary = pasteboardItem.propertyList(forType: foundType) as? PasteboardFeedDictionary {
|
||||||
|
self.init(dictionary: feedDictionary)
|
||||||
|
return
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let feedDictionary = pasteboardItem.propertyList(forType: foundType) as? [String: String] else {
|
// Check for URL or a string that may be a URL.
|
||||||
return nil
|
if pasteboardItem.types.contains(.URL) {
|
||||||
|
pasteboardType = .URL
|
||||||
|
}
|
||||||
|
else if pasteboardItem.types.contains(.string) {
|
||||||
|
pasteboardType = .string
|
||||||
|
}
|
||||||
|
if let foundType = pasteboardType {
|
||||||
|
if let possibleURLString = pasteboardItem.string(forType: foundType) {
|
||||||
|
if possibleURLString.rs_stringMayBeURL() {
|
||||||
|
self.init(url: possibleURLString, feedID: nil, homePageURL: nil, name: nil, editedName: nil, accountID: nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.init(dictionary: feedDictionary)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
static func pasteboardFeeds(with pasteboard: NSPasteboard) -> Set<PasteboardFeed>? {
|
static func pasteboardFeeds(with pasteboard: NSPasteboard) -> Set<PasteboardFeed>? {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user