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

Set button state on server state change

This commit is contained in:
Daniel Barber 2019-05-17 22:56:41 -04:00
parent ad04250760
commit 9351061a8d
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
5 changed files with 17 additions and 15 deletions

View File

@ -68,6 +68,11 @@ class WindowController: NSWindowController {
}
}
func setShuffleRepeatState(_ state: PlayerState) {
shuffleState.state = state.shuffleState ? .on : .off
repeatState.state = state.repeatState ? .on : .off
}
func setTrackProgressControls(_ playerState: PlayerState) {
guard let state = playerState.state,
let totalTime = playerState.totalTime,
@ -177,6 +182,7 @@ extension WindowController: StoreSubscriber {
func newState(state: (playerState: PlayerState, uiState: UIState)) {
DispatchQueue.main.async {
self.setTransportControlState(state.playerState)
self.setShuffleRepeatState(state.playerState)
self.setTrackProgressControls(state.playerState)
self.setDatabaseUpdatingIndicator(state.uiState)
}

View File

@ -39,7 +39,7 @@ extension MPDClient {
self.fetchQueue()
self.delegate?.didUpdateQueue(mpdClient: self, queue: self.queue)
}
if mpdIdle.contains(.player) {
if mpdIdle.contains(.player) || mpdIdle.contains(.options) {
self.fetchStatus()
if let status = self.status {

View File

@ -50,6 +50,14 @@ extension MPDClient {
return Int(mpd_status_get_song_pos(status))
}
var shuffleState: Bool {
return mpd_status_get_random(status)
}
var repeatState: Bool {
return mpd_status_get_repeat(status)
}
var updating: Bool {
let updating = mpd_status_get_update_id(status)

View File

@ -24,11 +24,3 @@ struct UpdateElapsedTimeAction: Action {
struct UpdateStatusAction: Action {
var status: MPDClient.MPDStatus
}
struct UpdateShuffleAction: Action {
var shuffleState: Bool
}
struct UpdateRepeatAction: Action {
var repeatState: Bool
}

View File

@ -18,6 +18,8 @@ func playerReducer(action: Action, state: PlayerState?) -> PlayerState {
state.state = action.status.state
state.totalTime = action.status.totalTime
state.elapsedTimeMs = action.status.elapsedTimeMs
state.shuffleState = action.status.shuffleState
state.repeatState = action.status.repeatState
if state.state == .playing {
App.trackTimer.start(elapsedTimeMs: state.elapsedTimeMs)
@ -60,12 +62,6 @@ func playerReducer(action: Action, state: PlayerState?) -> PlayerState {
case let action as UpdateElapsedTimeAction:
state.elapsedTimeMs = action.elapsedTimeMs
case let action as UpdateShuffleAction:
state.shuffleState = action.shuffleState
case let action as UpdateRepeatAction:
state.repeatState = action.repeatState
default:
break
}