Skip to content

Commit

Permalink
fix(libscoop): updated Config struct
Browse files Browse the repository at this point in the history
Signed-off-by: Chawye Hsu <[email protected]>
  • Loading branch information
chawyehsu committed May 15, 2024
1 parent 2f58173 commit 17e474a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 10 additions & 4 deletions crates/libscoop/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)),
}
}
}
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 6 additions & 5 deletions crates/libscoop/src/internal/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 17e474a

Please sign in to comment.