feat: custom config path
This commit is contained in:
parent
7d1b557112
commit
dd952bbfdb
1 changed files with 19 additions and 0 deletions
|
|
@ -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<Self, Error> {
|
||||
// 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue