From fa4a2c53705c978c9c3410b4988f53d6db249b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 19 Oct 2020 23:33:56 +0200 Subject: mumd: add method to reload config --- mumd/src/state.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 5e1908c..e436d3d 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -30,7 +30,6 @@ pub struct State { connection_info_sender: watch::Sender>, phase_watcher: (watch::Sender, watch::Receiver), - } impl State { @@ -38,21 +37,17 @@ impl State { packet_sender: mpsc::UnboundedSender>, connection_info_sender: watch::Sender>, ) -> Self { - let config = mumlib::config::read_default_cfg(); let audio = Audio::new(); - if let Some(audio_config) = &config.audio { - if let Some(input_volume) = audio_config.input_volume { - audio.set_input_volume(input_volume); - } - } - Self { - config, + let mut state = Self { + config: mumlib::config::read_default_cfg().expect("format error in config file"), server: None, audio, packet_sender, connection_info_sender, phase_watcher: watch::channel(StatePhase::Disconnected), - } + }; + state.reload_config(); + state } //TODO? move bool inside Result @@ -208,6 +203,16 @@ impl State { self.server.as_mut().unwrap().parse_user_state(msg); } + pub fn reload_config(&mut self) { + self.config = mumlib::config::read_default_cfg() + .expect("format error in config file"); + if let Some(audio_config) = &self.config.audio { + if let Some(input_volume) = audio_config.input_volume { + self.audio.set_input_volume(input_volume); + } + } + } + pub fn initialized(&self) { self.phase_watcher .0 -- cgit v1.2.1