Merge remote-tracking branch 'origin/master' into fix-memory-leak
Browse files
+15 −12 src/bin/main.rs
| @@ -86,18 +86,21 @@ fn load_config( | ||
| 86 | 86 | |
| 87 | 87 | let config_directory = config_path.parent(); |
| 88 | 88 | |
| 89 | - match oxwm::config::parse_lua_config(&config_string, config_directory) { | |
| 90 | - Ok(mut config) => { | |
| 91 | - config.path = Some(config_path); | |
| 92 | - Ok((config, false)) | |
| 93 | - } | |
| 94 | - Err(_error) => { | |
| 95 | - let template = include_str!("../../templates/config.lua"); | |
| 96 | - let config = oxwm::config::parse_lua_config(template, None) | |
| 97 | - .map_err(|error| format!("Failed to parse default template config: {}", error))?; | |
| 98 | - Ok((config, true)) | |
| 99 | - } | |
| 100 | - } | |
| 89 | + let (mut config, had_error) = | |
| 90 | + match oxwm::config::parse_lua_config(&config_string, config_directory) { | |
| 91 | + Ok(config) => (config, false), | |
| 92 | + Err(_error) => { | |
| 93 | + let template = include_str!("../../templates/config.lua"); | |
| 94 | + let config = oxwm::config::parse_lua_config(template, None).map_err(|error| { | |
| 95 | + format!("Failed to parse default template config: {}", error) | |
| 96 | + })?; | |
| 97 | + (config, true) | |
| 98 | + } | |
| 99 | + }; | |
| 100 | + | |
| 101 | + config.path = Some(config_path); | |
| 102 | + | |
| 103 | + Ok((config, had_error)) | |
| 101 | 104 | } |
| 102 | 105 | |
| 103 | 106 | fn init_config() -> Result<(), Box<dyn std::error::Error>> { |
+5 −3 src/window_manager.rs
| @@ -347,7 +347,7 @@ impl WindowManager { | ||
| 347 | 347 | |
| 348 | 348 | fn try_reload_config(&mut self) -> Result<(), String> { |
| 349 | 349 | let lua_path = |
| 350 | - self.config.path.take().ok_or( | |
| 350 | + self.config.path.as_ref().ok_or( | |
| 351 | 351 | "Could not find config file. Config path should've been set while loading", |
| 352 | 352 | )?; |
| 353 | 353 | |
| @@ -355,7 +355,7 @@ impl WindowManager { | ||
| 355 | 355 | return Err("Could not find config file, has it been moved?".to_string()); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - let config_str = std::fs::read_to_string(&lua_path) | |
| 358 | + let config_str = std::fs::read_to_string(lua_path) | |
| 359 | 359 | .map_err(|e| format!("Failed to read config: {}", e))?; |
| 360 | 360 | |
| 361 | 361 | let config_dir = lua_path.parent(); |
| @@ -363,8 +363,10 @@ impl WindowManager { | ||
| 363 | 363 | let new_config = crate::config::parse_lua_config(&config_str, config_dir) |
| 364 | 364 | .map_err(|e| format!("{}", e))?; |
| 365 | 365 | |
| 366 | + let lua_path = self.config.path.take(); | |
| 367 | + | |
| 366 | 368 | self.config = new_config; |
| 367 | - self.config.path = Some(lua_path); | |
| 369 | + self.config.path = lua_path; | |
| 368 | 370 | self.error_message = None; |
| 369 | 371 | |
| 370 | 372 | for bar in &mut self.bars { |