From 46861ce465d6f1d86e80007742a850fd1cfa9bad Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 20:31:50 +0100 Subject: add mumd support for volume adjustment --- mumlib/src/command.rs | 2 ++ mumlib/src/error.rs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index e404056..d2d5d53 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -10,6 +10,8 @@ pub enum Command { ChannelList, ConfigReload, InputVolumeSet(f32), + OutputVolumeSet(f32), + UserVolumeSet(String, f32), ServerConnect { host: String, port: u16, diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index c6d9255..eaf517c 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -10,6 +10,7 @@ pub enum Error { AlreadyConnectedError, ChannelIdentifierError(String, ChannelIdentifierError), InvalidServerAddrError(String, u16), + InvalidUsernameError(String), } impl Display for Error { @@ -18,9 +19,8 @@ impl Display for Error { Error::DisconnectedError => write!(f, "Not connected to a server"), Error::AlreadyConnectedError => write!(f, "Already connected to a server"), Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id), - Error::InvalidServerAddrError(addr, port) => { - write!(f, "Invalid server address: {}: {}", addr, port) - } + Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}: {}", addr, port), + Error::InvalidUsernameError(username) => write!(f, "Invalid username: {}", username), } } } -- cgit v1.2.1 From 0cb39d13bba3dc5ffa3231e6021066e4191a43a4 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 21:47:47 +0100 Subject: refactor and add audio out config command --- mumlib/src/config.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'mumlib/src') 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, + pub audio: AudioConfig, pub servers: Option>, } @@ -44,9 +44,10 @@ impl Config { } } -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct AudioConfig { pub input_volume: Option, + pub output_volume: Option, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -113,7 +114,7 @@ impl TryFrom for Config { fn try_from(config: TOMLConfig) -> Result { Ok(Config { - audio: config.audio, + audio: config.audio.unwrap_or_default(), servers: config .servers .map(|servers| { @@ -130,7 +131,11 @@ impl TryFrom for Config { impl From 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 for TOMLConfig { } } -pub fn read_default_cfg() -> Option { - Some( - Config::try_from( - toml::from_str::(&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::(&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 } -- cgit v1.2.1 From 9d60f06ae05c5de08a026c7f9067c1a339bc24be Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 22:57:52 +0100 Subject: remove redundancy --- mumlib/src/config.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index a971b2d..210dc7b 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -14,7 +14,7 @@ struct TOMLConfig { #[derive(Clone, Debug, Default)] pub struct Config { pub audio: AudioConfig, - pub servers: Option>, + pub servers: Vec, } impl Config { @@ -123,7 +123,8 @@ impl TryFrom for Config { .map(|s| s.try_into::()) .collect() }) - .transpose()?, + .transpose()? + .unwrap_or(Vec::new()), }) } } @@ -136,12 +137,9 @@ impl From for TOMLConfig { } else { None }, - servers: config.servers.map(|servers| { - servers - .into_iter() - .map(|s| Value::try_from::(s).unwrap()) - .collect() - }), + servers: Some(config.servers.into_iter() + .map(|s| Value::try_from::(s).unwrap()) + .collect()), } } } -- cgit v1.2.1 From 36b5d69929d15212f5845f42d0239ba50e46a69c Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 23:01:08 +0100 Subject: cargo fmt --- mumlib/src/config.rs | 16 +++++++++++----- mumlib/src/error.rs | 4 +++- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index 210dc7b..2eca104 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -137,9 +137,13 @@ impl From for TOMLConfig { } else { None }, - servers: Some(config.servers.into_iter() - .map(|s| Value::try_from::(s).unwrap()) - .collect()), + servers: Some( + config + .servers + .into_iter() + .map(|s| Value::try_from::(s).unwrap()) + .collect(), + ), } } } @@ -149,6 +153,8 @@ pub fn read_default_cfg() -> Config { toml::from_str::(&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 + }) + .expect("invalid TOML in config file"), //TODO + ) + .expect("invalid config in TOML") //TODO } diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index eaf517c..1e79b9c 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -19,7 +19,9 @@ impl Display for Error { Error::DisconnectedError => write!(f, "Not connected to a server"), Error::AlreadyConnectedError => write!(f, "Already connected to a server"), Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id), - Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}: {}", addr, port), + Error::InvalidServerAddrError(addr, port) => { + write!(f, "Invalid server address: {}: {}", addr, port) + } Error::InvalidUsernameError(username) => write!(f, "Invalid username: {}", username), } } -- cgit v1.2.1