- Fix XDG config dir logic in config/mod.rs (was double-nesting and had /home/user hardcode) - Replace /home/user hardcodes in breadbar.rs and hyprland.rs with config::config_dir() - Fix /home/user hardcode in packages.rs (uses /root fallback for .local/state path) - Remove eprintln! from GTK callback in packages.rs (no stderr at runtime) - Fix YAML parse error in branding.desc (missing space after sidebarTextHighlight key) - Add .gitignore (Rust target/, ISO artifacts, editor/OS junk, secrets) - Delete state.rs (dead code — never mod'd in main.rs) - Add brightnessctl, grim, slurp to packages.x86_64 (used by keybinds) - Rename can-you-begin-a-composed-beacon.md → DESIGN.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
27 lines
866 B
Rust
27 lines
866 B
Rust
use std::error::Error;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
pub fn load<T: for<'de> serde::Deserialize<'de>>(path: &Path) -> Result<T, Box<dyn Error>> {
|
|
let text = std::fs::read_to_string(path)?;
|
|
Ok(toml::from_str(&text)?)
|
|
}
|
|
|
|
pub fn save<T: serde::Serialize>(path: &Path, val: &T) -> Result<(), Box<dyn Error>> {
|
|
if let Some(parent) = path.parent() {
|
|
std::fs::create_dir_all(parent)?;
|
|
}
|
|
std::fs::write(path, toml::to_string_pretty(val)?)?;
|
|
Ok(())
|
|
}
|
|
|
|
pub fn config_dir() -> PathBuf {
|
|
// Honour XDG_CONFIG_HOME if set; otherwise fall back to $HOME/.config.
|
|
if let Ok(xdg) = std::env::var("XDG_CONFIG_HOME") {
|
|
let p = PathBuf::from(xdg);
|
|
if p.is_absolute() {
|
|
return p;
|
|
}
|
|
}
|
|
let home = std::env::var("HOME").unwrap_or_else(|_| "/root".to_string());
|
|
PathBuf::from(home).join(".config")
|
|
}
|