From e1907114374c842654f86b234b816f57dbbc79d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 30 Mar 2021 11:21:38 +0200 Subject: add StateError and AudioError --- mumd/src/state.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'mumd/src/state.rs') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 20fe660..858441a 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -3,6 +3,7 @@ pub mod server; pub mod user; use crate::audio::{Audio, NotificationEvents}; +use crate::error::StateError; use crate::network::{ConnectionInfo, VoiceStreamType}; use crate::network::tcp::{TcpEvent, TcpEventData}; use crate::notify; @@ -62,14 +63,14 @@ pub struct State { } impl State { - pub fn new() -> Self { + pub fn new() -> Result { let config = mumlib::config::read_default_cfg(); let phase_watcher = watch::channel(StatePhase::Disconnected); let audio = Audio::new( config.audio.input_volume.unwrap_or(1.0), config.audio.output_volume.unwrap_or(1.0), phase_watcher.1.clone(), - ); + ).map_err(|e| StateError::AudioError(e))?; let mut state = Self { config, server: None, @@ -77,7 +78,7 @@ impl State { phase_watcher, }; state.reload_config(); - state + Ok(state) } pub fn handle_command( -- cgit v1.2.1 From d8c269f66a4a5a17155bec5e2cb5ad97f3ba00fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 30 Mar 2021 11:27:10 +0200 Subject: rename notify -> notifications Notify is already taken, see https://lib.rs/crates/notify. --- mumd/src/state.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'mumd/src/state.rs') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 858441a..9202e9f 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -6,7 +6,7 @@ use crate::audio::{Audio, NotificationEvents}; use crate::error::StateError; use crate::network::{ConnectionInfo, VoiceStreamType}; use crate::network::tcp::{TcpEvent, TcpEventData}; -use crate::notify; +use crate::notifications; use crate::state::server::Server; use log::*; @@ -463,7 +463,7 @@ impl State { == self.get_users_channel(self.server().unwrap().session_id().unwrap()) { if let Some(channel) = self.server().unwrap().channels().get(&channel_id) { - notify::send(format!( + notifications::send(format!( "{} connected and joined {}", &msg.get_name(), channel.name() @@ -516,7 +516,7 @@ impl State { self.get_users_channel(self.server().unwrap().session_id().unwrap()); if from_channel == this_channel || to_channel == this_channel { if let Some(channel) = self.server().unwrap().channels().get(&to_channel) { - notify::send(format!( + notifications::send(format!( "{} moved to channel {}", user.name(), channel.name() @@ -545,7 +545,7 @@ impl State { s += if deaf { " deafened" } else { " undeafened" }; } s += " themselves"; - notify::send(s); + notifications::send(s); } } } @@ -561,7 +561,7 @@ impl State { if this_channel == other_channel { self.audio.play_effect(NotificationEvents::UserDisconnected); if let Some(user) = self.server().unwrap().users().get(&msg.get_session()) { - notify::send(format!("{} disconnected", &user.name())); + notifications::send(format!("{} disconnected", &user.name())); } } -- cgit v1.2.1 From 950158eaadd8db9ef0eb48187e825524499422d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 30 Mar 2021 12:36:53 +0200 Subject: config error --- mumd/src/state.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'mumd/src/state.rs') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 9202e9f..b52b330 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -64,7 +64,7 @@ pub struct State { impl State { pub fn new() -> Result { - let config = mumlib::config::read_default_cfg(); + let config = mumlib::config::read_default_cfg()?; let phase_watcher = watch::channel(StatePhase::Disconnected); let audio = Audio::new( config.audio.input_volume.unwrap_or(1.0), @@ -574,7 +574,12 @@ impl State { } pub fn reload_config(&mut self) { - self.config = mumlib::config::read_default_cfg(); + match mumlib::config::read_default_cfg() { + Ok(config) => { + self.config = config; + } + Err(e) => error!("Couldn't read config: {}", e), + } if let Some(input_volume) = self.config.audio.input_volume { self.audio.set_input_volume(input_volume); } -- cgit v1.2.1