diff --git a/Persephone/Components/Window/WindowController.swift b/Persephone/Components/Window/WindowController.swift index 7847e32..c183b01 100644 --- a/Persephone/Components/Window/WindowController.swift +++ b/Persephone/Components/Window/WindowController.swift @@ -162,6 +162,7 @@ class WindowController: NSWindowController { @IBAction func handleSearchQuery(_ sender: NSSearchField) { //App.store.dispatch(SetSearchQuery(searchQuery: sender.stringValue)) + CoverArtService.coverArtQueue App.mpdClient.fetchAlbums(filter: sender.stringValue) } } diff --git a/Persephone/MPDClient/Models/MPDAlbum.swift b/Persephone/MPDClient/Models/MPDAlbum.swift index e73ec8d..80582f1 100644 --- a/Persephone/MPDClient/Models/MPDAlbum.swift +++ b/Persephone/MPDClient/Models/MPDAlbum.swift @@ -14,5 +14,11 @@ extension MPDClient { let artist: String var date: String? var path: String? + + static func == (lhs: MPDAlbum, rhs: MPDAlbum) -> Bool { + return (lhs.title == rhs.title) && + (lhs.artist == rhs.artist) && + (lhs.date == rhs.date) + } } } diff --git a/Persephone/Services/CoverArtService.swift b/Persephone/Services/CoverArtService.swift index d8f2d28..3ec1a30 100644 --- a/Persephone/Services/CoverArtService.swift +++ b/Persephone/Services/CoverArtService.swift @@ -19,7 +19,7 @@ class CoverArtService { let bigArtworkSize = 600 var session = URLSession(configuration: .default) - let coverArtQueue = DispatchQueue(label: "coverArtQueue", qos: .utility) + static let coverArtQueue = DispatchQueue(label: "coverArtQueue", qos: .utility) init(path: String, album: Album) { self.path = path @@ -43,7 +43,7 @@ class CoverArtService { artwork.map(Promise.value) ?? self.getArtworkFromFilesystem() }.then { (artwork: NSImage?) -> Promise in artwork.map(Promise.value) ?? self.getRemoteArtwork() - }.compactMap(on: coverArtQueue) { + }.compactMap(on: CoverArtService.coverArtQueue) { return self.sizeAndCacheImage($0).map(Optional.some) }.recover { _ in return .value(nil) diff --git a/Persephone/Services/Extensions/CoverArtService+Caching.swift b/Persephone/Services/Extensions/CoverArtService+Caching.swift index 9ae8350..78d3bb1 100644 --- a/Persephone/Services/Extensions/CoverArtService+Caching.swift +++ b/Persephone/Services/Extensions/CoverArtService+Caching.swift @@ -14,7 +14,7 @@ extension CoverArtService { func getCachedArtwork() -> Promise { return Promise { seal in - coverArtQueue.async { + CoverArtService.coverArtQueue.async { if self.isArtworkCached() { let cacheFilePath = CoverArtService.cacheDir.appendingPathComponent(self.album.hash).path let data = FileManager.default.contents(atPath: cacheFilePath) @@ -29,7 +29,7 @@ extension CoverArtService { } func cacheArtwork(data: Data?) { - coverArtQueue.async { + CoverArtService.coverArtQueue.async { guard let bundleIdentifier = Bundle.main.bundleIdentifier, let cacheDir = try? FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true) .appendingPathComponent(bundleIdentifier) diff --git a/Persephone/Services/Extensions/CoverArtService+Filesystem.swift b/Persephone/Services/Extensions/CoverArtService+Filesystem.swift index 98a45fd..6c42d5e 100644 --- a/Persephone/Services/Extensions/CoverArtService+Filesystem.swift +++ b/Persephone/Services/Extensions/CoverArtService+Filesystem.swift @@ -24,7 +24,7 @@ extension CoverArtService { func getArtworkFromFilesystem() -> Promise { return Promise { seal in - coverArtQueue.async { + CoverArtService.coverArtQueue.async { guard let artworkPath = self.fileSystemArtworkFilePath() else { seal.fulfill(nil); return } diff --git a/Persephone/Services/Extensions/CoverArtService+Remote.swift b/Persephone/Services/Extensions/CoverArtService+Remote.swift index bf0a05d..1d187d5 100644 --- a/Persephone/Services/Extensions/CoverArtService+Remote.swift +++ b/Persephone/Services/Extensions/CoverArtService+Remote.swift @@ -20,7 +20,7 @@ extension CoverArtService { func getRemoteArtwork() -> Promise { return Promise { seal in if App.store.state.preferencesState .fetchMissingArtworkFromInternet { - coverArtQueue.async { + CoverArtService.coverArtQueue.async { let coverArtWorkItem = DispatchWorkItem { self.getArtworkFromMusicBrainz().map(Optional.some).pipe(to: seal.resolve) }