santui_core/
registry_config.rs1use serde::{Deserialize, Serialize};
2use std::path::{Path, PathBuf};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct InstalledPlugin {
7 pub enabled: bool,
8 pub version: String,
9 pub path: PathBuf,
10 #[serde(default)]
11 pub id: String,
12 #[serde(default)]
13 pub name: String,
14 #[serde(default)]
15 pub capabilities: Vec<String>,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct RegistryConfig {
21 pub plugins: Vec<InstalledPlugin>,
22}
23
24impl RegistryConfig {
25 pub fn load(path: &Path) -> Option<Self> {
26 let text = std::fs::read_to_string(path).ok()?;
27 toml::from_str(&text).ok()
28 }
29
30 pub fn save(&self, path: &Path) -> Result<(), String> {
31 let text = toml::to_string_pretty(self).map_err(|e| format!("TOML serialize: {e}"))?;
32 if let Some(parent) = path.parent() {
33 std::fs::create_dir_all(parent).map_err(|e| format!("Create config dir: {e}"))?;
34 }
35 std::fs::write(path, &text).map_err(|e| format!("Write config: {e}"))?;
36 Ok(())
37 }
38}