mirror of
https://github.com/chmln/handlr.git
synced 2024-11-23 09:41:45 +01:00
Fix handling of file:// paths
This commit is contained in:
parent
8e2b4b5b3b
commit
b4ebda37e0
2 changed files with 16 additions and 6 deletions
|
@ -2,7 +2,7 @@ use crate::{Error, Result};
|
|||
use mime::Mime;
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
path::{Path, PathBuf},
|
||||
path::{Path},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
|
@ -30,14 +30,14 @@ impl TryFrom<&str> for MimeType {
|
|||
fn try_from(arg: &str) -> Result<Self> {
|
||||
match url::Url::parse(arg) {
|
||||
Ok(url) if url.scheme() == "file" => {
|
||||
Self::try_from(&*PathBuf::from(url.path()))
|
||||
Self::try_from(Path::new(url.path()))
|
||||
}
|
||||
Ok(url) => Ok(Self(
|
||||
format!("x-scheme-handler/{}", url.scheme())
|
||||
.parse::<Mime>()
|
||||
.unwrap(),
|
||||
)),
|
||||
Err(_) => Self::try_from(&*PathBuf::from(arg)),
|
||||
Err(_) => Self::try_from(Path::new(arg)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -39,13 +39,23 @@ fn main() -> Result<()> {
|
|||
Cmd::Open { paths } => {
|
||||
let mut handlers: HashMap<Handler, Vec<String>> =
|
||||
HashMap::new();
|
||||
|
||||
for path in paths.into_iter() {
|
||||
let path = match url::Url::parse(&path) {
|
||||
Ok(url) if url.scheme() == "file" => {
|
||||
url.path().to_owned()
|
||||
}
|
||||
_ => path,
|
||||
};
|
||||
|
||||
let mime = MimeType::try_from(path.as_str())?.0;
|
||||
let handler = apps.get_handler(&mime)?;
|
||||
handlers.entry(handler).or_insert(Vec::new()).push(path);
|
||||
|
||||
handlers.entry(handler).or_default().push(path);
|
||||
}
|
||||
for (handler, handled_paths) in handlers.into_iter() {
|
||||
handler.open(handled_paths)?;
|
||||
|
||||
for (handler, paths) in handlers.into_iter() {
|
||||
handler.open(paths)?;
|
||||
}
|
||||
}
|
||||
Cmd::List { all } => {
|
||||
|
|
Loading…
Reference in a new issue