pull/1947/merge
Ludea 8 months ago committed by GitHub
commit 6c4d2400b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -339,6 +339,20 @@ class Child {
pid: this.pid
})
}
/**
* Waits for the child to exit completely, returning the status that it exited with.
*
* @returns A promise with ExitStatus.
*
* @since 2.0.2
*/
async wait(): Promise<void> {
await invoke('plugin:shell|wait', {
cmd: 'waitChild',
pid: this.pid
})
}
}
interface CommandEvents {

@ -13,7 +13,7 @@ use tauri::{
use crate::{
open::Program,
process::{CommandEvent, TerminatedPayload},
process::{CommandEvent, ExitStatus, TerminatedPayload},
scope::ExecuteArgs,
Shell,
};
@ -302,6 +302,19 @@ pub fn kill<R: Runtime>(
Ok(())
}
#[tauri::command]
pub async fn wait<R: Runtime>(
_window: Window<R>,
shell: State<'_, Shell<R>>,
pid: ChildId,
) -> crate::Result<ExitStatus> {
if let Some(child) = shell.children.lock().unwrap().get(&pid) {
child.wait().await
} else {
Err(crate::Error::UnknowChildProcess)
}
}
#[tauri::command]
pub async fn open<R: Runtime>(
_window: Window<R>,

@ -33,6 +33,8 @@ pub enum Error {
/// Utf8 error.
#[error(transparent)]
Utf8(#[from] std::string::FromUtf8Error),
#[error("Child process does'nt exist")]
UnknowChildProcess,
}
impl Serialize for Error {

@ -84,6 +84,14 @@ impl CommandChild {
pub fn pid(&self) -> u32 {
self.inner.id()
}
/// Waits for the child to exit completely, returning the status that it exited with.
pub async fn wait(self) -> crate::Result<ExitStatus> {
let exitstatus = self.inner.wait()?;
Ok(ExitStatus {
code: exitstatus.code(),
})
}
}
/// Describes the result of a process after it has terminated.

Loading…
Cancel
Save