Make FaviconDownloader.shared.

This commit is contained in:
Brent Simmons 2025-01-30 21:07:46 -08:00
parent 0dfb284f67
commit f91d673b5d
5 changed files with 7 additions and 17 deletions

View File

@ -29,7 +29,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
}
var userNotificationManager: UserNotificationManager!
var faviconDownloader: FaviconDownloader!
var extensionContainersFile: ExtensionContainersFile!
var extensionFeedAddRequestFile: ExtensionFeedAddRequestFile!
@ -143,11 +142,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
cacheFolder = (NSTemporaryDirectory() as NSString).appendingPathComponent(bundleIdentifier)
}
let faviconsFolder = (cacheFolder as NSString).appendingPathComponent("Favicons")
let faviconsFolderURL = URL(fileURLWithPath: faviconsFolder)
try! FileManager.default.createDirectory(at: faviconsFolderURL, withIntermediateDirectories: true, attributes: nil)
faviconDownloader = FaviconDownloader(folder: faviconsFolder)
let imagesFolder = (cacheFolder as NSString).appendingPathComponent("Images")
let imagesFolderURL = URL(fileURLWithPath: imagesFolder)
try! FileManager.default.createDirectory(at: imagesFolderURL, withIntermediateDirectories: true, attributes: nil)
@ -315,7 +309,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
return
}
if key == Feed.FeedSettingKey.homePageURL || key == Feed.FeedSettingKey.faviconURL {
_ = faviconDownloader.favicon(for: feed)
_ = FaviconDownloader.shared.favicon(for: feed)
}
}

View File

@ -28,7 +28,7 @@ extension Account: SmallIconProvider {
extension Feed: SmallIconProvider {
var smallIcon: IconImage? {
if let iconImage = appDelegate.faviconDownloader.favicon(for: self) {
if let iconImage = FaviconDownloader.shared.favicon(for: self) {
return iconImage
}
return FaviconGenerator.favicon(self)

View File

@ -23,6 +23,8 @@ extension Notification.Name {
final class FaviconDownloader {
static let shared = FaviconDownloader()
private static let saveQueue = CoalescingQueue(name: "Cache Save Queue", interval: 1.0)
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "FaviconDownloader")
@ -57,8 +59,9 @@ final class FaviconDownloader {
static let faviconURL = "faviconURL"
}
init(folder: String) {
init() {
let folder = AppConfig.cacheSubfolder(named: "Favicons")
self.folder = folder
self.diskCache = BinaryDiskCache(folder: folder)
self.queue = DispatchQueue(label: "FaviconDownloader serial queue - \(folder)")

View File

@ -91,7 +91,7 @@ private extension IconImageCache {
if let faviconImage = faviconImageCache[feedID] {
return faviconImage
}
if let faviconImage = appDelegate.faviconDownloader.faviconAsIcon(for: feed) {
if let faviconImage = FaviconDownloader.shared.faviconAsIcon(for: feed) {
faviconImageCache[feedID] = faviconImage
return faviconImage
}

View File

@ -39,7 +39,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
var userNotificationManager: UserNotificationManager!
var faviconDownloader: FaviconDownloader!
var extensionContainersFile: ExtensionContainersFile!
var extensionFeedAddRequestFile: ExtensionFeedAddRequestFile!
var widgetDataEncoder: WidgetDataEncoder!
@ -224,14 +223,8 @@ private extension AppDelegate {
private func initializeDownloaders() {
let tempDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
let faviconsFolderURL = tempDir.appendingPathComponent("Favicons")
let imagesFolderURL = tempDir.appendingPathComponent("Images")
try! FileManager.default.createDirectory(at: faviconsFolderURL, withIntermediateDirectories: true, attributes: nil)
let faviconsFolder = faviconsFolderURL.absoluteString
let faviconsFolderPath = faviconsFolder.suffix(from: faviconsFolder.index(faviconsFolder.startIndex, offsetBy: 7))
faviconDownloader = FaviconDownloader(folder: String(faviconsFolderPath))
try! FileManager.default.createDirectory(at: imagesFolderURL, withIntermediateDirectories: true, attributes: nil)
}