mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
Give the queue its own local state
This commit is contained in:
parent
22bb7efef2
commit
0de001ce16
@ -28,15 +28,6 @@ class AlbumViewController: NSViewController,
|
|||||||
albumScrollView.postsBoundsChangedNotifications = true
|
albumScrollView.postsBoundsChangedNotifications = true
|
||||||
|
|
||||||
albumCollectionView.dataSource = dataSource
|
albumCollectionView.dataSource = dataSource
|
||||||
|
|
||||||
// preferences.addObserver(self, forKeyPath: "mpdLibraryDir")
|
|
||||||
// preferences.addObserver(self, forKeyPath: "fetchMissingArtworkFromInternet")
|
|
||||||
}
|
|
||||||
|
|
||||||
override func viewWillDisappear() {
|
|
||||||
super.viewWillDisappear()
|
|
||||||
|
|
||||||
AppDelegate.store.unsubscribe(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillLayout() {
|
override func viewWillLayout() {
|
||||||
@ -68,7 +59,7 @@ class AlbumViewController: NSViewController,
|
|||||||
case "mpdLibraryDir":
|
case "mpdLibraryDir":
|
||||||
albumCollectionView.reloadData()
|
albumCollectionView.reloadData()
|
||||||
case "fetchMissingArtworkFromInternet":
|
case "fetchMissingArtworkFromInternet":
|
||||||
AppDelegate.store.dispatch(ResetAlbumListCoverArt())
|
AppDelegate.store.dispatch(ResetAlbumListCoverArtAction())
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -82,16 +73,11 @@ extension AlbumViewController: StoreSubscriber {
|
|||||||
typealias StoreSubscriberStateType = AlbumListState
|
typealias StoreSubscriberStateType = AlbumListState
|
||||||
|
|
||||||
func newState(state: StoreSubscriberStateType) {
|
func newState(state: StoreSubscriberStateType) {
|
||||||
if dataSource.albums == [] {
|
let oldAlbums = dataSource.albums
|
||||||
dataSource.albums = state.albums
|
dataSource.albums = state.albums
|
||||||
albumCollectionView.reloadData()
|
albumCollectionView.animateItemChanges(
|
||||||
} else {
|
oldData: oldAlbums,
|
||||||
let oldAlbums = dataSource.albums
|
newData: dataSource.albums
|
||||||
dataSource.albums = state.albums
|
)
|
||||||
albumCollectionView.animateItemChanges(
|
|
||||||
oldData: oldAlbums,
|
|
||||||
newData: dataSource.albums
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,13 +30,13 @@ class NotificationsController: MPDClientDelegate {
|
|||||||
|
|
||||||
func willStartDatabaseUpdate(mpdClient: MPDClient) {
|
func willStartDatabaseUpdate(mpdClient: MPDClient) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
AppDelegate.store.dispatch(StartedDatabaseUpdate())
|
AppDelegate.store.dispatch(StartedDatabaseUpdateAction())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func didFinishDatabaseUpdate(mpdClient: MPDClient) {
|
func didFinishDatabaseUpdate(mpdClient: MPDClient) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
AppDelegate.store.dispatch(FinishedDatabaseUpdate())
|
AppDelegate.store.dispatch(FinishedDatabaseUpdateAction())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,12 +27,6 @@ class QueueViewController: NSViewController,
|
|||||||
queueView.columnAutoresizingStyle = .sequentialColumnAutoresizingStyle
|
queueView.columnAutoresizingStyle = .sequentialColumnAutoresizingStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillDisappear() {
|
|
||||||
super.viewWillDisappear()
|
|
||||||
|
|
||||||
AppDelegate.store.unsubscribe(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
override func keyDown(with event: NSEvent) {
|
override func keyDown(with event: NSEvent) {
|
||||||
switch event.keyCode {
|
switch event.keyCode {
|
||||||
case NSEvent.keyCodeSpace:
|
case NSEvent.keyCodeSpace:
|
||||||
@ -128,7 +122,8 @@ extension QueueViewController: StoreSubscriber {
|
|||||||
typealias StoreSubscriberStateType = QueueState
|
typealias StoreSubscriberStateType = QueueState
|
||||||
|
|
||||||
func newState(state: StoreSubscriberStateType) {
|
func newState(state: StoreSubscriberStateType) {
|
||||||
dataSource.setQueueIcon()
|
dataSource.queue = state.queue
|
||||||
|
dataSource.setQueueIcon(state)
|
||||||
queueView.reloadData()
|
queueView.reloadData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@ class AlbumDataSource: NSObject, NSCollectionViewDataSource {
|
|||||||
.done { image in
|
.done { image in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
AppDelegate.store.dispatch(
|
AppDelegate.store.dispatch(
|
||||||
UpdateCoverArt(coverArt: image, albumIndex: indexPath.item)
|
UpdateCoverArtAction(coverArt: image, albumIndex: indexPath.item)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,10 +9,11 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class QueueDataSource: NSObject, NSOutlineViewDataSource {
|
class QueueDataSource: NSObject, NSOutlineViewDataSource {
|
||||||
|
var queue: [QueueItem] = []
|
||||||
var queueIcon: NSImage? = nil
|
var queueIcon: NSImage? = nil
|
||||||
|
|
||||||
func setQueueIcon() {
|
func setQueueIcon(_ state: QueueState) {
|
||||||
switch AppDelegate.store.state.playerState.state {
|
switch state.state {
|
||||||
case .playing?:
|
case .playing?:
|
||||||
queueIcon = .playIcon
|
queueIcon = .playIcon
|
||||||
case .paused?:
|
case .paused?:
|
||||||
@ -23,7 +24,7 @@ class QueueDataSource: NSObject, NSOutlineViewDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
|
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
|
||||||
return AppDelegate.store.state.queueState.queue.count + 1
|
return queue.count + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
|
func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
|
||||||
@ -32,7 +33,7 @@ class QueueDataSource: NSObject, NSOutlineViewDataSource {
|
|||||||
|
|
||||||
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
|
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
|
||||||
if index > 0 {
|
if index > 0 {
|
||||||
return AppDelegate.store.state.queueState.queue[index - 1]
|
return queue[index - 1]
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,9 +9,9 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
import ReSwift
|
import ReSwift
|
||||||
|
|
||||||
struct ResetAlbumListCoverArt: Action {}
|
struct ResetAlbumListCoverArtAction: Action {}
|
||||||
|
|
||||||
struct UpdateCoverArt: Action {
|
struct UpdateCoverArtAction: Action {
|
||||||
var coverArt: NSImage?
|
var coverArt: NSImage?
|
||||||
var albumIndex: Int
|
var albumIndex: Int
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,11 +9,11 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
import ReSwift
|
import ReSwift
|
||||||
|
|
||||||
struct UpdateCurrentCoverArt: Action {
|
struct UpdateCurrentCoverArtAction: Action {
|
||||||
var coverArt: NSImage?
|
var coverArt: NSImage?
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UpdateCurrentSong: Action {
|
struct UpdateCurrentSongAction: Action {
|
||||||
var currentSong: Song
|
var currentSong: Song
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,6 +25,6 @@ struct UpdateStatusAction: Action {
|
|||||||
var status: MPDClient.MPDStatus
|
var status: MPDClient.MPDStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StartedDatabaseUpdate: Action {}
|
struct StartedDatabaseUpdateAction: Action {}
|
||||||
|
|
||||||
struct FinishedDatabaseUpdate: Action {}
|
struct FinishedDatabaseUpdateAction: Action {}
|
||||||
|
|||||||
@ -15,3 +15,7 @@ struct UpdateQueueAction: Action {
|
|||||||
struct UpdateQueuePosAction: Action {
|
struct UpdateQueuePosAction: Action {
|
||||||
var queuePos: Int
|
var queuePos: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct UpdateQueuePlayerStateAction: Action {
|
||||||
|
var state: MPDClient.MPDStatus.State?
|
||||||
|
}
|
||||||
|
|||||||
@ -11,11 +11,14 @@ import ReSwift
|
|||||||
struct QueueState: StateType {
|
struct QueueState: StateType {
|
||||||
var queue: [QueueItem] = []
|
var queue: [QueueItem] = []
|
||||||
var queuePos: Int = -1
|
var queuePos: Int = -1
|
||||||
|
|
||||||
|
var state: MPDClient.MPDStatus.State?
|
||||||
}
|
}
|
||||||
|
|
||||||
extension QueueState: Equatable {
|
extension QueueState: Equatable {
|
||||||
static func == (lhs: QueueState, rhs: QueueState) -> Bool {
|
static func == (lhs: QueueState, rhs: QueueState) -> Bool {
|
||||||
return (lhs.queue == rhs.queue) &&
|
return (lhs.queue == rhs.queue) &&
|
||||||
(lhs.queuePos == rhs.queuePos)
|
(lhs.queuePos == rhs.queuePos) &&
|
||||||
|
(lhs.state == rhs.state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,10 +15,10 @@ func albumListReducer(action: Action, state: AlbumListState?) -> AlbumListState
|
|||||||
case let action as UpdateAlbumListAction:
|
case let action as UpdateAlbumListAction:
|
||||||
state.albums = action.albums.map { Album(mpdAlbum: $0) }
|
state.albums = action.albums.map { Album(mpdAlbum: $0) }
|
||||||
|
|
||||||
case let action as UpdateCoverArt:
|
case let action as UpdateCoverArtAction:
|
||||||
state.albums[action.albumIndex].coverArt = .loaded(action.coverArt)
|
state.albums[action.albumIndex].coverArt = .loaded(action.coverArt)
|
||||||
|
|
||||||
case is ResetAlbumListCoverArt:
|
case is ResetAlbumListCoverArtAction:
|
||||||
state.albums = AppDelegate.store.state.albumListState.albums.map {
|
state.albums = AppDelegate.store.state.albumListState.albums.map {
|
||||||
var album = $0
|
var album = $0
|
||||||
switch album.coverArt {
|
switch album.coverArt {
|
||||||
|
|||||||
@ -25,7 +25,13 @@ func playerReducer(action: Action, state: PlayerState?) -> PlayerState {
|
|||||||
AppDelegate.trackTimer.stop(elapsedTimeMs: state.elapsedTimeMs)
|
AppDelegate.trackTimer.stop(elapsedTimeMs: state.elapsedTimeMs)
|
||||||
}
|
}
|
||||||
|
|
||||||
case let action as UpdateCurrentSong:
|
DispatchQueue.main.async {
|
||||||
|
AppDelegate.store.dispatch(
|
||||||
|
UpdateQueuePlayerStateAction(state: state.state)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
case let action as UpdateCurrentSongAction:
|
||||||
state.currentSong = action.currentSong
|
state.currentSong = action.currentSong
|
||||||
|
|
||||||
if let currentSong = state.currentSong {
|
if let currentSong = state.currentSong {
|
||||||
@ -35,29 +41,29 @@ func playerReducer(action: Action, state: PlayerState?) -> PlayerState {
|
|||||||
.done() { image in
|
.done() { image in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if let image = image {
|
if let image = image {
|
||||||
AppDelegate.store.dispatch(UpdateCurrentCoverArt(coverArt: image))
|
AppDelegate.store.dispatch(UpdateCurrentCoverArtAction(coverArt: image))
|
||||||
} else {
|
} else {
|
||||||
AppDelegate.store.dispatch(UpdateCurrentCoverArt(coverArt: .defaultCoverArt))
|
AppDelegate.store.dispatch(UpdateCurrentCoverArtAction(coverArt: .defaultCoverArt))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.cauterize()
|
.cauterize()
|
||||||
} else {
|
} else {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
AppDelegate.store.dispatch(UpdateCurrentCoverArt(coverArt: .defaultCoverArt))
|
AppDelegate.store.dispatch(UpdateCurrentCoverArtAction(coverArt: .defaultCoverArt))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case let action as UpdateCurrentCoverArt:
|
case let action as UpdateCurrentCoverArtAction:
|
||||||
state.currentArtwork = action.coverArt
|
state.currentArtwork = action.coverArt
|
||||||
|
|
||||||
case let action as UpdateElapsedTimeAction:
|
case let action as UpdateElapsedTimeAction:
|
||||||
state.elapsedTimeMs = action.elapsedTimeMs
|
state.elapsedTimeMs = action.elapsedTimeMs
|
||||||
|
|
||||||
case is StartedDatabaseUpdate:
|
case is StartedDatabaseUpdateAction:
|
||||||
state.databaseUpdating = true
|
state.databaseUpdating = true
|
||||||
|
|
||||||
case is FinishedDatabaseUpdate:
|
case is FinishedDatabaseUpdateAction:
|
||||||
state.databaseUpdating = false
|
state.databaseUpdating = false
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -40,9 +40,12 @@ func queueReducer(action: Action, state: QueueState?) -> QueueState {
|
|||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
AppDelegate.store.dispatch(
|
AppDelegate.store.dispatch(
|
||||||
UpdateCurrentSong(currentSong: state.queue[newSongRowPos].song)
|
UpdateCurrentSongAction(currentSong: state.queue[newSongRowPos].song)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case let action as UpdateQueuePlayerStateAction:
|
||||||
|
state.state = action.state
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user