aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
authorlukeflo2025-02-19 21:13:50 +0100
committerlukeflo2025-02-19 21:13:50 +0100
commitdc5ded8160177864963a31476c2a7afe8ca8e834 (patch)
treeabc0e3293b89fa24d3b9a7cbfe5dbc9d83d1d8b5 /src/app.rs
parent3bdd57994d94839aef04871bd0247f2b82b71d35 (diff)
downloadbibiman-dc5ded8160177864963a31476c2a7afe8ca8e834.tar.gz
bibiman-dc5ded8160177864963a31476c2a7afe8ca8e834.zip
resource opener in config
+ implement config field `pdf_opener` for setting app to open PDFs/Epubs + implement config field `url_opener` for setting app to open URLs/DOIs + function to select fallback if no field is provided in config
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs55
1 files changed, 36 insertions, 19 deletions
diff --git a/src/app.rs b/src/app.rs
index b49e883..e03f8d7 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -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::*;