diff --git a/psst-core/src/player/queue.rs b/psst-core/src/player/queue.rs index 27566e9b..cd4c61d8 100644 --- a/psst-core/src/player/queue.rs +++ b/psst-core/src/player/queue.rs @@ -74,6 +74,10 @@ impl Queue { self.user_items.push(item); } + pub fn get_playing_from_user_items_bool(&mut self) -> bool{ + self.playing_from_user_items + } + pub fn remove(&mut self, index: usize) { if self.playing_from_user_items { self.user_items.remove(index+1); diff --git a/psst-gui/src/controller/playback.rs b/psst-gui/src/controller/playback.rs index c1dce9de..e4b74d5b 100644 --- a/psst-gui/src/controller/playback.rs +++ b/psst-gui/src/controller/playback.rs @@ -357,13 +357,12 @@ where let (item, progress) = cmd.get_unchecked(cmd::PLAYBACK_PLAYING); // TODO: this falsely removes the song if you click on a song from the playlist that is also in the queue, not sure how to solve this? - if !data.displayed_added_queue.is_empty() && data.playback.now_playing.as_mut().is_some_and(|np| { + if !data.added_queue.displayed_queue.is_empty() && data.playback.now_playing.as_mut().is_some_and(|np| { np.origin.to_string() == PlaybackOrigin::Queue.to_string() - && np.item.id() == data.displayed_added_queue[0].item.id() + && np.item.id() == data.added_queue.displayed_queue[0].item.id() }) { - data.displayed_added_queue.remove(0); + data.added_queue.displayed_queue.remove(0); } - if let Some(queued) = data.queued_entry(*item) { data.start_playback(queued.item, queued.origin, progress.to_owned()); self.update_media_control_playback(&data.playback); @@ -463,12 +462,12 @@ where Ordering::Greater => { if data.playback.queue.is_empty() || (data.playback.queue.len() <= 1 && data.playback.queue[0].origin.to_string() == PlaybackOrigin::Queue.to_string()) { data.playback.queue.clear(); - data.playback.queue.push_back(data.displayed_added_queue[track_pos].clone()); - data.displayed_added_queue = data.displayed_added_queue.split_off(track_pos); + data.playback.queue.push_back(data.added_queue.displayed_queue[track_pos].clone()); + data.added_queue.displayed_queue = data.added_queue.displayed_queue.split_off(track_pos); self.skip_to_place_in_queue(&(track_pos+1)); self.play(&data.playback.queue, track_pos);} else if data.playback.now_playing.is_some() { - data.displayed_added_queue = data.displayed_added_queue.split_off(track_pos); + data.added_queue.displayed_queue = data.added_queue.displayed_queue.split_off(track_pos); self.skip_to_place_in_queue(&track_pos); self.next(); } @@ -476,9 +475,9 @@ where Ordering::Equal => { if data.playback.queue.is_empty() || (data.playback.queue.len() <= 1 && data.playback.queue[0].origin.to_string() == PlaybackOrigin::Queue.to_string()) { data.playback.queue.clear(); - data.playback.queue.push_back(data.displayed_added_queue[track_pos].clone()); + data.playback.queue.push_back(data.added_queue.displayed_queue[track_pos].clone()); self.remove_from_queue(&track_pos); - data.displayed_added_queue.remove(track_pos); + data.added_queue.displayed_queue.remove(track_pos); self.play(&data.playback.queue, track_pos); } else if data.playback.now_playing.is_some() { @@ -491,14 +490,14 @@ where } Event::Command(cmd) if cmd.is(cmd::REMOVE_FROM_QUEUE) => { let item = cmd.get_unchecked(cmd::REMOVE_FROM_QUEUE); - data.displayed_added_queue.remove(*item); + data.added_queue.displayed_queue.remove(*item); self.remove_from_queue(item); data.info_alert("Track removed from queue."); ctx.set_handled(); } Event::Command(cmd) if cmd.is(cmd::CLEAR_QUEUE) => { - data.displayed_added_queue.clear(); + data.added_queue.displayed_queue.clear(); self.clear_queue(); data.info_alert("Tracks cleared from queue."); ctx.set_handled(); diff --git a/psst-gui/src/data/mod.rs b/psst-gui/src/data/mod.rs index b802418f..d4df310a 100644 --- a/psst-gui/src/data/mod.rs +++ b/psst-gui/src/data/mod.rs @@ -82,9 +82,14 @@ pub struct AppState { pub home_detail: HomeDetail, pub alerts: Vector, pub finder: Finder, - pub added_queue: Vector, + pub added_queue: QueueFields, +} + +#[derive(Clone, Data, Lens)] +pub struct QueueFields { + pub queue: Vector, // TODO: This is a problem, due to added_queue never changing, the origin of a song, if also once added to the queue, will always be the queue. - pub displayed_added_queue: Vector, + pub displayed_queue: Vector, } impl AppState { @@ -124,8 +129,10 @@ impl AppState { cache_size: Promise::Empty, }, playback, - added_queue: Vector::new(), - displayed_added_queue: Vector::new(), + added_queue: QueueFields { + queue: Vector::new(), + displayed_queue: Vector::new(), + }, search: Search { input: "".into(), results: Promise::Empty, @@ -197,6 +204,7 @@ impl AppState { pub fn queued_entry(&self, item_id: ItemId) -> Option { if let Some(queued) = self .added_queue + .queue .iter() .find(|queued| queued.item.id() == item_id) .cloned() @@ -216,8 +224,8 @@ impl AppState { } pub fn add_queued_entry(&mut self, queue_entry: QueueEntry) { - self.added_queue.push_back(queue_entry.clone()); - self.displayed_added_queue.push_back(queue_entry); + self.added_queue.queue.push_back(queue_entry.clone()); + self.added_queue.displayed_queue.push_back(queue_entry); } pub fn loading_playback(&mut self, item: Playable, origin: PlaybackOrigin) { diff --git a/psst-gui/src/ui/queued.rs b/psst-gui/src/ui/queued.rs index 0c610ce3..749869bd 100644 --- a/psst-gui/src/ui/queued.rs +++ b/psst-gui/src/ui/queued.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use crate::{ cmd, - data::{AppState, Nav, QueueEntry, RecommendationsRequest}, + data::{AppState, Nav, QueueEntry, QueueFields, RecommendationsRequest}, ui::Vector, widget::{icons, Border, Empty, MyWidgetExt}, }; @@ -43,7 +43,7 @@ pub fn queue_widget() -> impl Widget { .with_flex_child( Scroll::new(queue_list_widget()) .vertical() - .lens(AppState::displayed_added_queue.map( + .lens(AppState::added_queue.then(QueueFields::displayed_queue).map( |entries| queue_entries_with_index(entries.clone()), |_, _| (), )),