mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-11 01:04:05 +01:00
Convert findFaviconURLs to async await.
This commit is contained in:
parent
bf4b751c76
commit
019c499b80
@ -21,17 +21,13 @@ struct FaviconURLFinder {
|
|||||||
/// Finds favicon URLs in a web page.
|
/// Finds favicon URLs in a web page.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - homePageURL: The page to search.
|
/// - homePageURL: The page to search.
|
||||||
/// - completion: A closure called when the links have been found.
|
|
||||||
/// - urls: An array of favicon URLs as strings.
|
/// - urls: An array of favicon URLs as strings.
|
||||||
@MainActor static func findFaviconURLs(with homePageURL: String, _ completion: @escaping (_ urls: [String]?) -> Void) {
|
@MainActor static func findFaviconURLs(with homePageURL: String) async -> [String]? {
|
||||||
|
|
||||||
guard let _ = URL(unicodeString: homePageURL) else {
|
guard let _ = URL(unicodeString: homePageURL) else {
|
||||||
completion(nil)
|
return nil
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Task { @MainActor in
|
|
||||||
|
|
||||||
// If the favicon has an explicit type, check that for an ignored type; otherwise, check the file extension.
|
// If the favicon has an explicit type, check that for an ignored type; otherwise, check the file extension.
|
||||||
let htmlMetadata = try? await HTMLMetadataDownloader.downloadMetadata(for: homePageURL)
|
let htmlMetadata = try? await HTMLMetadataDownloader.downloadMetadata(for: homePageURL)
|
||||||
|
|
||||||
@ -39,8 +35,7 @@ struct FaviconURLFinder {
|
|||||||
shouldAllowFavicon(favicon) ? favicon.urlString : nil
|
shouldAllowFavicon(favicon) ? favicon.urlString : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
completion(faviconURLs)
|
return faviconURLs
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static func shouldAllowFavicon(_ favicon: RSHTMLMetadataFavicon) -> Bool {
|
static func shouldAllowFavicon(_ favicon: RSHTMLMetadataFavicon) -> Bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user