rmptuibb5bcea
fix #4
+16 −26
2 files changed
- M src/app.rs +14 −21
- M src/main.rs +2 −5
| @@ -12,12 +12,12 @@ pub type AppResult<T> = std::result::Result<T, Box<dyn std::error::Error>>; | |||
| 12 | 12 | /// Application | |
| 13 | 13 | #[derive(Debug)] | |
| 14 | 14 | pub struct App { | |
| 15 | − | pub running: bool, // Check if app is running | |
| 16 | − | pub conn: Connection, // Connection | |
| 17 | − | pub browser: FileBrowser, // Directory browser | |
| 18 | − | pub queue_list: ContentList<Song>, // Stores the current playing queue | |
| 19 | − | pub pl_list: ContentList<String>, // Stores list of playlists | |
| 20 | − | pub selected_tab: SelectedTab, // Used to switch between tabs | |
| 15 | + | pub running: bool, // Check if app is running | |
| 16 | + | pub conn: Connection, // Connection | |
| 17 | + | pub browser: FileBrowser, // Directory browser | |
| 18 | + | pub queue_list: ContentList<Song>, // Stores the current playing queue | |
| 19 | + | pub pl_list: ContentList<String>, // Stores list of playlists | |
| 20 | + | pub selected_tab: SelectedTab, // Used to switch between tabs | |
| 21 | 21 | ||
| 22 | 22 | // Search | |
| 23 | 23 | pub inputmode: InputMode, // Defines input mode, Normal or Search | |
| @@ -194,15 +194,6 @@ impl App { | |||
| 194 | 194 | browser.selected = 0; | |
| 195 | 195 | } | |
| 196 | 196 | } else { | |
| 197 | − | // let list = conn | |
| 198 | − | // .songs_filenames | |
| 199 | − | // .iter() | |
| 200 | − | // .map(|f| f.as_str()) | |
| 201 | − | // .collect::<Vec<&str>>(); | |
| 202 | − | // let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(&path, &list) | |
| 203 | − | // .get(0) | |
| 204 | − | // .unwrap() | |
| 205 | − | // .clone(); | |
| 206 | 197 | let index = self | |
| 207 | 198 | .queue_list | |
| 208 | 199 | .list | |
| @@ -212,12 +203,14 @@ impl App { | |||
| 212 | 203 | if index.is_some() { | |
| 213 | 204 | self.conn.conn.switch(index.unwrap() as u32)?; | |
| 214 | 205 | } else { | |
| 215 | − | for filename in self.conn.songs_filenames.clone().iter() { | |
| 216 | − | if filename.contains(path) { | |
| 217 | − | let song = self.conn.get_song_with_only_filename(filename); | |
| 218 | − | self.conn.push(&song)?; | |
| 219 | − | } | |
| 220 | − | } | |
| 206 | + | let mut filename = format!("{}/{}", browser.path, path); | |
| 207 | + | ||
| 208 | + | // Remove "./" from the beginning of filename | |
| 209 | + | filename.remove(0); | |
| 210 | + | filename.remove(0); | |
| 211 | + | ||
| 212 | + | let song = self.conn.get_song_with_only_filename(&filename); | |
| 213 | + | self.conn.push(&song)?; | |
| 221 | 214 | ||
| 222 | 215 | // updating queue, to avoid multiple pushes of the same songs if we enter multiple times before the queue gets updated | |
| 223 | 216 | self.update_queue(); | |
| @@ -1,3 +1,4 @@ | |||
| 1 | + | use ratatui::prelude::*; | |
| 1 | 2 | use rmptui::app::App; | |
| 2 | 3 | use rmptui::app::AppResult; | |
| 3 | 4 | use rmptui::event::event::Event; | |
| @@ -6,10 +7,6 @@ use rmptui::event::handler; | |||
| 6 | 7 | use rmptui::tui; | |
| 7 | 8 | use std::env; | |
| 8 | 9 | use std::io; | |
| 9 | − | use ratatui::prelude::*; | |
| 10 | − | ||
| 11 | − | pub type Result<T> = core::result::Result<T, Error>; | |
| 12 | − | pub type Error = Box<dyn std::error::Error>; | |
| 13 | 10 | ||
| 14 | 11 | fn main() -> AppResult<()> { | |
| 15 | 12 | // Connection | |
| @@ -26,7 +23,7 @@ fn main() -> AppResult<()> { | |||
| 26 | 23 | tui.init()?; | |
| 27 | 24 | ||
| 28 | 25 | // initial directory read | |
| 29 | − | app.browser.update_directory(&mut app.conn).unwrap(); | |
| 26 | + | app.browser.update_directory(&mut app.conn)?; | |
| 30 | 27 | ||
| 31 | 28 | while app.running { | |
| 32 | 29 | tui.draw(&mut app)?; | |