From 20f319860908c2fa86bba25bb1e7bf8ba1a464e1 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 3 Feb 2019 16:44:39 +0000 Subject: Fix regression in the URL launcher config Due to the merging of configuration files on all platforms, it has been made impossible to completely disable URL launching without still executing some kind of program like `true`. Setting the launcher to `None` in the config, will now disable it completely. This fixes #2058. --- src/config/mod.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/config/mod.rs b/src/config/mod.rs index d9717704..c487ceb7 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -116,7 +116,7 @@ pub struct Mouse { #[derive(Clone, Debug, Deserialize, PartialEq, Eq)] pub struct Url { // Program for opening links - #[serde(deserialize_with = "failure_default")] + #[serde(deserialize_with = "deserialize_launcher")] pub launcher: Option, // Modifier used to open links @@ -124,6 +124,34 @@ pub struct Url { pub modifiers: ModifiersState, } +fn deserialize_launcher<'a, D>(deserializer: D) -> ::std::result::Result, D::Error> + where D: de::Deserializer<'a> +{ + let default = Url::default().launcher; + + // Deserialize to generic value + let val = match serde_yaml::Value::deserialize(deserializer) { + Ok(val) => val, + Err(err) => { + error!("Problem with config: {}; using {}", err, default.clone().unwrap().program()); + return Ok(default); + }, + }; + + // Accept `None` to disable the launcher + if val.as_str().filter(|v| v.to_lowercase() == "none").is_some() { + return Ok(None); + } + + match >::deserialize(val) { + Ok(launcher) => Ok(launcher), + Err(err) => { + error!("Problem with config: {}; using {}", err, default.clone().unwrap().program()); + Ok(default) + }, + } +} + impl Default for Url { fn default() -> Url { Url { -- cgit