You've already forked AstralRinth
forked from didirus/AstralRinth
String settings hooks (#82)
* added theme; env change * began refactoring * added process hook * now singular string for each hook * fixed splitting by comma to by space * profile_create function updated * prettier * added jre validator * restructured so that it doesnt look like a vec * fixed merge issue * snake case * resolved merge issues + added process events * clippy, fmt * removed unnecssary func
This commit is contained in:
@@ -33,7 +33,7 @@ pub async fn download_minecraft(
|
||||
LoadingBarType::MinecraftDownload {
|
||||
// If we are downloading minecraft for a profile, provide its name and uuid
|
||||
profile_name: profile.metadata.name.clone(),
|
||||
profile_uuid: profile.uuid,
|
||||
profile_uuid: profile.uuid,
|
||||
},
|
||||
100.0,
|
||||
"Downloading Minecraft...",
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
//! Logic for launching Minecraft
|
||||
use crate::{process, state as st};
|
||||
use crate::{
|
||||
process,
|
||||
state::{self as st, MinecraftChild},
|
||||
};
|
||||
use daedalus as d;
|
||||
use dunce::canonicalize;
|
||||
use st::Profile;
|
||||
use std::{path::Path, process::Stdio};
|
||||
use tokio::process::{Child, Command};
|
||||
use std::{path::Path, process::Stdio, sync::Arc};
|
||||
use tokio::process::Command;
|
||||
|
||||
mod args;
|
||||
|
||||
@@ -58,8 +61,9 @@ pub async fn launch_minecraft(
|
||||
memory: &st::MemorySettings,
|
||||
resolution: &st::WindowSize,
|
||||
credentials: &auth::Credentials,
|
||||
post_exit_hook: Option<Command>,
|
||||
profile: &Profile, // optional ref to Profile for event tracking
|
||||
) -> crate::Result<Child> {
|
||||
) -> crate::Result<Arc<tokio::sync::RwLock<MinecraftChild>>> {
|
||||
let state = st::State::get().await?;
|
||||
let instance_path = &canonicalize(instance_path)?;
|
||||
|
||||
@@ -182,10 +186,10 @@ pub async fn launch_minecraft(
|
||||
// Check if profile has a running profile, and reject running the command if it does
|
||||
// Done late so a quick double call doesn't launch two instances
|
||||
let existing_processes =
|
||||
process::get_pids_by_profile_path(instance_path).await?;
|
||||
if let Some(pid) = existing_processes.first() {
|
||||
process::get_uuids_by_profile_path(instance_path).await?;
|
||||
if let Some(uuid) = existing_processes.first() {
|
||||
return Err(crate::ErrorKind::LauncherError(format!(
|
||||
"Profile {} is already running at PID: {pid}",
|
||||
"Profile {} is already running at UUID: {uuid}",
|
||||
instance_path.display()
|
||||
))
|
||||
.as_error());
|
||||
@@ -233,12 +237,15 @@ pub async fn launch_minecraft(
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
|
||||
command.spawn().map_err(|err| {
|
||||
crate::ErrorKind::LauncherError(format!(
|
||||
"Error running Minecraft (minecraft-{} @ {}): {err}",
|
||||
&version.id,
|
||||
instance_path.display()
|
||||
))
|
||||
.as_error()
|
||||
})
|
||||
// Create Minecraft child by inserting it into the state
|
||||
// This also spawns the process and prepares the subsequent processes
|
||||
let mut state_children = state.children.write().await;
|
||||
state_children
|
||||
.insert_process(
|
||||
uuid::Uuid::new_v4(),
|
||||
instance_path.to_path_buf(),
|
||||
command,
|
||||
post_exit_hook,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user