From c4f4f438d3066ec419ef8f8e1836431d754f8ea3 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 16 Nov 2021 22:27:43 +0100 Subject: [PATCH] fix(core): prevent blocking when spawning the textview UI --- espanso/src/gui/modulo/manager.rs | 19 ++----------------- espanso/src/gui/modulo/textview.rs | 4 ++-- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/espanso/src/gui/modulo/manager.rs b/espanso/src/gui/modulo/manager.rs index e371db9..9f7ed51 100644 --- a/espanso/src/gui/modulo/manager.rs +++ b/espanso/src/gui/modulo/manager.rs @@ -39,7 +39,7 @@ impl ModuloManager { Self { is_support_enabled } } - pub fn invoke_no_output(&self, args: &[&str], body: &str) -> Result<()> { + pub fn spawn(&self, args: &[&str], body: &str) -> Result<()> { if self.is_support_enabled { let exec_path = std::env::current_exe().expect("unable to obtain current exec path"); let mut command = Command::new(exec_path); @@ -59,19 +59,7 @@ impl ModuloManager { Ok(mut child) => { if let Some(stdin) = child.stdin.as_mut() { match stdin.write_all(body.as_bytes()) { - Ok(_) => { - // Get the output - match child.wait_with_output() { - Ok(child_output) => { - if child_output.status.success() { - Ok(()) - } else { - Err(ModuloError::NonZeroExit.into()) - } - } - Err(error) => Err(ModuloError::Error(error).into()), - } - } + Ok(_) => Ok(()), Err(error) => Err(ModuloError::Error(error).into()), } } else { @@ -147,9 +135,6 @@ pub enum ModuloError { )] MissingModulo, - #[error("modulo returned a non-zero exit code")] - NonZeroExit, - #[error("modulo returned an empty output")] EmptyOutput, diff --git a/espanso/src/gui/modulo/textview.rs b/espanso/src/gui/modulo/textview.rs index 66d0834..57c31ba 100644 --- a/espanso/src/gui/modulo/textview.rs +++ b/espanso/src/gui/modulo/textview.rs @@ -35,7 +35,7 @@ impl<'a> TextUI for ModuloTextUI<'a> { fn show_text(&self, title: &str, text: &str) -> anyhow::Result<()> { self .manager - .invoke_no_output(&["textview", "--title", title, "-i", "-"], text)?; + .spawn(&["textview", "--title", title, "-i", "-"], text)?; Ok(()) } @@ -44,7 +44,7 @@ impl<'a> TextUI for ModuloTextUI<'a> { let path_str = path.to_string_lossy().to_string(); self .manager - .invoke_no_output(&["textview", "--title", title, "-i", &path_str], "")?; + .spawn(&["textview", "--title", title, "-i", &path_str], "")?; Ok(()) }