use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct AppConfig {
pub window_width: Option<f32>,
pub window_height: Option<f32>,
pub browse_path: Option<PathBuf>,
pub preview_backend: Option<String>,
}
impl AppConfig {
pub fn config_path() -> Option<PathBuf> {
dirs::config_dir().map(|d| d.join("photograph").join("config.toml"))
}
pub fn load() -> Self {
let Some(path) = Self::config_path() else {
return Self::default();
};
let Ok(contents) = std::fs::read_to_string(&path) else {
return Self::default();
};
toml::from_str(&contents).unwrap_or_default()
}
pub fn save(&self) {
let Some(path) = Self::config_path() else {
return;
};
if let Some(parent) = path.parent() {
let _ = std::fs::create_dir_all(parent);
}
if let Ok(s) = toml::to_string_pretty(self) {
let _ = std::fs::write(&path, s);
}
}
}