//! Optional TOML config at `/ripgrow/config.toml`. //! //! Currently holds only Supernote push settings. Missing file, missing //! `[supernote]` table, and unparseable file all degrade to `Config::default()` //! silently — Supernote is opt-in and its absence is not an error. use std::path::PathBuf; use serde::Deserialize; #[derive(Default, Deserialize)] pub struct Config { #[serde(default)] pub supernote: Option, } #[derive(Deserialize)] pub struct Supernote { pub host: String, #[serde(default = "default_remote_dir")] pub remote_dir: String, #[serde(default)] pub passcode: Option, } fn default_remote_dir() -> String { "Document/ripgrow".to_string() } pub fn path() -> Option { Some(dirs::config_dir()?.join("ripgrow").join("config.toml")) } pub fn load() -> Config { path() .and_then(|p| std::fs::read_to_string(p).ok()) .and_then(|s| toml::from_str(&s).ok()) .unwrap_or_default() }