From 6b66a44ed035c33c43377a63b23856923743ea09 Mon Sep 17 00:00:00 2001 From: krolxon Date: Sun, 28 Apr 2024 23:59:42 +0530 Subject: fix queue deletion & make get_full_path return an option --- src/app.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index 7286657..22cd91e 100755 --- a/src/app.rs +++ b/src/app.rs @@ -113,11 +113,11 @@ impl App { Ok(()) } - pub fn handle_remove_or_from_current_playlist(&mut self) -> AppResult<()> { + pub fn handle_add_or_remove_from_current_playlist(&mut self) -> AppResult<()> { match self.selected_tab { SelectedTab::DirectoryBrowser => { let (_, file) = self.browser.filetree.get(self.browser.selected).unwrap(); - self.browser.selected += 1; + let mut status = false; for (i, song) in self.queue_list.list.clone().iter().enumerate() { if song.contains(file) { @@ -127,14 +127,21 @@ impl App { } if !status { - let song = self - .conn - .get_song_with_only_filename(&self.conn.get_full_path(&file).unwrap()); - self.conn.conn.push(&song)?; + if let Some(full_path) = &self.conn.get_full_path(&file) { + let song = self.conn.get_song_with_only_filename(full_path); + self.conn.conn.push(&song)?; + } + } + + if self.browser.selected != self.browser.filetree.len() - 1 { + self.browser.selected += 1; } } SelectedTab::Queue => { + if self.queue_list.list.len() == 0 { + return Ok(()); + } let file = self .queue_list .list @@ -145,6 +152,9 @@ impl App { for (i, song) in self.queue_list.list.clone().iter().enumerate() { if song.contains(&file) { self.conn.conn.delete(i as u32).unwrap(); + if self.queue_list.index != 0 { + self.queue_list.index -= 1; + } } } } @@ -205,9 +215,10 @@ impl App { } pub fn search_song(&mut self) -> AppResult<()> { - let filename = self.conn.get_full_path(&self.search_input)?; - let song = self.conn.get_song_with_only_filename(&filename); - self.conn.push(&song)?; + if let Some(filename) = self.conn.get_full_path(&self.search_input) { + let song = self.conn.get_song_with_only_filename(&filename); + self.conn.push(&song)?; + } Ok(()) } -- cgit v1.2.3