| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|