diff --git a/src/commands.rs b/src/commands.rs index c656d42..7957c14 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -120,13 +120,7 @@ impl CommandManager { self.queue.get_current_index() ); s.queuestate.queue = queue.clone(); - s.queuestate.random_order = self - .queue - .get_random_order() - .read() - .unwrap() - .as_ref() - .cloned(); + s.queuestate.random_order = self.queue.get_random_order(); s.queuestate.current_track = self.queue.get_current_index(); s.queuestate.track_progress = self.spotify.get_current_progress(); }); diff --git a/src/queue.rs b/src/queue.rs index 73bb33b..e138221 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -43,7 +43,7 @@ pub struct Queue { /// the raw data only. pub queue: Arc>>, /// The playback order of the queue, as indices into `self.queue`. - random_order: Arc>>>, + random_order: RwLock>>, current_track: RwLock>, spotify: Spotify, cfg: Arc, @@ -62,7 +62,7 @@ impl Queue { queue: Arc::new(RwLock::new(queue_state.queue)), spotify: spotify.clone(), current_track: RwLock::new(queue_state.current_track), - random_order: Arc::new(RwLock::new(queue_state.random_order)), + random_order: RwLock::new(queue_state.random_order), cfg, #[cfg(feature = "notify")] notification_id: Arc::new(AtomicU32::new(0)), @@ -442,8 +442,8 @@ impl Queue { } /// Get the current order that is used to shuffle. - pub fn get_random_order(&self) -> Arc>>> { - self.random_order.clone() + pub fn get_random_order(&self) -> Option> { + self.random_order.read().unwrap().clone() } /// (Re)generate the random shuffle order. diff --git a/src/ui/listview.rs b/src/ui/listview.rs index 61f9212..437ac31 100644 --- a/src/ui/listview.rs +++ b/src/ui/listview.rs @@ -34,7 +34,6 @@ use crate::ui::pagination::Pagination; pub struct ListView { content: Arc>>, - order: Arc>>>, last_content_len: usize, selected: usize, search_query: String, @@ -62,7 +61,6 @@ impl ListView { pub fn new(content: Arc>>, queue: Arc, library: Arc) -> Self { let result = Self { content, - order: Arc::new(RwLock::new(None)), last_content_len: 0, selected: 0, search_query: String::new(), @@ -79,11 +77,6 @@ impl ListView { result } - pub fn with_order(mut self, order: Arc>>>) -> Self { - self.order = order; - self - } - pub fn with_title(mut self, title: &str) -> Self { self.title = title.to_string(); self @@ -200,19 +193,11 @@ impl View for ListView { printer.print((0, 0), &buf); }); } else if i < content.len() { - let current_index = if self.order.read().unwrap().is_some() { - self.order.read().unwrap().as_ref().unwrap()[i] - } else { - i - }; - - let item = &content[current_index]; - - let currently_playing = item.is_playing(&self.queue) - && self.queue.get_current_index() == Some(current_index); + let item = &content[i]; + let currently_playing = + item.is_playing(&self.queue) && self.queue.get_current_index() == Some(i); let style = if self.selected == i { - // Highlight the currently selected item. if currently_playing { ColorStyle::new( *printer.theme.palette.custom("playing_selected").unwrap(), @@ -222,7 +207,6 @@ impl View for ListView { ColorStyle::highlight() } } else if currently_playing { - // Apply a different color to the currently playing item. ColorStyle::new( ColorType::Color(*printer.theme.palette.custom("playing").unwrap()), ColorType::Color(*printer.theme.palette.custom("playing_bg").unwrap()), diff --git a/src/ui/queue.rs b/src/ui/queue.rs index 0c3dcbc..d0342a1 100644 --- a/src/ui/queue.rs +++ b/src/ui/queue.rs @@ -23,8 +23,7 @@ pub struct QueueView { impl QueueView { pub fn new(queue: Arc, library: Arc) -> QueueView { - let list = ListView::new(queue.queue.clone(), queue.clone(), library.clone()) - .with_order(queue.get_random_order()); + let list = ListView::new(queue.queue.clone(), queue.clone(), library.clone()); QueueView { list,