aboutsummaryrefslogtreecommitdiff
path: root/src/config/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/mod.rs')
-rw-r--r--src/config/mod.rs30
1 files changed, 29 insertions, 1 deletions
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<CommandWrapper>,
// 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<Option<CommandWrapper>, 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 <Option<CommandWrapper>>::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 {