gst-wpe-webrtc-demo/src/utils.rs
Philippe Normand e5a3621705 Initial checkin
2020-07-01 19:21:13 +01:00

28 lines
728 B
Rust

use std::path::PathBuf;
use crate::settings::Settings;
use crate::APPLICATION_NAME;
// Get the default path for the settings file
pub fn get_settings_file_path() -> PathBuf {
let mut path = glib::get_user_config_dir().unwrap_or_else(|| PathBuf::from("."));
path.push(APPLICATION_NAME);
path.push("settings.toml");
path
}
// Load the current settings
pub fn load_settings() -> Settings {
let s = get_settings_file_path();
if s.exists() && s.is_file() {
match serde_any::from_file::<Settings, _>(&s) {
Ok(s) => s,
Err(e) => {
panic!("Error while opening '{}': {}", s.display(), e);
}
}
} else {
Settings::default()
}
}