rmptuic61b050
sort by directories in directory browser
+17 −9
1 file changed
- M src/browser.rs +17 −9
| @@ -46,15 +46,23 @@ impl FileBrowser { | |||
| 46 | 46 | ||
| 47 | 47 | pub fn update_directory(&mut self, conn: &mut Connection) -> AppResult<()> { | |
| 48 | 48 | self.filetree.clear(); | |
| 49 | − | self.filetree = conn | |
| 50 | − | .conn | |
| 51 | − | .listfiles(self.path.as_str())? | |
| 52 | − | .into_iter() | |
| 53 | − | .filter(|(f, l)| { | |
| 54 | − | f == "directory" | |
| 55 | − | || f == "file" && Path::new(l).has_extension(&["mp3", "ogg", "flac", "m4a", "wav", "aac" ,"opus", "ape", "wma", "mpc", "aiff", "dff", "mp2", "mka"]) | |
| 56 | − | }) | |
| 57 | − | .collect::<Vec<(String, String)>>(); | |
| 49 | + | let mut file_vec: Vec<(String, String)> = vec![]; | |
| 50 | + | let mut dir_vec: Vec<(String, String)> = vec![]; | |
| 51 | + | for (t, f) in conn.conn.listfiles(self.path.as_str())?.into_iter() { | |
| 52 | + | if t == "directory" { | |
| 53 | + | dir_vec.push((t, f)); | |
| 54 | + | } else if t == "file" | |
| 55 | + | && Path::new(&f).has_extension(&[ | |
| 56 | + | "mp3", "ogg", "flac", "m4a", "wav", "aac", "opus", "ape", "wma", "mpc", "aiff", | |
| 57 | + | "dff", "mp2", "mka", | |
| 58 | + | ]) | |
| 59 | + | { | |
| 60 | + | file_vec.push((t, f)); | |
| 61 | + | } | |
| 62 | + | } | |
| 63 | + | ||
| 64 | + | dir_vec.extend(file_vec); | |
| 65 | + | self.filetree = dir_vec; | |
| 58 | 66 | ||
| 59 | 67 | self.songs.clear(); | |
| 60 | 68 | for (t, song) in self.filetree.iter() { | |