Skip to content

Commit 837b3e6

Browse files
authored
Emit shuffle and repeat events again (#1469)
* emit shuffle and repeat events again * connect: split context/track repeat handling
1 parent 11c3df8 commit 837b3e6

2 files changed

Lines changed: 36 additions & 33 deletions

File tree

connect/src/spirc.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,9 @@ impl SpircTask {
641641
SpircCommand::Next => self.handle_next(None)?,
642642
SpircCommand::VolumeUp => self.handle_volume_up(),
643643
SpircCommand::VolumeDown => self.handle_volume_down(),
644-
SpircCommand::Shuffle(shuffle) => self.connect_state.handle_shuffle(shuffle)?,
645-
SpircCommand::Repeat(repeat) => self.connect_state.set_repeat_context(repeat),
646-
SpircCommand::RepeatTrack(repeat) => self.connect_state.set_repeat_track(repeat),
644+
SpircCommand::Shuffle(shuffle) => self.handle_shuffle(shuffle)?,
645+
SpircCommand::Repeat(repeat) => self.handle_repeat_context(repeat)?,
646+
SpircCommand::RepeatTrack(repeat) => self.handle_repeat_track(repeat),
647647
SpircCommand::SetPosition(position) => self.handle_seek(position),
648648
SpircCommand::SetVolume(volume) => self.set_volume(volume),
649649
SpircCommand::Load(command) => self.handle_load(command, None).await?,
@@ -1010,23 +1010,25 @@ impl SpircTask {
10101010
trace!("seek to {seek_to:?}");
10111011
self.handle_seek(seek_to.value)
10121012
}
1013-
SetShufflingContext(shuffle) => self.connect_state.handle_shuffle(shuffle.value)?,
1014-
SetRepeatingContext(repeat_context) => self
1015-
.connect_state
1016-
.handle_set_repeat(Some(repeat_context.value), None)?,
1017-
SetRepeatingTrack(repeat_track) => self
1018-
.connect_state
1019-
.handle_set_repeat(None, Some(repeat_track.value))?,
1013+
SetShufflingContext(shuffle) => self.handle_shuffle(shuffle.value)?,
1014+
SetRepeatingContext(repeat_context) => {
1015+
self.handle_repeat_context(repeat_context.value)?
1016+
}
1017+
SetRepeatingTrack(repeat_track) => self.handle_repeat_track(repeat_track.value),
10201018
AddToQueue(add_to_queue) => self.connect_state.add_to_queue(add_to_queue.track, true),
10211019
SetQueue(set_queue) => self.connect_state.handle_set_queue(set_queue),
10221020
SetOptions(set_options) => {
1023-
let context = set_options.repeating_context;
1024-
let track = set_options.repeating_track;
1025-
self.connect_state.handle_set_repeat(context, track)?;
1021+
if let Some(repeat_context) = set_options.repeating_context {
1022+
self.handle_repeat_context(repeat_context)?
1023+
}
1024+
1025+
if let Some(repeat_track) = set_options.repeating_track {
1026+
self.handle_repeat_track(repeat_track)
1027+
}
10261028

10271029
let shuffle = set_options.shuffling_context;
10281030
if let Some(shuffle) = shuffle {
1029-
self.connect_state.handle_shuffle(shuffle)?;
1031+
self.handle_shuffle(shuffle)?;
10301032
}
10311033
}
10321034
SkipNext(skip_next) => self.handle_next(skip_next.track.map(|t| t.uri))?,
@@ -1381,6 +1383,23 @@ impl SpircTask {
13811383
};
13821384
}
13831385

1386+
fn handle_shuffle(&mut self, shuffle: bool) -> Result<(), Error> {
1387+
self.player.emit_shuffle_changed_event(shuffle);
1388+
self.connect_state.handle_shuffle(shuffle)
1389+
}
1390+
1391+
fn handle_repeat_context(&mut self, repeat: bool) -> Result<(), Error> {
1392+
self.player
1393+
.emit_repeat_changed_event(repeat, self.connect_state.repeat_track());
1394+
self.connect_state.handle_set_repeat_context(repeat)
1395+
}
1396+
1397+
fn handle_repeat_track(&mut self, repeat: bool) {
1398+
self.player
1399+
.emit_repeat_changed_event(self.connect_state.repeat_context(), repeat);
1400+
self.connect_state.set_repeat_track(repeat);
1401+
}
1402+
13841403
fn handle_preload_next_track(&mut self) {
13851404
// Requests the player thread to preload the next track
13861405
match self.play_status {

connect/src/state/handle.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,10 @@ impl ConnectState {
4040
self.update_queue_revision();
4141
}
4242

43-
pub fn handle_set_repeat(
44-
&mut self,
45-
context: Option<bool>,
46-
track: Option<bool>,
47-
) -> Result<(), Error> {
48-
// doesn't need any state updates, because it should only change how the current song is played
49-
if let Some(track) = track {
50-
self.set_repeat_track(track);
51-
}
52-
53-
if matches!(context, Some(context) if self.repeat_context() == context) || context.is_none()
54-
{
55-
return Ok(());
56-
}
57-
58-
if let Some(context) = context {
59-
self.set_repeat_context(context);
60-
}
43+
pub fn handle_set_repeat_context(&mut self, repeat: bool) -> Result<(), Error> {
44+
self.set_repeat_context(repeat);
6145

62-
if self.repeat_context() {
46+
if repeat {
6347
self.set_shuffle(false);
6448
self.reset_context(ResetContext::DefaultIndex);
6549

0 commit comments

Comments
 (0)