rmptuibba509f
make dmenu optional, dont crash
+16 −14
2 files changed
- M README.md +4 −0
- M src/connection.rs +12 −14
| @@ -34,6 +34,10 @@ A MPD client in Rust | |||
| 34 | 34 | - `g` to go to top of list | |
| 35 | 35 | - `G` to go to bottom of list | |
| 36 | 36 | ||
| 37 | + | ### Prerequisites | |
| 38 | + | - [MPD](https://wiki.archlinux.org/title/Music_Player_Daemon) installed and configured. | |
| 39 | + | - [dmenu](https://tools.suckless.org/dmenu/) (optional) | |
| 40 | + | ||
| 37 | 41 | ### TODO | |
| 38 | 42 | - [x] fix performance issues | |
| 39 | 43 | - [x] improvements on queue control | |
| @@ -66,14 +66,16 @@ impl Connection { | |||
| 66 | 66 | ||
| 67 | 67 | /// Dmenu prompt for selecting songs | |
| 68 | 68 | pub fn play_dmenu(&mut self) -> Result<()> { | |
| 69 | − | is_installed("dmenu")?; | |
| 70 | − | let ss: Vec<&str> = self.songs_filenames.iter().map(|x| x.as_str()).collect(); | |
| 71 | − | let op = dmenu!(iter &ss; args "-p", "Choose a song: ", "-l", "30"); | |
| 72 | − | let index = ss.iter().position(|s| s == &op); | |
| 73 | − | if let Some(i) = index { | |
| 74 | − | let song = self.get_song_with_only_filename(ss.get(i).unwrap()); | |
| 75 | − | self.push(&song)?; | |
| 69 | + | if is_installed("dmenu") { | |
| 70 | + | let ss: Vec<&str> = self.songs_filenames.iter().map(|x| x.as_str()).collect(); | |
| 71 | + | let op = dmenu!(iter &ss; args "-p", "Choose a song: ", "-l", "30"); | |
| 72 | + | let index = ss.iter().position(|s| s == &op); | |
| 73 | + | if let Some(i) = index { | |
| 74 | + | let song = self.get_song_with_only_filename(ss.get(i).unwrap()); | |
| 75 | + | self.push(&song)?; | |
| 76 | + | } | |
| 76 | 77 | } | |
| 78 | + | ||
| 77 | 79 | Ok(()) | |
| 78 | 80 | } | |
| 79 | 81 | ||
| @@ -240,15 +242,11 @@ impl Connection { | |||
| 240 | 242 | } | |
| 241 | 243 | ||
| 242 | 244 | /// Checks if given program is installed in your system | |
| 243 | − | fn is_installed(ss: &str) -> Result<()> { | |
| 245 | + | fn is_installed(ss: &str) -> bool { | |
| 244 | 246 | let output = Command::new("which") | |
| 245 | 247 | .arg(ss) | |
| 246 | 248 | .output() | |
| 247 | 249 | .expect("Failed to execute command"); | |
| 248 | − | if output.status.success() { | |
| 249 | − | Ok(()) | |
| 250 | − | } else { | |
| 251 | − | let err = format!("{} not installed", ss); | |
| 252 | − | Err(err.into()) | |
| 253 | − | } | |
| 250 | + | ||
| 251 | + | output.status.success() | |
| 254 | 252 | } | |