httpman 0.1.5

A fast, modern HTTP client with tab management and request persistence
Documentation
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppSettings {
    pub active_tab_index: usize,
    pub tab_bar_width: f32,
}

impl Default for AppSettings {
    fn default() -> Self {
        Self {
            active_tab_index: 0,
            tab_bar_width: 200.0,
        }
    }
}

impl AppSettings {
    pub fn load_from_file<P: AsRef<Path>>(path: P) -> Self {
        match std::fs::read_to_string(path) {
            Ok(content) => serde_json::from_str(&content).unwrap_or_default(),
            Err(_) => Self::default(),
        }
    }

    pub fn save_to_file<P: AsRef<Path>>(&self, path: P) -> anyhow::Result<()> {
        let content = serde_json::to_string_pretty(self)?;
        std::fs::write(path, content)?;
        Ok(())
    }

    pub fn settings_path(base_path: &Path) -> PathBuf {
        base_path.join("settings.json")
    }
}