From dd952bbfdba85cbb865f61928e67a4c5ba43db95 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Tue, 9 Apr 2024 16:17:40 -0400 Subject: [PATCH] feat: custom config path --- cosmic-config/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cosmic-config/src/lib.rs b/cosmic-config/src/lib.rs index e80f58c5..b0db5828 100644 --- a/cosmic-config/src/lib.rs +++ b/cosmic-config/src/lib.rs @@ -12,6 +12,7 @@ use std::{ #[cfg(feature = "subscription")] mod subscription; +#[cfg(feature = "subscription")] pub use subscription::*; #[cfg(all(feature = "dbus", feature = "subscription"))] @@ -170,6 +171,24 @@ impl Config { }) } + /// Get config for the given application name and config version and custom path. + pub fn with_custom_path(name: &str, version: u64, custom_path: PathBuf) -> Result { + // Look for [name]/v[version] + let path = sanitize_name(name)?.join(format!("v{version}")); + + let cosmic_user_path = custom_path.join("cosmic"); + + let user_path = cosmic_user_path.join(path); + // Create new configuration directory if not found. + fs::create_dir_all(&user_path)?; + + // Return Config + Ok(Self { + system_path: None, + user_path: Some(user_path), + }) + } + /// Get state for the given application name and config version. State is meant to be used to /// store items that may need to be exposed to other programs but will change regularly without /// user action