diff --git a/UNRELEASED.md b/UNRELEASED.md index 09e2a24..2534460 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -14,3 +14,4 @@ - Numbering in playlist starts from 1 - Songs are now loaded with correct time - Some button text may not be fully shown +- No more ghosts diff --git a/src/app.rs b/src/app.rs index f3444e8..d564bbe 100644 --- a/src/app.rs +++ b/src/app.rs @@ -265,6 +265,7 @@ impl UampApp { let mut player = Player::from_config(sender.clone(), &conf); player.load_config(&conf); + player.remove_deleted(&lib); let listener = if conf.enable_server() { match Self::start_server(&conf) { diff --git a/src/config/msg.rs b/src/config/msg.rs index d2b5d59..383a75d 100644 --- a/src/config/msg.rs +++ b/src/config/msg.rs @@ -35,7 +35,7 @@ pub enum Message { ShuffleCurrent(bool), ShowHelp(bool), PreviousTimeout(Option), - ShowRemainingTime(bool) + ShowRemainingTime(bool), } #[derive(Clone, Debug, Copy)] @@ -324,7 +324,9 @@ impl UampApp { .previous_timeout_set(config::default_previous_timeout()); } DefMessage::ShowRemainingTime => { - self.config.show_remaining_time_set(config::default_show_remaining_time()); + self.config.show_remaining_time_set( + config::default_show_remaining_time(), + ); } } diff --git a/src/gui/app.rs b/src/gui/app.rs index 96bd1d9..1f31878 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -257,8 +257,15 @@ impl UampApp { fn bottom_menu(&self) -> Element { let song = self.player.now_playing().map(|s| &self.library[s]); - let title = song.map(|s| s.title()).unwrap_or("-"); - let artist = song.map(|s| s.artist()).unwrap_or("-"); + let (title, artist) = if let Some(s) = song { + if s.is_deleted() { + ("-", "-") + } else { + (s.title(), s.artist()) + } + } else { + ("-", "-") + }; container(grid![ Relative(2.), Relative(1.), Fixed(210.), Relative(1.), Relative(2.); diff --git a/src/gui/elements.rs b/src/gui/elements.rs index dbb56db..305eff2 100644 --- a/src/gui/elements.rs +++ b/src/gui/elements.rs @@ -118,7 +118,11 @@ impl UampApp { .style(Container::Dark), wrap_box( (0..songs.len()) - .map(|i| self.song_list_item(i, songs.clone(), numbered)) + .filter_map(|i| self.song_list_item( + i, + songs.clone(), + numbered + )) .collect(), state, ) @@ -134,7 +138,7 @@ impl UampApp { song: usize, songs: Arc<[SongId]>, numbered: bool, - ) -> Element<'static> { + ) -> Option> { let text_style = if Some(songs[song]) == self.player.now_playing() { Text::Contrast } else { @@ -143,6 +147,10 @@ impl UampApp { let s = &self.library[songs[song]]; + if s.is_deleted() { + return None; + } + fn top_text<'a, S>(s: S, portion: u16, style: Text) -> Element<'a> where S: Into>, @@ -197,13 +205,15 @@ impl UampApp { info.padding([0, 10, 0, 10]).into() }; - border( - button(cursor_grad(item).style(CursorGrad::Long)) - .padding(0) - .on_press(Msg::PlaySong(song, songs)), + Some( + border( + button(cursor_grad(item).style(CursorGrad::Long)) + .padding(0) + .on_press(Msg::PlaySong(song, songs)), + ) + .style(Border::SongItem) + .into(), ) - .style(Border::SongItem) - .into() } } diff --git a/src/gui/settings/help.rs b/src/gui/settings/help.rs index 0849c57..d69daf7 100644 --- a/src/gui/settings/help.rs +++ b/src/gui/settings/help.rs @@ -336,8 +336,9 @@ pub const SHOW_REMAINING_TIME: SetHelp = SetHelp { value_type: Some("bool"), default_value: Some("false"), reset_message: Some(DefMessage::ShowRemainingTime), - description: "When enabled, the time to the right of the seek slider will \ -show the remaining time instead of the total time." + description: + "When enabled, the time to the right of the seek slider will \ +show the remaining time instead of the total time.", }; impl SetHelp { diff --git a/src/player/player.rs b/src/player/player.rs index d9696b3..ebeb11f 100644 --- a/src/player/player.rs +++ b/src/player/player.rs @@ -286,6 +286,14 @@ impl Player { error!("Failed to seek: {e}"); } } + + pub fn remove_deleted(&mut self, lib: &Library) { + let cur = self.now_playing(); + self.playlist_mut().remove_deleted(lib); + if let Some(cur) = cur { + self.current_set(self.playlist.iter().position(|i| i == &cur)); + } + } } impl UampApp { diff --git a/src/player/playlist.rs b/src/player/playlist.rs index 5433640..33a1b00 100644 --- a/src/player/playlist.rs +++ b/src/player/playlist.rs @@ -4,9 +4,10 @@ use std::{ sync::Arc, }; +use itertools::Itertools; use serde::{Deserialize, Serialize}; -use crate::library::SongId; +use crate::library::{Library, SongId}; /// A playlist, lazily cloned pub enum Playlist { @@ -42,6 +43,20 @@ impl Playlist { Playlist::Dynamic(v) => v[..].into(), } } + + pub fn remove_deleted(&mut self, lib: &Library) { + match self { + Playlist::Static(a) => { + *self = Playlist::Dynamic( + a.iter() + .map(|s| *s) + .filter(|s| !lib[*s].is_deleted()) + .collect_vec(), + ) + } + Playlist::Dynamic(v) => v.retain(|s| !lib[*s].is_deleted()), + } + } } impl Default for Playlist {