synpad 0.1.0

A full-featured Matrix chat client built with Dioxus
use std::path::PathBuf;

/// Application configuration.
#[derive(Clone, Debug)]
pub struct ClientConfig {
    /// Default homeserver URL
    pub default_homeserver: String,
    /// Application data directory
    data_dir: PathBuf,
}

impl Default for ClientConfig {
    fn default() -> Self {
        let data_dir = dirs::data_local_dir()
            .unwrap_or_else(|| PathBuf::from("."))
            .join("synpad");

        Self {
            default_homeserver: "https://matrix.org".to_string(),
            data_dir,
        }
    }
}

impl ClientConfig {
    /// Get the application data directory, creating it if it doesn't exist.
    pub fn data_dir(&self) -> PathBuf {
        std::fs::create_dir_all(&self.data_dir).ok();
        self.data_dir.clone()
    }

    /// Get the cache directory.
    pub fn cache_dir(&self) -> PathBuf {
        let dir = self.data_dir.join("cache");
        std::fs::create_dir_all(&dir).ok();
        dir
    }

    /// Get the media cache directory.
    pub fn media_cache_dir(&self) -> PathBuf {
        let dir = self.cache_dir().join("media");
        std::fs::create_dir_all(&dir).ok();
        dir
    }

    /// Get the avatar cache directory.
    pub fn avatar_cache_dir(&self) -> PathBuf {
        let dir = self.cache_dir().join("avatars");
        std::fs::create_dir_all(&dir).ok();
        dir
    }
}