From b712a8d00decb1b8fa9e6683aaa6908c2893a082 Mon Sep 17 00:00:00 2001 From: Daniel Barber Date: Fri, 22 Nov 2019 14:44:01 -0500 Subject: [PATCH] Use Kingfisher to fetch the notification album art --- .../Shared/UserNotificationsController.swift | 31 +++++++++++++------ Persephone/State/Actions/PlayerActions.swift | 4 --- Persephone/State/Reducers/PlayerReducer.swift | 3 -- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Persephone/Components/Shared/UserNotificationsController.swift b/Persephone/Components/Shared/UserNotificationsController.swift index 9c74f72..005462a 100644 --- a/Persephone/Components/Shared/UserNotificationsController.swift +++ b/Persephone/Components/Shared/UserNotificationsController.swift @@ -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 + } + } } } diff --git a/Persephone/State/Actions/PlayerActions.swift b/Persephone/State/Actions/PlayerActions.swift index 76a12f2..77d4f94 100644 --- a/Persephone/State/Actions/PlayerActions.swift +++ b/Persephone/State/Actions/PlayerActions.swift @@ -9,10 +9,6 @@ import AppKit import ReSwift -struct UpdateCurrentCoverArtAction: Action { - var coverArt: NSImage? -} - struct UpdateCurrentSongAction: Action { var currentSong: Song? } diff --git a/Persephone/State/Reducers/PlayerReducer.swift b/Persephone/State/Reducers/PlayerReducer.swift index f89ebf0..30f64bc 100644 --- a/Persephone/State/Reducers/PlayerReducer.swift +++ b/Persephone/State/Reducers/PlayerReducer.swift @@ -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