From 9603381da7810e1e6bed884d697951e9285e8baa Mon Sep 17 00:00:00 2001 From: Kirottu Date: Mon, 1 May 2023 16:13:05 +0300 Subject: [PATCH] Display config error in the main Anyrun window, if exists --- anyrun/src/main.rs | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/anyrun/src/main.rs b/anyrun/src/main.rs index 571b8ff..7b10acc 100644 --- a/anyrun/src/main.rs +++ b/anyrun/src/main.rs @@ -207,22 +207,26 @@ fn activate(app: >k::Application, runtime_data: Rc DEFAULT_CONFIG_DIR.to_string() }; - // Load config, if unable to then read default config - let config: Config = match fs::read_to_string(format!("{}/config.ron", config_dir)) { - Ok(content) => ron::from_str(&content).unwrap_or_else(|why| { - eprintln!( - "Failed to parse Anyrun config file, using default config: {}", - why - ); - Config::default() - }), - Err(why) => { - eprintln!( + // Load config, if unable to then read default config. If an error occurs the message will be displayed. + let (config, error_label) = match fs::read_to_string(format!("{}/config.ron", config_dir)) { + Ok(content) => ron::from_str(&content) + .map(|config| (config, None)) + .unwrap_or_else(|why| { + ( + Config::default(), + Some(format!( + "Failed to parse Anyrun config file, using default config: {}", + why + )), + ) + }), + Err(why) => ( + Config::default(), + Some(format!( "Failed to read Anyrun config file, using default config: {}", why - ); - Config::default() - } + )), + ), }; // Create the main window @@ -577,6 +581,16 @@ fn activate(app: >k::Application, runtime_data: Rc .build(); main_vbox.add(&entry); + // Display the error message + if let Some(error_label) = &error_label { + main_vbox.add( + >k::Label::builder() + .label(&format!(r#"{}"#, error_label)) + .use_markup(true) + .build(), + ); + } + let vertical_offset = match config.vertical_offset { RelativeNum::Absolute(offset) => offset, RelativeNum::Fraction(fraction) => (event.size().1 as f32 * fraction) as i32,