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 }
|
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,
|
||||||
|
|
||||||
|
|
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user