mirror of
https://github.com/chmln/handlr.git
synced 2024-11-14 21:49:27 +01:00
Cleanup
This commit is contained in:
parent
b6c6433aa3
commit
39965313d2
3 changed files with 52 additions and 34 deletions
43
Cargo.lock
generated
43
Cargo.lock
generated
|
@ -105,9 +105,9 @@ checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.61"
|
||||
version = "1.0.62"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d"
|
||||
checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
|
@ -172,9 +172,9 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
|
|||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.7.0"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
|
||||
checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
|
@ -182,9 +182,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.7.0"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
|
||||
checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
|
@ -285,6 +285,16 @@ version = "0.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00"
|
||||
dependencies = [
|
||||
"matches",
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "freedesktop_entry_parser"
|
||||
version = "1.1.0"
|
||||
|
@ -704,9 +714,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d"
|
||||
checksum = "1a1cda389c26d6b88f3d2dc38aa1b750fe87d298cc5d795ec9e975f402f00372"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"libc",
|
||||
|
@ -799,9 +809,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "2.3.2"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ac6fe3538f701e339953a3ebbe4f39941aababa8a3f6964635b24ab526daeac"
|
||||
checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
|
@ -1106,9 +1116,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "security-framework"
|
||||
version = "0.4.4"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535"
|
||||
checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"core-foundation",
|
||||
|
@ -1119,9 +1129,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "security-framework-sys"
|
||||
version = "0.4.3"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405"
|
||||
checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
|
@ -1452,10 +1462,11 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
|||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.1.1"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
|
||||
checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"matches",
|
||||
"percent-encoding",
|
||||
|
|
|
@ -73,9 +73,8 @@ impl DesktopEntry {
|
|||
// If the entry expects a terminal (emulator), but this process is not running in one, we
|
||||
// launch a new one.
|
||||
if self.term && !atty::is(atty::Stream::Stdout) {
|
||||
let terminal_emulator_args =
|
||||
shlex::split(&CONFIG.terminal_emulator).unwrap();
|
||||
split = terminal_emulator_args
|
||||
split = shlex::split(&CONFIG.terminal_emulator)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.chain(split.into_iter())
|
||||
.collect();
|
||||
|
|
|
@ -42,32 +42,37 @@ impl TryFrom<&str> for MimeType {
|
|||
}
|
||||
}
|
||||
|
||||
fn mime_to_option(mime: Mime) -> Option<Mime> {
|
||||
if mime == mime::APPLICATION_OCTET_STREAM {
|
||||
None
|
||||
} else {
|
||||
Some(mime)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&Path> for MimeType {
|
||||
type Error = Error;
|
||||
fn try_from(path: &Path) -> Result<Self> {
|
||||
use mime::APPLICATION_OCTET_STREAM as UNKNOWN;
|
||||
let db = xdg_mime::SharedMimeInfo::new();
|
||||
|
||||
let name_guess = || match path.file_name() {
|
||||
let name_guess = mime_to_option(match path.file_name() {
|
||||
Some(f) => db.get_mime_types_from_file_name(&f.to_string_lossy())
|
||||
[0]
|
||||
.clone(),
|
||||
None => UNKNOWN,
|
||||
};
|
||||
});
|
||||
|
||||
let content_guess = db.guess_mime_type().path(&path).guess();
|
||||
let content_guess = mime_to_option({
|
||||
let guess = db.guess_mime_type().path(&path).guess();
|
||||
guess.mime_type().clone()
|
||||
});
|
||||
|
||||
let mime = match (name_guess(), content_guess.mime_type().clone()) {
|
||||
(m1, m2) if m1 == UNKNOWN && m2 == UNKNOWN => {
|
||||
return Err(Error::Ambiguous(path.to_owned()))
|
||||
}
|
||||
(m1, m2) if m1 == UNKNOWN => m2,
|
||||
(m1, m2) if m2 == UNKNOWN => m1,
|
||||
(m1, m2) if m1 != m2 => m2,
|
||||
(m1, _) => m1,
|
||||
};
|
||||
|
||||
Ok(Self(mime.clone()))
|
||||
Ok(Self(
|
||||
name_guess
|
||||
.or(content_guess)
|
||||
.ok_or_else(|| Error::Ambiguous(path.to_owned()))?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +128,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn filename_priority() -> Result<()> {
|
||||
assert_eq!(MimeType::try_from("./tests/p.html")?.0, "text/html");
|
||||
assert_eq!(
|
||||
MimeType::try_from("./tests/p.html")?.0,
|
||||
"application/x-extension-html"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue