vcs-controller/src/config.rs

37 lines
913 B
Rust
Raw Normal View History

2024-03-25 16:28:13 -07:00
use config::{Config, FileFormat};
use std::fs::File;
use std::io::Write;
use crate::ui_code::AppState;
pub fn load_config() -> AppState {
let settings = Config::builder()
.add_source(config::File::new("./settings.toml", FileFormat::Toml))
.build();
if let Ok(val) = settings {
if let Ok(state) = val.try_deserialize() {
state
} else {
AppState::default()
}
} else {
AppState::default()
}
}
pub fn save_config(config: &AppState) {
println!("{}", {
if let Ok(toml_str) = toml::to_string(&config) {
if let Ok(mut file) = File::create("./settings.toml") {
file.write_all(toml_str.as_bytes()).unwrap();
""
} else {
"File could not be opened"
}
} else {
"Settings could not be deserialized"
}
});
}