diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index f03bf44ef..2fc958191 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -39,7 +39,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat } var userNotificationManager: UserNotificationManager! - var faviconDownloader: FaviconDownloader! var extensionContainersFile: ExtensionContainersFile! var extensionFeedAddRequestFile: ExtensionFeedAddRequestFile! @@ -157,11 +156,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) @@ -342,7 +336,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat return } if key == WebFeed.WebFeedSettingKey.homePageURL || key == WebFeed.WebFeedSettingKey.faviconURL { - let _ = faviconDownloader.favicon(for: feed) + _ = FaviconDownloader.shared.favicon(for: feed) } } diff --git a/Shared/Extensions/SmallIconProvider.swift b/Shared/Extensions/SmallIconProvider.swift index 292d84f36..eebf98f19 100644 --- a/Shared/Extensions/SmallIconProvider.swift +++ b/Shared/Extensions/SmallIconProvider.swift @@ -28,7 +28,7 @@ extension Account: SmallIconProvider { extension WebFeed: 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) diff --git a/Shared/Favicons/FaviconDownloader.swift b/Shared/Favicons/FaviconDownloader.swift index 7d290b067..0d9e7ee1a 100644 --- a/Shared/Favicons/FaviconDownloader.swift +++ b/Shared/Favicons/FaviconDownloader.swift @@ -21,6 +21,7 @@ extension Notification.Name { } final class FaviconDownloader { + static let shared = FaviconDownloader() private static let saveQueue = CoalescingQueue(name: "Cache Save Queue", interval: 1.0) @@ -53,8 +54,9 @@ final class FaviconDownloader { static let faviconURL = "faviconURL" } - init(folder: String) { - + init() { + let folderURL = AppConfig.cacheSubfolder(named: "Favicons") + let folder = folderURL.path self.folder = folder self.diskCache = BinaryDiskCache(folder: folder) self.queue = DispatchQueue(label: "FaviconDownloader serial queue - \(folder)") diff --git a/Shared/IconImageCache.swift b/Shared/IconImageCache.swift index 50468f78d..b3cfbd9de 100644 --- a/Shared/IconImageCache.swift +++ b/Shared/IconImageCache.swift @@ -91,7 +91,7 @@ private extension IconImageCache { if let faviconImage = faviconImageCache[feedID] { return faviconImage } - if let faviconImage = appDelegate.faviconDownloader.faviconAsIcon(for: webFeed) { + if let faviconImage = FaviconDownloader.shared.faviconAsIcon(for: webFeed) { faviconImageCache[feedID] = faviconImage return faviconImage } diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 5dc34c858..ffc86eafe 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -40,7 +40,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Application") var userNotificationManager: UserNotificationManager! - var faviconDownloader: FaviconDownloader! var extensionContainersFile: ExtensionContainersFile! var extensionFeedAddRequestFile: ExtensionFeedAddRequestFile! var widgetDataEncoder: WidgetDataEncoder! @@ -237,14 +236,7 @@ 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) }