diff options
Diffstat (limited to 'src/app.rs')
| -rw-r--r-- | src/app.rs | 55 |
1 files changed, 36 insertions, 19 deletions
@@ -275,7 +275,7 @@ impl App { if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup(); } else if let Some(PopupKind::OpenRes) = self.bibiman.popup_area.popup_kind { - self.bibiman.open_connected_res()?; + self.bibiman.open_connected_res(cfg)?; } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind { self.bibiman.append_entry_to_file(args)? @@ -362,16 +362,20 @@ impl App { } } -pub fn open_connected_file(file: &OsStr) -> Result<()> { +pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard // TODO: make custom opener command possible through config - let cmd = { - match std::env::consts::OS { - "linux" => String::from("xdg-open"), - "macos" => String::from("open"), - "windows" => String::from("start"), - _ => panic!("Couldn't detect OS for setting correct opener"), - } + // let cmd = { + // match std::env::consts::OS { + // "linux" => String::from("xdg-open"), + // "macos" => String::from("open"), + // "windows" => String::from("start"), + // _ => panic!("Couldn't detect OS for setting correct opener"), + // } + // }; + let cmd = match &cfg.general.pdf_opener { + Some(c) => c, + None => &select_opener(), }; // If necessary, replace ~ with /home dir @@ -381,7 +385,7 @@ pub fn open_connected_file(file: &OsStr) -> Result<()> { // Pass filepath as argument, pipe stdout and stderr to /dev/null // to keep the TUI clean (where is it piped on Windows???) - let _ = Command::new(&cmd) + let _ = Command::new(cmd) .arg(file) .stdout(Stdio::null()) .stderr(Stdio::null()) @@ -391,21 +395,25 @@ pub fn open_connected_file(file: &OsStr) -> Result<()> { Ok(()) } -pub fn open_connected_link(link: &str) -> Result<()> { +pub fn open_connected_link(cfg: &BibiConfig, link: &str) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard // TODO: make custom opener command possible through config - let cmd = { - match std::env::consts::OS { - "linux" => String::from("xdg-open"), - "macos" => String::from("open"), - "windows" => String::from("start"), - _ => panic!("Couldn't detect OS for setting correct opener"), - } + // let cmd = { + // match std::env::consts::OS { + // "linux" => String::from("xdg-open"), + // "macos" => String::from("open"), + // "windows" => String::from("start"), + // _ => panic!("Couldn't detect OS for setting correct opener"), + // } + // }; + let cmd = match &cfg.general.url_opener { + Some(c) => c, + None => &select_opener(), }; // Pass filepath as argument, pipe stdout and stderr to /dev/null // to keep the TUI clean (where is it piped on Windows???) - let _ = Command::new(&cmd) + let _ = Command::new(cmd) .arg(link) .stdout(Stdio::null()) .stderr(Stdio::null()) @@ -437,6 +445,15 @@ fn expand_home(path: &PathBuf) -> PathBuf { } } +fn select_opener() -> String { + match std::env::consts::OS { + "linux" => String::from("xdg-open"), + "macos" => String::from("open"), + "windows" => String::from("start"), + _ => panic!("Couldn't detect OS for setting correct opener"), + } +} + #[cfg(test)] mod test { use super::*; |
