use serde::Deserialize;
use std::collections::HashMap;
use std::path::Path;
#[derive(Debug, Clone, Deserialize)]
pub struct SettingsHelpEntry {
pub title: String,
pub description: String,
}
#[derive(Debug, Clone, Default)]
pub struct SettingsHelpStore {
entries: HashMap<String, SettingsHelpEntry>,
}
impl SettingsHelpStore {
pub fn load_embedded() -> Self {
let mut store = Self::default();
let content = include_str!("../../assets/metadata/settings_help.toml");
if let Ok(entries) = toml::from_str::<HashMap<String, SettingsHelpEntry>>(content) {
store.entries = entries;
}
store
}
pub fn load_user_overrides(&mut self, path: &Path) {
if !path.exists() {
return;
}
if let Ok(content) = std::fs::read_to_string(path) {
if let Ok(entries) = toml::from_str::<HashMap<String, SettingsHelpEntry>>(&content) {
for (key, value) in entries {
self.entries.insert(key, value);
}
}
}
}
#[allow(dead_code)]
pub fn get(&self, key: &str) -> Option<&SettingsHelpEntry> {
self.entries.get(key)
}
pub fn get_or_default(&self, key: &str) -> (&str, &str) {
self.entries
.get(key)
.map(|e| (e.title.as_str(), e.description.as_str()))
.or_else(|| {
self.entries
.get("default")
.map(|e| (e.title.as_str(), e.description.as_str()))
})
.unwrap_or(("Settings", "Select a setting to see its description."))
}
}