mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Fix deprecation warnings.
This commit is contained in:
@@ -11,6 +11,7 @@ import CoreServices
|
||||
import Articles
|
||||
import Account
|
||||
import RSCore
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
extension Notification.Name {
|
||||
|
||||
@@ -61,8 +62,6 @@ final class FaviconDownloader {
|
||||
loadHomePageToFaviconURLCache()
|
||||
loadHomePageURLsWithNoFaviconURLCache()
|
||||
|
||||
FaviconURLFinder.ignoredTypes = [kUTTypeScalableVectorGraphics as String]
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(didLoadFavicon(_:)), name: .DidLoadFavicon, object: nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,31 +9,14 @@
|
||||
import Foundation
|
||||
import CoreServices
|
||||
import RSParser
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
// The favicon URLs may be specified in the head section of the home page.
|
||||
|
||||
struct FaviconURLFinder {
|
||||
|
||||
private static var ignoredMimeTypes = [String]()
|
||||
private static var ignoredExtensions = [String]()
|
||||
|
||||
/// Uniform types to ignore when finding favicon URLs.
|
||||
static var ignoredTypes: [String]? {
|
||||
didSet {
|
||||
guard let ignoredTypes = ignoredTypes else {
|
||||
return
|
||||
}
|
||||
|
||||
for type in ignoredTypes {
|
||||
if let mimeTypes = UTTypeCopyAllTagsWithClass(type as CFString, kUTTagClassMIMEType)?.takeRetainedValue() {
|
||||
ignoredMimeTypes.append(contentsOf: mimeTypes as! [String])
|
||||
}
|
||||
if let extensions = UTTypeCopyAllTagsWithClass(type as CFString, kUTTagClassFilenameExtension)?.takeRetainedValue() {
|
||||
ignoredExtensions.append(contentsOf: extensions as! [String])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static var ignoredTypes = [UTType.svg]
|
||||
|
||||
/// Finds favicon URLs in a web page.
|
||||
/// - Parameters:
|
||||
@@ -48,24 +31,36 @@ struct FaviconURLFinder {
|
||||
}
|
||||
|
||||
// If the favicon has an explicit type, check that for an ignored type; otherwise, check the file extension.
|
||||
HTMLMetadataDownloader.downloadMetadata(for: homePageURL) { (htmlMetadata) in
|
||||
let faviconURLs = htmlMetadata?.favicons.compactMap({ (favicon) -> String? in
|
||||
if let type = favicon.type {
|
||||
if ignoredMimeTypes.contains(type) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
else {
|
||||
if let urlString = favicon.urlString, let url = URL(string: urlString), ignoredExtensions.contains(url.pathExtension) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
HTMLMetadataDownloader.downloadMetadata(for: homePageURL) { htmlMetadata in
|
||||
let faviconURLs = htmlMetadata?.favicons.compactMap { favicon -> String? in
|
||||
|
||||
guard shouldAllowFavicon(favicon) else {
|
||||
return nil
|
||||
}
|
||||
return favicon.urlString
|
||||
})
|
||||
}
|
||||
|
||||
completion(faviconURLs)
|
||||
}
|
||||
}
|
||||
|
||||
static func shouldAllowFavicon(_ favicon: RSHTMLMetadataFavicon) -> Bool {
|
||||
|
||||
// Check mime type.
|
||||
if let mimeType = favicon.type, let utType = UTType(mimeType: mimeType) {
|
||||
if ignoredTypes.contains(utType) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Check file extension.
|
||||
if let urlString = favicon.urlString, let url = URL(string: urlString), let utType = UTType(filenameExtension: url.pathExtension) {
|
||||
if ignoredTypes.contains(utType) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user