From 59804dc8ab657a73c8bb62f752e0ffa7460e7bde Mon Sep 17 00:00:00 2001 From: Mohammad AlSaleh Date: Tue, 2 Jan 2024 18:23:44 +0300 Subject: [PATCH] Handle the case where configured font name is not available This can happen if configured font name is uninstalled for example. Pick the first font name available if that's the case. Signed-off-by: Mohammad AlSaleh --- src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.rs b/src/main.rs index d8a3d81..f7f8b3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -247,6 +247,14 @@ impl App { } fn set_curr_font_weights_and_stretches(&mut self) { + // check if config font_name is available first, if not, set it to first name in list + if !self.font_names.contains(&self.config.font_name) { + log::error!("'{}' is not in the font list", self.config.font_name); + log::error!("setting font name to '{}'", self.font_names[0]); + self.config.font_name = self.font_names[0].clone(); + let _ = self.save_config(); + } + let curr_font_faces = &self.font_name_faces_map[&self.config.font_name]; self.curr_font_stretches = curr_font_faces