aboutsummaryrefslogtreecommitdiffstats
path: root/mumlib/src/config.rs
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2020-11-02 21:47:47 +0100
committerEskil Queseth <eskilq@kth.se>2020-11-02 21:47:47 +0100
commit0cb39d13bba3dc5ffa3231e6021066e4191a43a4 (patch)
tree5c4a14dac57fc84e688932783f02d6c06ff0515b /mumlib/src/config.rs
parent46861ce465d6f1d86e80007742a850fd1cfa9bad (diff)
downloadmum-0cb39d13bba3dc5ffa3231e6021066e4191a43a4.tar.gz
refactor and add audio out config command
Diffstat (limited to 'mumlib/src/config.rs')
-rw-r--r--mumlib/src/config.rs31
1 files changed, 16 insertions, 15 deletions
diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs
index e6b97fd..a971b2d 100644
--- a/mumlib/src/config.rs
+++ b/mumlib/src/config.rs
@@ -13,7 +13,7 @@ struct TOMLConfig {
#[derive(Clone, Debug, Default)]
pub struct Config {
- pub audio: Option<AudioConfig>,
+ pub audio: AudioConfig,
pub servers: Option<Vec<ServerConfig>>,
}
@@ -44,9 +44,10 @@ impl Config {
}
}
-#[derive(Clone, Debug, Deserialize, Serialize)]
+#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct AudioConfig {
pub input_volume: Option<f32>,
+ pub output_volume: Option<f32>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -113,7 +114,7 @@ impl TryFrom<TOMLConfig> for Config {
fn try_from(config: TOMLConfig) -> Result<Self, Self::Error> {
Ok(Config {
- audio: config.audio,
+ audio: config.audio.unwrap_or_default(),
servers: config
.servers
.map(|servers| {
@@ -130,7 +131,11 @@ impl TryFrom<TOMLConfig> for Config {
impl From<Config> for TOMLConfig {
fn from(config: Config) -> Self {
TOMLConfig {
- audio: config.audio,
+ audio: if config.audio.output_volume.is_some() || config.audio.input_volume.is_some() {
+ Some(config.audio)
+ } else {
+ None
+ },
servers: config.servers.map(|servers| {
servers
.into_iter()
@@ -141,15 +146,11 @@ impl From<Config> for TOMLConfig {
}
}
-pub fn read_default_cfg() -> Option<Config> {
- Some(
- Config::try_from(
- toml::from_str::<TOMLConfig>(&match fs::read_to_string(get_cfg_path()) {
- Ok(f) => f.to_string(),
- Err(_) => return None,
- })
- .expect("invalid TOML in config file"), //TODO
- )
- .expect("invalid config in TOML"),
- ) //TODO
+pub fn read_default_cfg() -> Config {
+ Config::try_from(
+ toml::from_str::<TOMLConfig>(&match fs::read_to_string(get_cfg_path()) {
+ Ok(f) => f,
+ Err(_) => return Config::default(),
+ }).expect("invalid TOML in config file"), //TODO
+ ).expect("invalid config in TOML") //TODO
}