From 7b152bd2189ffd8e0ed46cdf9364437732ba0580 Mon Sep 17 00:00:00 2001 From: Mohammad AlSaleh Date: Mon, 1 Jan 2024 10:37:05 +0300 Subject: [PATCH] Check if a Config message was handled before creating first tab In `Application::subscription()`, `subscription::channel()` would create a dead terminal tab if it was called before `config_subscription()`. Then `subscription::channel()` would be triggered a second time creating a second terminal tab that works. This commit fixes this issue by only creating the first terminal tab after a `Message::Config{}` was handled, i.e. after `config_subscription()` was run. Signed-off-by: Mohammad AlSaleh --- src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4fc0322..a2d1d78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -184,6 +184,7 @@ pub struct App { context_page: ContextPage, term_event_tx_opt: Option>, term_config: TermConfig, + config_subscribed: bool, } impl App { @@ -384,6 +385,7 @@ impl Application for App { context_page: ContextPage::Settings, term_config: flags.term_config, term_event_tx_opt: None, + config_subscribed: false, }; let command = app.update_title(); @@ -405,6 +407,7 @@ impl Application for App { self.config = config; return self.update_config(); } + self.config_subscribed = true; } Message::Copy(entity_opt) => { let entity = entity_opt.unwrap_or_else(|| self.tab_model.active()); @@ -544,8 +547,9 @@ impl Application for App { _ => {} } } - Message::TabNew => match &self.term_event_tx_opt { - Some(term_event_tx) => match self.themes.get(self.config.syntax_theme()) { + Message::TabNew => match (self.config_subscribed, &self.term_event_tx_opt) { + (false, _) => log::info!("must wait for config subscription before creating first tab"), + (true, Some(term_event_tx)) => match self.themes.get(self.config.syntax_theme()) { Some(colors) => { let entity = self .tab_model @@ -572,7 +576,7 @@ impl Application for App { //TODO: fall back to known good theme } }, - None => { + (true, None) => { log::warn!("tried to create new tab before having event channel"); } },