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:
@@ -1,4 +1,5 @@
|
||||
//! Theseus profile management interface
|
||||
use crate::state::MinecraftChild;
|
||||
pub use crate::{
|
||||
state::{JavaSettings, Profile},
|
||||
State,
|
||||
@@ -9,10 +10,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
use tokio::{
|
||||
process::{Child, Command},
|
||||
sync::RwLock,
|
||||
};
|
||||
use tokio::{process::Command, sync::RwLock};
|
||||
|
||||
/// Add a profile to the in-memory state
|
||||
#[tracing::instrument]
|
||||
@@ -114,7 +112,7 @@ pub async fn list(
|
||||
pub async fn run(
|
||||
path: &Path,
|
||||
credentials: &crate::auth::Credentials,
|
||||
) -> crate::Result<Arc<RwLock<Child>>> {
|
||||
) -> crate::Result<Arc<RwLock<MinecraftChild>>> {
|
||||
let state = State::get().await.unwrap();
|
||||
let settings = state.settings.read().await;
|
||||
let profile = get(path).await?.ok_or_else(|| {
|
||||
@@ -227,31 +225,8 @@ pub async fn run(
|
||||
"Process failed to stay open.".to_string(),
|
||||
)
|
||||
})?;
|
||||
let child_arc = state_children.insert(pid, mc_process);
|
||||
let mchild_arc =
|
||||
state_children.insert_process(pid, path.to_path_buf(), mc_process);
|
||||
|
||||
Ok(child_arc)
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn kill(running: &mut Child) -> crate::Result<()> {
|
||||
running.kill().await?;
|
||||
wait_for(running).await
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn wait_for(running: &mut Child) -> crate::Result<()> {
|
||||
let result = running.wait().await.map_err(|err| {
|
||||
crate::ErrorKind::LauncherError(format!(
|
||||
"Error running minecraft: {err}"
|
||||
))
|
||||
})?;
|
||||
|
||||
match result.success() {
|
||||
false => Err(crate::ErrorKind::LauncherError(format!(
|
||||
"Minecraft exited with non-zero code {}",
|
||||
result.code().unwrap_or(-1)
|
||||
))
|
||||
.as_error()),
|
||||
true => Ok(()),
|
||||
}
|
||||
Ok(mchild_arc)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user