Skip to main content

max / ripgrow

1005 B · 40 lines History Blame Raw
1 //! Optional TOML config at `<config_dir>/ripgrow/config.toml`.
2 //!
3 //! Currently holds only Supernote push settings. Missing file, missing
4 //! `[supernote]` table, and unparseable file all degrade to `Config::default()`
5 //! silently — Supernote is opt-in and its absence is not an error.
6
7 use std::path::PathBuf;
8
9 use serde::Deserialize;
10
11 #[derive(Default, Deserialize)]
12 pub struct Config {
13 #[serde(default)]
14 pub supernote: Option<Supernote>,
15 }
16
17 #[derive(Deserialize)]
18 pub struct Supernote {
19 pub host: String,
20 #[serde(default = "default_remote_dir")]
21 pub remote_dir: String,
22 #[serde(default)]
23 pub passcode: Option<String>,
24 }
25
26 fn default_remote_dir() -> String {
27 "Document/ripgrow".to_string()
28 }
29
30 pub fn path() -> Option<PathBuf> {
31 Some(dirs::config_dir()?.join("ripgrow").join("config.toml"))
32 }
33
34 pub fn load() -> Config {
35 path()
36 .and_then(|p| std::fs::read_to_string(p).ok())
37 .and_then(|s| toml::from_str(&s).ok())
38 .unwrap_or_default()
39 }
40