1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Settings {
6 #[serde(default = "default_engine")]
7 pub default_engine: String,
8 #[serde(default)]
9 pub theme: ThemeSettings,
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize, Default)]
13pub struct ThemeSettings {
14 #[serde(default)]
15 pub catppuccin: bool,
16}
17
18fn default_engine() -> String {
19 "rust".to_string()
20}
21
22impl Default for Settings {
23 fn default() -> Self {
24 Self {
25 default_engine: default_engine(),
26 theme: ThemeSettings::default(),
27 }
28 }
29}
30
31impl Settings {
32 pub fn load() -> Self {
33 let path = config_path();
34 if let Some(path) = path {
35 if path.exists() {
36 if let Ok(content) = std::fs::read_to_string(&path) {
37 if let Ok(settings) = toml::from_str(&content) {
38 return settings;
39 }
40 }
41 }
42 }
43 Self::default()
44 }
45}
46
47fn config_path() -> Option<PathBuf> {
48 dirs::config_dir().map(|d| d.join("rgx").join("config.toml"))
49}