You've already forked AstralRinth
forked from didirus/AstralRinth
Child process manager api (#64)
* child process api * added hook to js * process API + restructured process state storage * formatting * added path-pid check and fixed probs * prettier * added profile checking function --------- Co-authored-by: Wyatt <wyatt@modrinth.com>
This commit is contained in:
@@ -76,7 +76,7 @@ pub async fn profile_run(
|
||||
credentials: theseus::auth::Credentials,
|
||||
) -> Result<u32> {
|
||||
let proc_lock = profile::run(path, &credentials).await?;
|
||||
let pid = proc_lock.read().await.id().ok_or_else(|| {
|
||||
let pid = proc_lock.read().await.child.id().ok_or_else(|| {
|
||||
theseus::Error::from(theseus::ErrorKind::LauncherError(
|
||||
"Process failed to stay open.".to_string(),
|
||||
))
|
||||
@@ -93,31 +93,5 @@ pub async fn profile_run_wait(
|
||||
) -> Result<()> {
|
||||
let proc_lock = profile::run(path, &credentials).await?;
|
||||
let mut proc = proc_lock.write().await;
|
||||
Ok(profile::wait_for(&mut proc).await?)
|
||||
}
|
||||
|
||||
// Wait for a running minecraft process (a Child)
|
||||
// invoke('profile_wait_for', pid)
|
||||
#[tauri::command]
|
||||
pub async fn profile_wait_for(pid: u32) -> Result<()> {
|
||||
let st = State::get().await?;
|
||||
if let Some(proc_lock) = st.children.read().await.get(&pid) {
|
||||
let mut proc = proc_lock.write().await;
|
||||
return Ok(profile::wait_for(&mut proc).await?);
|
||||
}
|
||||
// If child is gone from state, it's not tracked or already finished
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Tries to kill a running minecraft process (if PID is still stored)
|
||||
// invoke('profile_kill', pid)
|
||||
#[tauri::command]
|
||||
pub async fn profile_kill(pid: u32) -> Result<()> {
|
||||
let st = State::get().await?;
|
||||
if let Some(proc_lock) = st.children.read().await.get(&pid) {
|
||||
let mut proc = proc_lock.write().await;
|
||||
return Ok(profile::kill(&mut proc).await?);
|
||||
}
|
||||
// If child is gone from state, it's not tracked or already finished
|
||||
Ok(())
|
||||
Ok(process::wait_for(&mut proc).await?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user