Merge pull request 'Better way to attain config & theme directories' (#14) from emma/breed:main into main
Reviewed-on: #14
This commit is contained in:
commit
8b90eb647a
|
@ -46,11 +46,29 @@ impl Default for Config {
|
|||
|
||||
/// Gets the configuration directory. Panics if unavailable.
|
||||
pub fn get_config_dir() -> PathBuf {
|
||||
std::env::var_os("HOME")
|
||||
.map(PathBuf::try_from)
|
||||
.expect("$HOME is unset")
|
||||
.unwrap()
|
||||
.join(".config/breed")
|
||||
std::env::var_os("XDG_CONFIG_HOME")
|
||||
.map(|p| PathBuf::try_from(p).expect("$XDG_CONFIG_HOME is not a valid path."))
|
||||
.unwrap_or_else(|| {
|
||||
std::env::var_os("HOME")
|
||||
.map(PathBuf::try_from)
|
||||
.expect("$HOME is not a valid path.")
|
||||
.expect("User has no $HOME or $XDG_CONFIG_HOME.")
|
||||
.join(".config")
|
||||
})
|
||||
.join("breed")
|
||||
}
|
||||
|
||||
pub fn get_data_dir() -> PathBuf {
|
||||
std::env::var_os("XDG_DATA_HOME")
|
||||
.map(|p| PathBuf::try_from(p).expect("$XDG_DATA_HOME is not a valid path."))
|
||||
.unwrap_or_else(|| {
|
||||
std::env::var_os("HOME")
|
||||
.map(PathBuf::try_from)
|
||||
.expect("$HOME is not a valid path.")
|
||||
.expect("User has no $HOME or $XDG_DATA_HOME.")
|
||||
.join(".local/share")
|
||||
})
|
||||
.join("breed")
|
||||
}
|
||||
|
||||
/// Watches a theme file and automatically reloads it into a [StyleStore].
|
||||
|
@ -65,7 +83,7 @@ pub struct ThemeWatcher {
|
|||
|
||||
impl ThemeWatcher {
|
||||
pub fn spawn(styles: Arc<Mutex<StyleStore>>) -> Sender<PathBuf> {
|
||||
let themes_dir = get_config_dir().join("themes");
|
||||
let themes_dir = get_data_dir().join("themes");
|
||||
let default_path = themes_dir.join("default.toml");
|
||||
let (fs_tx, fs_rx) = unbounded();
|
||||
let (command_tx, command_rx) = unbounded();
|
||||
|
|
Loading…
Reference in New Issue