From cd2e5efc950eb21d7b0bc104127e37531d0c6407 Mon Sep 17 00:00:00 2001 From: Daniel Barber Date: Sun, 16 Feb 2020 12:51:11 -0500 Subject: [PATCH] Cache the small image when we get the browser art We use the RawImageDataProvider here to pass the already downloaded image onto this transform, to avoid fetching it from MPD again. The 180x180 size artwork is plenty big enough to use as source for the 32x32 queue/dragged song artwork. --- .../Browser/Album Browser/AlbumViewItem.swift | 29 ++++++++++++++++++- .../Album Detail/AlbumDetailView.swift | 13 --------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Persephone/Components/Browser/Album Browser/AlbumViewItem.swift b/Persephone/Components/Browser/Album Browser/AlbumViewItem.swift index ded5dd9..6528c0e 100644 --- a/Persephone/Components/Browser/Album Browser/AlbumViewItem.swift +++ b/Persephone/Components/Browser/Album Browser/AlbumViewItem.swift @@ -71,7 +71,34 @@ class AlbumViewItem: NSCollectionViewItem { .processor(DownsamplingImageProcessor(size: .albumListCoverSize)), .scaleFactor(2), ] - ) + ) { result in + switch result { + case .success(let imageResult): + guard let imageData = imageResult.image.tiffRepresentation + else { return } + + let rawProvider = RawImageDataProvider( + data: imageData, + cacheKey: album.hash + ) + + self.cacheSmallCover(provider: rawProvider) + + case .failure(_): + break + } + } + } + + func cacheSmallCover(provider: ImageDataProvider) { + _ = KingfisherManager.shared.retrieveImage( + with: .provider(provider), + options: [ + .memoryCacheExpiration(.never), + .processor(DownsamplingImageProcessor(size: .queueSongCoverSize)), + .scaleFactor(2), + ] + ) { result in } } func setAppearance(selected isSelected: Bool) { diff --git a/Persephone/Components/Browser/Album Detail/AlbumDetailView.swift b/Persephone/Components/Browser/Album Detail/AlbumDetailView.swift index 0f0224c..1f18808 100644 --- a/Persephone/Components/Browser/Album Detail/AlbumDetailView.swift +++ b/Persephone/Components/Browser/Album Detail/AlbumDetailView.swift @@ -145,19 +145,6 @@ class AlbumDetailView: NSViewController { .scaleFactor(2), ] ) - - cacheSmallCover(provider: provider) - } - - func cacheSmallCover(provider: MPDAlbumArtImageDataProvider) { - _ = KingfisherManager.shared.retrieveImage( - with: .provider(provider), - options: [ - .memoryCacheExpiration(.never), - .processor(DownsamplingImageProcessor(size: .queueSongCoverSize)), - .scaleFactor(2), - ] - ) { result in } } func setAppearance() {