diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-10-21 00:57:37 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-10-21 00:57:37 +0200 |
| commit | 6a136ac842dd601ce7f68566c27b5262d221872c (patch) | |
| tree | a6f43da526bf84f96f79f96199f0bca33deb66f8 /mumd/src/state.rs | |
| parent | 2afb9bed4ef5a51b1d2b49728819d187b194829d (diff) | |
| download | mum-6a136ac842dd601ce7f68566c27b5262d221872c.tar.gz | |
default cfg is option
None if the file doesn't exist
Diffstat (limited to 'mumd/src/state.rs')
| -rw-r--r-- | mumd/src/state.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 08724dd..0dbf9c5 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -22,7 +22,7 @@ pub enum StatePhase { } pub struct State { - config: Config, + config: Option<Config>, server: Option<Server>, audio: Audio, @@ -39,7 +39,7 @@ impl State { ) -> Self { let audio = Audio::new(); let mut state = Self { - config: mumlib::config::read_default_cfg().expect("format error in config file"), + config: mumlib::config::read_default_cfg(), server: None, audio, packet_sender, @@ -208,12 +208,16 @@ impl State { } 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); + if let Some(config) = mumlib::config::read_default_cfg() { + self.config = Some(config); + let config = &self.config.as_ref().unwrap(); + if let Some(audio_config) = &config.audio { + if let Some(input_volume) = audio_config.input_volume { + self.audio.set_input_volume(input_volume); + } } + } else { + warn!("config file not found"); } } @@ -224,10 +228,6 @@ impl State { .unwrap(); } - pub fn config(&self) -> &Config { - &self.config - } - pub fn audio(&self) -> &Audio { &self.audio } |
