ipchat 0.0.0

Chat solution for local networks based on WLAN and Router's IP Addresses
Documentation
use std::path::PathBuf;

use anyhow::Result;
use tokio::fs::create_dir_all;
use tracing::info;

use crate::util::path::home_dir;

#[derive(Clone, Debug)]
pub struct Setup {
    home_dir: PathBuf,
}

impl Setup {
    pub async fn new() -> Result<Self> {
        let home_dir = Self::setup_home_dir().await?;
        Ok(Self { home_dir })
    }

    #[inline]
    pub const fn home_dir(&self) -> &PathBuf {
        &self.home_dir
    }

    async fn setup_home_dir() -> Result<PathBuf> {
        let home_dir = home_dir()?;

        if !home_dir.exists() {
            info!(?home_dir, "Creating IPChat Home Directory");
            create_dir_all(&home_dir).await?;
        } else {
            info!(?home_dir, "Home directory already exists");
        }

        Ok(home_dir)
    }
}