fix(core): prevent blocking when spawning the textview UI
This commit is contained in:
parent
8909ccdb4d
commit
c4f4f438d3
|
@ -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,
|
||||
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user