use std::path::PathBuf;
use homedir::unix::my_home;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct BularJson {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub token: Option<String>,
}
impl BularJson {
pub fn path() -> PathBuf {
let config_dir = my_home()
.unwrap()
.expect("Failed to determine home directory!")
.join(".config");
if !config_dir.exists() {
std::fs::create_dir_all(&config_dir).unwrap();
}
config_dir.join("bular.json")
}
pub fn load() -> Option<Self> {
let path = Self::path();
if !path.exists() {
return None;
}
Some(serde_json::from_str(&std::fs::read_to_string(Self::path()).unwrap()).unwrap())
}
pub fn save(&self) {
std::fs::write(Self::path(), serde_json::to_string_pretty(&self).unwrap()).unwrap();
}
}