Skip to content

Commit f91d673

Browse files
committed
Make FaviconDownloader.shared.
1 parent 0dfb284 commit f91d673

File tree

5 files changed

+7
-17
lines changed

5 files changed

+7
-17
lines changed

Diff for: Mac/AppDelegate.swift

+1-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
2929
}
3030

3131
var userNotificationManager: UserNotificationManager!
32-
var faviconDownloader: FaviconDownloader!
3332
var extensionContainersFile: ExtensionContainersFile!
3433
var extensionFeedAddRequestFile: ExtensionFeedAddRequestFile!
3534

@@ -143,11 +142,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
143142
cacheFolder = (NSTemporaryDirectory() as NSString).appendingPathComponent(bundleIdentifier)
144143
}
145144

146-
let faviconsFolder = (cacheFolder as NSString).appendingPathComponent("Favicons")
147-
let faviconsFolderURL = URL(fileURLWithPath: faviconsFolder)
148-
try! FileManager.default.createDirectory(at: faviconsFolderURL, withIntermediateDirectories: true, attributes: nil)
149-
faviconDownloader = FaviconDownloader(folder: faviconsFolder)
150-
151145
let imagesFolder = (cacheFolder as NSString).appendingPathComponent("Images")
152146
let imagesFolderURL = URL(fileURLWithPath: imagesFolder)
153147
try! FileManager.default.createDirectory(at: imagesFolderURL, withIntermediateDirectories: true, attributes: nil)
@@ -315,7 +309,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
315309
return
316310
}
317311
if key == Feed.FeedSettingKey.homePageURL || key == Feed.FeedSettingKey.faviconURL {
318-
_ = faviconDownloader.favicon(for: feed)
312+
_ = FaviconDownloader.shared.favicon(for: feed)
319313
}
320314
}
321315

Diff for: Shared/Extensions/SmallIconProvider.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension Account: SmallIconProvider {
2828
extension Feed: SmallIconProvider {
2929

3030
var smallIcon: IconImage? {
31-
if let iconImage = appDelegate.faviconDownloader.favicon(for: self) {
31+
if let iconImage = FaviconDownloader.shared.favicon(for: self) {
3232
return iconImage
3333
}
3434
return FaviconGenerator.favicon(self)

Diff for: Shared/Favicons/FaviconDownloader.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ extension Notification.Name {
2323

2424
final class FaviconDownloader {
2525

26+
static let shared = FaviconDownloader()
27+
2628
private static let saveQueue = CoalescingQueue(name: "Cache Save Queue", interval: 1.0)
2729

2830
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "FaviconDownloader")
@@ -57,8 +59,9 @@ final class FaviconDownloader {
5759
static let faviconURL = "faviconURL"
5860
}
5961

60-
init(folder: String) {
62+
init() {
6163

64+
let folder = AppConfig.cacheSubfolder(named: "Favicons")
6265
self.folder = folder
6366
self.diskCache = BinaryDiskCache(folder: folder)
6467
self.queue = DispatchQueue(label: "FaviconDownloader serial queue - \(folder)")

Diff for: Shared/IconImageCache.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private extension IconImageCache {
9191
if let faviconImage = faviconImageCache[feedID] {
9292
return faviconImage
9393
}
94-
if let faviconImage = appDelegate.faviconDownloader.faviconAsIcon(for: feed) {
94+
if let faviconImage = FaviconDownloader.shared.faviconAsIcon(for: feed) {
9595
faviconImageCache[feedID] = faviconImage
9696
return faviconImage
9797
}

Diff for: iOS/AppDelegate.swift

-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
3939
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
4040

4141
var userNotificationManager: UserNotificationManager!
42-
var faviconDownloader: FaviconDownloader!
4342
var extensionContainersFile: ExtensionContainersFile!
4443
var extensionFeedAddRequestFile: ExtensionFeedAddRequestFile!
4544
var widgetDataEncoder: WidgetDataEncoder!
@@ -224,14 +223,8 @@ private extension AppDelegate {
224223

225224
private func initializeDownloaders() {
226225
let tempDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
227-
let faviconsFolderURL = tempDir.appendingPathComponent("Favicons")
228226
let imagesFolderURL = tempDir.appendingPathComponent("Images")
229227

230-
try! FileManager.default.createDirectory(at: faviconsFolderURL, withIntermediateDirectories: true, attributes: nil)
231-
let faviconsFolder = faviconsFolderURL.absoluteString
232-
let faviconsFolderPath = faviconsFolder.suffix(from: faviconsFolder.index(faviconsFolder.startIndex, offsetBy: 7))
233-
faviconDownloader = FaviconDownloader(folder: String(faviconsFolderPath))
234-
235228
try! FileManager.default.createDirectory(at: imagesFolderURL, withIntermediateDirectories: true, attributes: nil)
236229
}
237230

0 commit comments

Comments
 (0)