mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
WIP
This commit is contained in:
parent
42d274058f
commit
01428d8126
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<NSImage?> 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)
|
||||
|
||||
@ -14,7 +14,7 @@ extension CoverArtService {
|
||||
|
||||
func getCachedArtwork() -> Promise<NSImage?> {
|
||||
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)
|
||||
|
||||
@ -24,7 +24,7 @@ extension CoverArtService {
|
||||
|
||||
func getArtworkFromFilesystem() -> Promise<NSImage?> {
|
||||
return Promise { seal in
|
||||
coverArtQueue.async {
|
||||
CoverArtService.coverArtQueue.async {
|
||||
guard let artworkPath = self.fileSystemArtworkFilePath()
|
||||
else { seal.fulfill(nil); return }
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ extension CoverArtService {
|
||||
func getRemoteArtwork() -> Promise<NSImage?> {
|
||||
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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user