Krolyxon
Commit bba509f

rmptuibba509f

make dmenu optional, dont crash

Author
krolxon
Date
2024-05-13 17:32 +0530
Parent
bc7ab75
Commit
bba509fabf490ab51afc60124f0e4cf1a1db6a3d

+16 −14

2 files changed

  1. M README.md +4 −0
  2. M src/connection.rs +12 −14
M README.md View
@@ -34,6 +34,10 @@ A MPD client in Rust
3434 - `g` to go to top of list
3535 - `G` to go to bottom of list
3636
37+### Prerequisites
38+- [MPD](https://wiki.archlinux.org/title/Music_Player_Daemon) installed and configured.
39+- [dmenu](https://tools.suckless.org/dmenu/) (optional)
40+
3741 ### TODO
3842 - [x] fix performance issues
3943 - [x] improvements on queue control
M src/connection.rs View
@@ -66,14 +66,16 @@ impl Connection {
6666
6767 /// Dmenu prompt for selecting songs
6868 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+ }
7677 }
78+
7779 Ok(())
7880 }
7981
@@ -240,15 +242,11 @@ impl Connection {
240242 }
241243
242244 /// Checks if given program is installed in your system
243−fn is_installed(ss: &str) -> Result<()> {
245+fn is_installed(ss: &str) -> bool {
244246 let output = Command::new("which")
245247 .arg(ss)
246248 .output()
247249 .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()
254252 }