mirror of
https://github.com/chmln/handlr.git
synced 2024-11-14 21:49:27 +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 mime::Mime;
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
path::{Path, PathBuf},
|
path::{Path},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,14 +30,14 @@ impl TryFrom<&str> for MimeType {
|
||||||
fn try_from(arg: &str) -> Result<Self> {
|
fn try_from(arg: &str) -> Result<Self> {
|
||||||
match url::Url::parse(arg) {
|
match url::Url::parse(arg) {
|
||||||
Ok(url) if url.scheme() == "file" => {
|
Ok(url) if url.scheme() == "file" => {
|
||||||
Self::try_from(&*PathBuf::from(url.path()))
|
Self::try_from(Path::new(url.path()))
|
||||||
}
|
}
|
||||||
Ok(url) => Ok(Self(
|
Ok(url) => Ok(Self(
|
||||||
format!("x-scheme-handler/{}", url.scheme())
|
format!("x-scheme-handler/{}", url.scheme())
|
||||||
.parse::<Mime>()
|
.parse::<Mime>()
|
||||||
.unwrap(),
|
.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 } => {
|
Cmd::Open { paths } => {
|
||||||
let mut handlers: HashMap<Handler, Vec<String>> =
|
let mut handlers: HashMap<Handler, Vec<String>> =
|
||||||
HashMap::new();
|
HashMap::new();
|
||||||
|
|
||||||
for path in paths.into_iter() {
|
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 mime = MimeType::try_from(path.as_str())?.0;
|
||||||
let handler = apps.get_handler(&mime)?;
|
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 } => {
|
Cmd::List { all } => {
|
||||||
|
|
Loading…
Reference in a new issue