1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 09:49:31 +02:00

Emit shuffle and repeat events again (#1469)

* emit shuffle and repeat events again

* connect: split context/track repeat handling
This commit is contained in:
Felix Prillwitz 2025-03-22 20:17:46 +01:00 committed by GitHub
parent 11c3df8eb1
commit 837b3e6d1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 33 deletions

View file

@ -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_context(repeat)?,
SpircCommand::RepeatTrack(repeat) => self.handle_repeat_track(repeat),
SpircCommand::SetPosition(position) => self.handle_seek(position),
SpircCommand::SetVolume(volume) => self.set_volume(volume),
SpircCommand::Load(command) => self.handle_load(command, None).await?,
@ -1010,23 +1010,25 @@ 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_context(repeat_context.value)?
}
SetRepeatingTrack(repeat_track) => self.handle_repeat_track(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)?;
if let Some(repeat_context) = set_options.repeating_context {
self.handle_repeat_context(repeat_context)?
}
if let Some(repeat_track) = set_options.repeating_track {
self.handle_repeat_track(repeat_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))?,
@ -1381,6 +1383,23 @@ 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_context(&mut self, repeat: bool) -> Result<(), Error> {
self.player
.emit_repeat_changed_event(repeat, self.connect_state.repeat_track());
self.connect_state.handle_set_repeat_context(repeat)
}
fn handle_repeat_track(&mut self, repeat: bool) {
self.player
.emit_repeat_changed_event(self.connect_state.repeat_context(), repeat);
self.connect_state.set_repeat_track(repeat);
}
fn handle_preload_next_track(&mut self) {
// Requests the player thread to preload the next track
match self.play_status {

View file

@ -40,26 +40,10 @@ impl ConnectState {
self.update_queue_revision();
}
pub fn handle_set_repeat(
&mut self,
context: Option<bool>,
track: Option<bool>,
) -> Result<(), Error> {
// doesn't need any state updates, because it should only change how the current song is played
if let Some(track) = track {
self.set_repeat_track(track);
}
pub fn handle_set_repeat_context(&mut self, repeat: bool) -> Result<(), Error> {
self.set_repeat_context(repeat);
if matches!(context, Some(context) if self.repeat_context() == context) || context.is_none()
{
return Ok(());
}
if let Some(context) = context {
self.set_repeat_context(context);
}
if self.repeat_context() {
if repeat {
self.set_shuffle(false);
self.reset_context(ResetContext::DefaultIndex);