Convert methods to async await.
This commit is contained in:
parent
019c499b80
commit
8acda7be1c
@ -14,7 +14,6 @@ import UniformTypeIdentifiers
|
||||
import Core
|
||||
|
||||
extension Notification.Name {
|
||||
|
||||
static let FaviconDidBecomeAvailable = Notification.Name("FaviconDidBecomeAvailableNotification") // userInfo key: FaviconDownloader.UserInfoKey.faviconURL
|
||||
}
|
||||
|
||||
@ -134,15 +133,15 @@ extension Notification.Name {
|
||||
}
|
||||
|
||||
Task { @MainActor in
|
||||
findFaviconURLs(with: url) { (faviconURLs) in
|
||||
if let faviconURLs = faviconURLs {
|
||||
// If the site explicitly specifies favicon.ico, it will appear twice.
|
||||
self.currentHomePageHasOnlyFaviconICO = faviconURLs.count == 1
|
||||
|
||||
if let firstIconURL = faviconURLs.first {
|
||||
let _ = self.favicon(with: firstIconURL, homePageURL: url)
|
||||
self.remainingFaviconURLs[url] = faviconURLs.dropFirst()
|
||||
}
|
||||
if let faviconURLs = await findFaviconURLs(with: url) {
|
||||
|
||||
// If the site explicitly specifies favicon.ico, it will appear twice.
|
||||
self.currentHomePageHasOnlyFaviconICO = faviconURLs.count == 1
|
||||
|
||||
if let firstIconURL = faviconURLs.first {
|
||||
let _ = self.favicon(with: firstIconURL, homePageURL: url)
|
||||
self.remainingFaviconURLs[url] = faviconURLs.dropFirst()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -199,31 +198,21 @@ private extension FaviconDownloader {
|
||||
|
||||
static let localeForLowercasing = Locale(identifier: "en_US")
|
||||
|
||||
func findFaviconURLs(with homePageURL: String, _ completion: @escaping ([String]?) -> Void) {
|
||||
func findFaviconURLs(with homePageURL: String) async -> [String]? {
|
||||
|
||||
guard let url = URL(unicodeString: homePageURL) else {
|
||||
completion(nil)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
guard let faviconURLs = await FaviconURLFinder.findFaviconURLs(with: homePageURL) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
FaviconURLFinder.findFaviconURLs(with: homePageURL) { (faviconURLs) in
|
||||
guard var faviconURLs = faviconURLs else {
|
||||
completion(nil)
|
||||
return
|
||||
}
|
||||
|
||||
var defaultFaviconURL: String? = nil
|
||||
|
||||
if let scheme = url.scheme, let host = url.host {
|
||||
defaultFaviconURL = "\(scheme)://\(host)/favicon.ico".lowercased(with: FaviconDownloader.localeForLowercasing)
|
||||
}
|
||||
|
||||
if let defaultFaviconURL = defaultFaviconURL {
|
||||
faviconURLs.append(defaultFaviconURL)
|
||||
}
|
||||
|
||||
completion(faviconURLs)
|
||||
guard let scheme = url.scheme, let host = url.host else {
|
||||
return faviconURLs
|
||||
}
|
||||
|
||||
let defaultFaviconURL = "\(scheme)://\(host)/favicon.ico".lowercased(with: FaviconDownloader.localeForLowercasing)
|
||||
return faviconURLs + [defaultFaviconURL]
|
||||
}
|
||||
|
||||
func faviconDownloader(withURL faviconURL: String, homePageURL: String?) -> SingleFaviconDownloader {
|
||||
|
@ -13,7 +13,7 @@ import UniformTypeIdentifiers
|
||||
|
||||
// The favicon URLs may be specified in the head section of the home page.
|
||||
|
||||
struct FaviconURLFinder {
|
||||
@MainActor struct FaviconURLFinder {
|
||||
|
||||
/// Uniform types to ignore when finding favicon URLs.
|
||||
static let ignoredTypes = [UTType.svg]
|
||||
@ -22,7 +22,7 @@ struct FaviconURLFinder {
|
||||
/// - Parameters:
|
||||
/// - homePageURL: The page to search.
|
||||
/// - urls: An array of favicon URLs as strings.
|
||||
@MainActor static func findFaviconURLs(with homePageURL: String) async -> [String]? {
|
||||
static func findFaviconURLs(with homePageURL: String) async -> [String]? {
|
||||
|
||||
guard let _ = URL(unicodeString: homePageURL) else {
|
||||
return nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user