Skip to content

Commit

Permalink
emit shuffle and repeat events again
Browse files Browse the repository at this point in the history
  • Loading branch information
photovoltex committed Feb 22, 2025
1 parent 09b4aa4 commit dd2330b
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,9 @@ impl SpircTask {
SpircCommand::Next => self.handle_next(None)?,
SpircCommand::VolumeUp => self.handle_volume_up(),
SpircCommand::VolumeDown => self.handle_volume_down(),
SpircCommand::Shuffle(shuffle) => self.connect_state.handle_shuffle(shuffle)?,
SpircCommand::Repeat(repeat) => self.connect_state.set_repeat_context(repeat),
SpircCommand::RepeatTrack(repeat) => self.connect_state.set_repeat_track(repeat),
SpircCommand::Shuffle(shuffle) => self.handle_shuffle(shuffle)?,
SpircCommand::Repeat(repeat) => self.handle_repeat(Some(repeat), None)?,
SpircCommand::RepeatTrack(repeat) => self.handle_repeat(None, Some(repeat))?,
SpircCommand::SetPosition(position) => self.handle_seek(position),
SpircCommand::SetVolume(volume) => self.set_volume(volume),
SpircCommand::Load(command) => self.handle_load(command, None).await?,
Expand Down Expand Up @@ -1010,23 +1010,23 @@ impl SpircTask {
trace!("seek to {seek_to:?}");
self.handle_seek(seek_to.value)
}
SetShufflingContext(shuffle) => self.connect_state.handle_shuffle(shuffle.value)?,
SetRepeatingContext(repeat_context) => self
.connect_state
.handle_set_repeat(Some(repeat_context.value), None)?,
SetRepeatingTrack(repeat_track) => self
.connect_state
.handle_set_repeat(None, Some(repeat_track.value))?,
SetShufflingContext(shuffle) => self.handle_shuffle(shuffle.value)?,
SetRepeatingContext(repeat_context) => {
self.handle_repeat(Some(repeat_context.value), None)?
}
SetRepeatingTrack(repeat_track) => {
self.handle_repeat(None, Some(repeat_track.value))?
}
AddToQueue(add_to_queue) => self.connect_state.add_to_queue(add_to_queue.track, true),
SetQueue(set_queue) => self.connect_state.handle_set_queue(set_queue),
SetOptions(set_options) => {
let context = set_options.repeating_context;
let track = set_options.repeating_track;
self.connect_state.handle_set_repeat(context, track)?;
self.handle_repeat(context, track)?;

let shuffle = set_options.shuffling_context;
if let Some(shuffle) = shuffle {
self.connect_state.handle_shuffle(shuffle)?;
self.handle_shuffle(shuffle)?;
}
}
SkipNext(skip_next) => self.handle_next(skip_next.track.map(|t| t.uri))?,
Expand Down Expand Up @@ -1381,6 +1381,20 @@ impl SpircTask {
};
}

fn handle_shuffle(&mut self, shuffle: bool) -> Result<(), Error> {
self.player.emit_shuffle_changed_event(shuffle);
self.connect_state.handle_shuffle(shuffle)
}

fn handle_repeat(&mut self, context: Option<bool>, track: Option<bool>) -> Result<(), Error> {
let context_repeat = context.unwrap_or_else(|| self.connect_state.repeat_context());
let context_track = track.unwrap_or_else(|| self.connect_state.repeat_track());

self.player
.emit_repeat_changed_event(context_repeat, context_track);
self.connect_state.handle_set_repeat(context, track)
}

fn handle_preload_next_track(&mut self) {
// Requests the player thread to preload the next track
match self.play_status {
Expand Down

0 comments on commit dd2330b

Please sign in to comment.