From 703ecfa7465cb1da70756c5a08ffd5499ad62da3 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 19 Jan 2025 17:59:41 -0800 Subject: [PATCH] Fetch favicon (if needed) when HTMLMetadata is available. --- Shared/Favicons/FaviconDownloader.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Shared/Favicons/FaviconDownloader.swift b/Shared/Favicons/FaviconDownloader.swift index 97649bdd4..e5ab2133a 100644 --- a/Shared/Favicons/FaviconDownloader.swift +++ b/Shared/Favicons/FaviconDownloader.swift @@ -65,6 +65,7 @@ final class FaviconDownloader { loadHomePageURLsWithNoFaviconURLCache() NotificationCenter.default.addObserver(self, selector: #selector(didLoadFavicon(_:)), name: .DidLoadFavicon, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(htmlMetadataIsAvailable(_:)), name: .htmlMetadataAvailable, object: nil) } // MARK: - API @@ -179,7 +180,20 @@ final class FaviconDownloader { postFaviconDidBecomeAvailableNotification(singleFaviconDownloader.faviconURL) } - + + @objc func htmlMetadataIsAvailable(_ note: Notification) { + + guard let url = note.userInfo?[HTMLMetadataCache.UserInfoKey.url] as? String else { + assertionFailure("Expected URL string in .htmlMetadataAvailable Notification userInfo.") + return + } + + Task { @MainActor in + // This will fetch the favicon (if possible) and post a .FaviconDidBecomeAvailable Notification. + _ = favicon(withHomePageURL: url) + } + } + @objc func saveHomePageToFaviconURLCacheIfNeeded() { if homePageToFaviconURLCacheDirty { saveHomePageToFaviconURLCache()