aboutsummaryrefslogtreecommitdiffstats
path: root/mumd
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-10-19 23:33:56 +0200
committerGustav Sörnäs <gustav@sornas.net>2020-10-19 23:41:44 +0200
commitfa4a2c53705c978c9c3410b4988f53d6db249b06 (patch)
tree5db101d554af414370ab9ee003f9d256d8f4dfd3 /mumd
parentf5f14327f7038159541f9f569170268fd64a8fbb (diff)
downloadmum-fa4a2c53705c978c9c3410b4988f53d6db249b06.tar.gz
mumd: add method to reload config
Diffstat (limited to 'mumd')
-rw-r--r--mumd/src/state.rs25
1 files changed, 15 insertions, 10 deletions
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<Option<ConnectionInfo>>,
phase_watcher: (watch::Sender<StatePhase>, watch::Receiver<StatePhase>),
-
}
impl State {
@@ -38,21 +37,17 @@ impl State {
packet_sender: mpsc::UnboundedSender<ControlPacket<Serverbound>>,
connection_info_sender: watch::Sender<Option<ConnectionInfo>>,
) -> 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