Skip to main content

rgx/config/
settings.rs

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