From 17e474a48a03f3c5281af203802a26f79e284e95 Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Wed, 15 May 2024 19:24:26 +0800 Subject: [PATCH] fix(libscoop): updated Config struct Signed-off-by: Chawye Hsu --- crates/libscoop/src/config.rs | 14 ++++++++++---- crates/libscoop/src/internal/env.rs | 11 ++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/libscoop/src/config.rs b/crates/libscoop/src/config.rs index 2842be2..c33d65a 100644 --- a/crates/libscoop/src/config.rs +++ b/crates/libscoop/src/config.rs @@ -208,7 +208,7 @@ pub enum IsolatedPath { Boolean(bool), /// string type of `use_isolated_path` indicating the environment variable name - Name(String), + Named(String), } impl FromStr for IsolatedPath { @@ -226,7 +226,7 @@ impl FromStr for IsolatedPath { match s.as_str() { "true" => Ok(IsolatedPath::Boolean(true)), "false" => Ok(IsolatedPath::Boolean(false)), - _ => Ok(IsolatedPath::Name(s)), + _ => Ok(IsolatedPath::Named(s)), } } } @@ -265,18 +265,24 @@ impl Config { self.no_junction.unwrap_or_default() } - /// Get the `proxy` setting. + /// Get the `proxy` config. #[inline] pub fn proxy(&self) -> Option<&str> { self.proxy.as_deref() } - /// Get the `cat_style` setting. + /// Get the `cat_style` config. #[inline] pub fn cat_style(&self) -> &str { self.cat_style.as_deref().unwrap_or_default() } + /// Get the `use_isoloated_path` config. + #[inline] + pub fn use_isolated_path(&self) -> Option<&IsolatedPath> { + self.use_isolated_path.as_ref() + } + /// Update config key with new value. pub(crate) fn set(&mut self, key: &str, value: &str) -> Fallible<()> { let is_unset = value.is_empty(); diff --git a/crates/libscoop/src/internal/env.rs b/crates/libscoop/src/internal/env.rs index 43e9907..7e2cfe4 100644 --- a/crates/libscoop/src/internal/env.rs +++ b/crates/libscoop/src/internal/env.rs @@ -40,11 +40,12 @@ mod windows { let path = Path::new("Environment"); let (env, _) = HKCU.create_subkey(path)?; - if value.is_none() { - // ignore error of deleting non-existent value - let _ = env.delete_value(key); - } else { - env.set_value(key, value.unwrap())?; + match value { + Some(value) => env.set_value(key, value)?, + None => { + // ignore error of deleting non-existent value + let _ = env.delete_value(key); + } } Ok(()) }