1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Use Kingfisher to fetch the notification album art

This commit is contained in:
Daniel Barber 2019-11-22 14:44:01 -05:00
parent 4322a25b8b
commit b712a8d00d
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
3 changed files with 22 additions and 16 deletions

View File

@ -8,8 +8,11 @@
import Foundation
import ReSwift
import Kingfisher
class UserNotificationsController {
let cache = ImageCache.default
init() {
App.store.subscribe(self) {
$0.select { $0.playerState.currentSong }
@ -18,18 +21,28 @@ class UserNotificationsController {
func notifyTrack(_ state: Song?) {
guard let currentSong = state,
let coverArtFilePath = currentSong.album.coverArtFilePath,
let status = App.mpdClient.status,
status.state == .playing
else { return }
//
// let coverArtService = CoverArtService(path: currentSong.mpdSong.path, album: currentSong.album)
//
// coverArtService.fetchBigCoverArt()
// .done() {
// SongNotifierService(song: currentSong, image: $0)
// .deliver()
// }
// .cauterize()
let imageURL = URL(fileURLWithPath: coverArtFilePath)
let provider = LocalFileImageDataProvider(fileURL: imageURL)
_ = KingfisherManager.shared.retrieveImage(
with: .provider(provider),
options: [
.processor(DownsamplingImageProcessor(size: NSSize(width: 180, height: 180))),
.scaleFactor(2),
]
) { result in
switch result {
case .success(let value):
SongNotifierService(song: currentSong, image: value.image)
.deliver()
case .failure:
break
}
}
}
}

View File

@ -9,10 +9,6 @@
import AppKit
import ReSwift
struct UpdateCurrentCoverArtAction: Action {
var coverArt: NSImage?
}
struct UpdateCurrentSongAction: Action {
var currentSong: Song?
}

View File

@ -39,9 +39,6 @@ func playerReducer(action: Action, state: PlayerState?) -> PlayerState {
case let action as UpdateCurrentSongAction:
state.currentSong = action.currentSong
case let action as UpdateCurrentCoverArtAction:
break
case let action as UpdateElapsedTimeAction:
state.elapsedTimeMs = action.elapsedTimeMs