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:
parent
ad04250760
commit
9351061a8d
@ -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) {
|
func setTrackProgressControls(_ playerState: PlayerState) {
|
||||||
guard let state = playerState.state,
|
guard let state = playerState.state,
|
||||||
let totalTime = playerState.totalTime,
|
let totalTime = playerState.totalTime,
|
||||||
@ -177,6 +182,7 @@ extension WindowController: StoreSubscriber {
|
|||||||
func newState(state: (playerState: PlayerState, uiState: UIState)) {
|
func newState(state: (playerState: PlayerState, uiState: UIState)) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.setTransportControlState(state.playerState)
|
self.setTransportControlState(state.playerState)
|
||||||
|
self.setShuffleRepeatState(state.playerState)
|
||||||
self.setTrackProgressControls(state.playerState)
|
self.setTrackProgressControls(state.playerState)
|
||||||
self.setDatabaseUpdatingIndicator(state.uiState)
|
self.setDatabaseUpdatingIndicator(state.uiState)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ extension MPDClient {
|
|||||||
self.fetchQueue()
|
self.fetchQueue()
|
||||||
self.delegate?.didUpdateQueue(mpdClient: self, queue: self.queue)
|
self.delegate?.didUpdateQueue(mpdClient: self, queue: self.queue)
|
||||||
}
|
}
|
||||||
if mpdIdle.contains(.player) {
|
if mpdIdle.contains(.player) || mpdIdle.contains(.options) {
|
||||||
self.fetchStatus()
|
self.fetchStatus()
|
||||||
|
|
||||||
if let status = self.status {
|
if let status = self.status {
|
||||||
|
|||||||
@ -50,6 +50,14 @@ extension MPDClient {
|
|||||||
return Int(mpd_status_get_song_pos(status))
|
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 {
|
var updating: Bool {
|
||||||
let updating = mpd_status_get_update_id(status)
|
let updating = mpd_status_get_update_id(status)
|
||||||
|
|
||||||
|
|||||||
@ -24,11 +24,3 @@ struct UpdateElapsedTimeAction: Action {
|
|||||||
struct UpdateStatusAction: Action {
|
struct UpdateStatusAction: Action {
|
||||||
var status: MPDClient.MPDStatus
|
var status: MPDClient.MPDStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UpdateShuffleAction: Action {
|
|
||||||
var shuffleState: Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
struct UpdateRepeatAction: Action {
|
|
||||||
var repeatState: Bool
|
|
||||||
}
|
|
||||||
|
|||||||
@ -18,6 +18,8 @@ func playerReducer(action: Action, state: PlayerState?) -> PlayerState {
|
|||||||
state.state = action.status.state
|
state.state = action.status.state
|
||||||
state.totalTime = action.status.totalTime
|
state.totalTime = action.status.totalTime
|
||||||
state.elapsedTimeMs = action.status.elapsedTimeMs
|
state.elapsedTimeMs = action.status.elapsedTimeMs
|
||||||
|
state.shuffleState = action.status.shuffleState
|
||||||
|
state.repeatState = action.status.repeatState
|
||||||
|
|
||||||
if state.state == .playing {
|
if state.state == .playing {
|
||||||
App.trackTimer.start(elapsedTimeMs: state.elapsedTimeMs)
|
App.trackTimer.start(elapsedTimeMs: state.elapsedTimeMs)
|
||||||
@ -60,12 +62,6 @@ func playerReducer(action: Action, state: PlayerState?) -> PlayerState {
|
|||||||
case let action as UpdateElapsedTimeAction:
|
case let action as UpdateElapsedTimeAction:
|
||||||
state.elapsedTimeMs = action.elapsedTimeMs
|
state.elapsedTimeMs = action.elapsedTimeMs
|
||||||
|
|
||||||
case let action as UpdateShuffleAction:
|
|
||||||
state.shuffleState = action.shuffleState
|
|
||||||
|
|
||||||
case let action as UpdateRepeatAction:
|
|
||||||
state.repeatState = action.repeatState
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user