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 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 { interface CommandEvents {

@ -13,7 +13,7 @@ use tauri::{
use crate::{ use crate::{
open::Program, open::Program,
process::{CommandEvent, TerminatedPayload}, process::{CommandEvent, ExitStatus, TerminatedPayload},
scope::ExecuteArgs, scope::ExecuteArgs,
Shell, Shell,
}; };
@ -302,6 +302,19 @@ pub fn kill<R: Runtime>(
Ok(()) 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] #[tauri::command]
pub async fn open<R: Runtime>( pub async fn open<R: Runtime>(
_window: Window<R>, _window: Window<R>,

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

@ -84,6 +84,14 @@ impl CommandChild {
pub fn pid(&self) -> u32 { pub fn pid(&self) -> u32 {
self.inner.id() 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. /// Describes the result of a process after it has terminated.

Loading…
Cancel
Save