Krolyxon
Commit bb5bcea

rmptuibb5bcea

fix #4

Author
krolxon
Date
2024-05-13 13:41 +0530
Parent
1e02da6
Commit
bb5bcea3ff0f3205d087637ab485ef066309adeb

+16 −26

2 files changed

  1. M src/app.rs +14 −21
  2. M src/main.rs +2 −5
M src/app.rs View
@@ -12,12 +12,12 @@ pub type AppResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
1212 /// Application
1313 #[derive(Debug)]
1414 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
2121
2222 // Search
2323 pub inputmode: InputMode, // Defines input mode, Normal or Search
@@ -194,15 +194,6 @@ impl App {
194194 browser.selected = 0;
195195 }
196196 } 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();
206197 let index = self
207198 .queue_list
208199 .list
@@ -212,12 +203,14 @@ impl App {
212203 if index.is_some() {
213204 self.conn.conn.switch(index.unwrap() as u32)?;
214205 } 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)?;
221214
222215 // updating queue, to avoid multiple pushes of the same songs if we enter multiple times before the queue gets updated
223216 self.update_queue();
M src/main.rs View
@@ -1,3 +1,4 @@
1+use ratatui::prelude::*;
12 use rmptui::app::App;
23 use rmptui::app::AppResult;
34 use rmptui::event::event::Event;
@@ -6,10 +7,6 @@ use rmptui::event::handler;
67 use rmptui::tui;
78 use std::env;
89 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>;
1310
1411 fn main() -> AppResult<()> {
1512 // Connection
@@ -26,7 +23,7 @@ fn main() -> AppResult<()> {
2623 tui.init()?;
2724
2825 // initial directory read
29− app.browser.update_directory(&mut app.conn).unwrap();
26+ app.browser.update_directory(&mut app.conn)?;
3027
3128 while app.running {
3229 tui.draw(&mut app)?;