mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 01:40:22 +00:00
Make FaviconDownloader a singleton.
This commit is contained in:
1 parent
c600c807c8
commit
9eb0907b2f
5 files changed
+7
-19
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user