fix(core): prevent blocking when spawning the textview UI

This commit is contained in:
Federico Terzi 2021-11-16 22:27:43 +01:00
parent 8909ccdb4d
commit c4f4f438d3
2 changed files with 4 additions and 19 deletions

View File

@ -39,7 +39,7 @@ impl ModuloManager {
Self { is_support_enabled } 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 { if self.is_support_enabled {
let exec_path = std::env::current_exe().expect("unable to obtain current exec path"); let exec_path = std::env::current_exe().expect("unable to obtain current exec path");
let mut command = Command::new(exec_path); let mut command = Command::new(exec_path);
@ -59,19 +59,7 @@ impl ModuloManager {
Ok(mut child) => { Ok(mut child) => {
if let Some(stdin) = child.stdin.as_mut() { if let Some(stdin) = child.stdin.as_mut() {
match stdin.write_all(body.as_bytes()) { match stdin.write_all(body.as_bytes()) {
Ok(_) => { Ok(_) => 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()),
}
}
Err(error) => Err(ModuloError::Error(error).into()), Err(error) => Err(ModuloError::Error(error).into()),
} }
} else { } else {
@ -147,9 +135,6 @@ pub enum ModuloError {
)] )]
MissingModulo, MissingModulo,
#[error("modulo returned a non-zero exit code")]
NonZeroExit,
#[error("modulo returned an empty output")] #[error("modulo returned an empty output")]
EmptyOutput, EmptyOutput,

View File

@ -35,7 +35,7 @@ impl<'a> TextUI for ModuloTextUI<'a> {
fn show_text(&self, title: &str, text: &str) -> anyhow::Result<()> { fn show_text(&self, title: &str, text: &str) -> anyhow::Result<()> {
self self
.manager .manager
.invoke_no_output(&["textview", "--title", title, "-i", "-"], text)?; .spawn(&["textview", "--title", title, "-i", "-"], text)?;
Ok(()) Ok(())
} }
@ -44,7 +44,7 @@ impl<'a> TextUI for ModuloTextUI<'a> {
let path_str = path.to_string_lossy().to_string(); let path_str = path.to_string_lossy().to_string();
self self
.manager .manager
.invoke_no_output(&["textview", "--title", title, "-i", &path_str], "")?; .spawn(&["textview", "--title", title, "-i", &path_str], "")?;
Ok(()) Ok(())
} }