1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00
This commit is contained in:
Daniel Barber 2019-11-22 11:07:02 -05:00
parent 42d274058f
commit 01428d8126
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
6 changed files with 13 additions and 6 deletions

View File

@ -162,6 +162,7 @@ class WindowController: NSWindowController {
@IBAction func handleSearchQuery(_ sender: NSSearchField) { @IBAction func handleSearchQuery(_ sender: NSSearchField) {
//App.store.dispatch(SetSearchQuery(searchQuery: sender.stringValue)) //App.store.dispatch(SetSearchQuery(searchQuery: sender.stringValue))
CoverArtService.coverArtQueue
App.mpdClient.fetchAlbums(filter: sender.stringValue) App.mpdClient.fetchAlbums(filter: sender.stringValue)
} }
} }

View File

@ -14,5 +14,11 @@ extension MPDClient {
let artist: String let artist: String
var date: String? var date: String?
var path: String? var path: String?
static func == (lhs: MPDAlbum, rhs: MPDAlbum) -> Bool {
return (lhs.title == rhs.title) &&
(lhs.artist == rhs.artist) &&
(lhs.date == rhs.date)
}
} }
} }

View File

@ -19,7 +19,7 @@ class CoverArtService {
let bigArtworkSize = 600 let bigArtworkSize = 600
var session = URLSession(configuration: .default) 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) { init(path: String, album: Album) {
self.path = path self.path = path
@ -43,7 +43,7 @@ class CoverArtService {
artwork.map(Promise.value) ?? self.getArtworkFromFilesystem() artwork.map(Promise.value) ?? self.getArtworkFromFilesystem()
}.then { (artwork: NSImage?) -> Promise<NSImage?> in }.then { (artwork: NSImage?) -> Promise<NSImage?> in
artwork.map(Promise.value) ?? self.getRemoteArtwork() artwork.map(Promise.value) ?? self.getRemoteArtwork()
}.compactMap(on: coverArtQueue) { }.compactMap(on: CoverArtService.coverArtQueue) {
return self.sizeAndCacheImage($0).map(Optional.some) return self.sizeAndCacheImage($0).map(Optional.some)
}.recover { _ in }.recover { _ in
return .value(nil) return .value(nil)

View File

@ -14,7 +14,7 @@ extension CoverArtService {
func getCachedArtwork() -> Promise<NSImage?> { func getCachedArtwork() -> Promise<NSImage?> {
return Promise { seal in return Promise { seal in
coverArtQueue.async { CoverArtService.coverArtQueue.async {
if self.isArtworkCached() { if self.isArtworkCached() {
let cacheFilePath = CoverArtService.cacheDir.appendingPathComponent(self.album.hash).path let cacheFilePath = CoverArtService.cacheDir.appendingPathComponent(self.album.hash).path
let data = FileManager.default.contents(atPath: cacheFilePath) let data = FileManager.default.contents(atPath: cacheFilePath)
@ -29,7 +29,7 @@ extension CoverArtService {
} }
func cacheArtwork(data: Data?) { func cacheArtwork(data: Data?) {
coverArtQueue.async { CoverArtService.coverArtQueue.async {
guard let bundleIdentifier = Bundle.main.bundleIdentifier, guard let bundleIdentifier = Bundle.main.bundleIdentifier,
let cacheDir = try? FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true) let cacheDir = try? FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
.appendingPathComponent(bundleIdentifier) .appendingPathComponent(bundleIdentifier)

View File

@ -24,7 +24,7 @@ extension CoverArtService {
func getArtworkFromFilesystem() -> Promise<NSImage?> { func getArtworkFromFilesystem() -> Promise<NSImage?> {
return Promise { seal in return Promise { seal in
coverArtQueue.async { CoverArtService.coverArtQueue.async {
guard let artworkPath = self.fileSystemArtworkFilePath() guard let artworkPath = self.fileSystemArtworkFilePath()
else { seal.fulfill(nil); return } else { seal.fulfill(nil); return }

View File

@ -20,7 +20,7 @@ extension CoverArtService {
func getRemoteArtwork() -> Promise<NSImage?> { func getRemoteArtwork() -> Promise<NSImage?> {
return Promise { seal in return Promise { seal in
if App.store.state.preferencesState .fetchMissingArtworkFromInternet { if App.store.state.preferencesState .fetchMissingArtworkFromInternet {
coverArtQueue.async { CoverArtService.coverArtQueue.async {
let coverArtWorkItem = DispatchWorkItem { let coverArtWorkItem = DispatchWorkItem {
self.getArtworkFromMusicBrainz().map(Optional.some).pipe(to: seal.resolve) self.getArtworkFromMusicBrainz().map(Optional.some).pipe(to: seal.resolve)
} }