fix(app): make per-instance launch hooks clearable (#3757)

* fix(app): make per-instance launch hooks clearable

* chore(apps/app-frontend): fix Prettier lints
This commit is contained in:
Alejandro González
2025-06-13 22:53:47 +02:00
committed by GitHub
parent d4de1dc9a1
commit 8a26011e76
7 changed files with 30 additions and 24 deletions

1
Cargo.lock generated
View File

@@ -8903,6 +8903,7 @@ dependencies = [
"serde", "serde",
"serde_ini", "serde_ini",
"serde_json", "serde_json",
"serde_with",
"sha1_smol", "sha1_smol",
"sha2", "sha2",
"sqlx", "sqlx",

View File

@@ -25,9 +25,8 @@ const editProfileObject = computed(() => {
hooks?: Hooks hooks?: Hooks
} = {} } = {}
if (overrideHooks.value) { // When hooks are not overridden per-instance, we want to clear them
editProfile.hooks = hooks.value editProfile.hooks = overrideHooks.value ? hooks.value : {}
}
return editProfile return editProfile
}) })

View File

@@ -9,6 +9,7 @@ bytes.workspace = true
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true serde_json.workspace = true
serde_ini.workspace = true serde_ini.workspace = true
serde_with.workspace = true
sha1_smol.workspace = true sha1_smol.workspace = true
sha2.workspace = true sha2.workspace = true
url = { workspace = true, features = ["serde"] } url = { workspace = true, features = ["serde"] }

View File

@@ -644,7 +644,6 @@ pub async fn run(
/// Run Minecraft using a profile, and credentials for authentication /// Run Minecraft using a profile, and credentials for authentication
/// Returns Arc pointer to RwLock to Child /// Returns Arc pointer to RwLock to Child
#[tracing::instrument(skip(credentials))] #[tracing::instrument(skip(credentials))]
pub async fn run_credentials( pub async fn run_credentials(
path: &str, path: &str,
credentials: &Credentials, credentials: &Credentials,
@@ -662,7 +661,8 @@ pub async fn run_credentials(
.hooks .hooks
.pre_launch .pre_launch
.as_ref() .as_ref()
.or(settings.hooks.pre_launch.as_ref()); .or(settings.hooks.pre_launch.as_ref())
.filter(|hook_command| !hook_command.is_empty());
if let Some(hook) = pre_launch_hooks { if let Some(hook) = pre_launch_hooks {
// TODO: hook parameters // TODO: hook parameters
let mut cmd = hook.split(' '); let mut cmd = hook.split(' ');
@@ -692,7 +692,12 @@ pub async fn run_credentials(
.clone() .clone()
.unwrap_or(settings.extra_launch_args); .unwrap_or(settings.extra_launch_args);
let wrapper = profile.hooks.wrapper.clone().or(settings.hooks.wrapper); let wrapper = profile
.hooks
.wrapper
.clone()
.or(settings.hooks.wrapper)
.filter(|hook_command| !hook_command.is_empty());
let memory = profile.memory.unwrap_or(settings.memory); let memory = profile.memory.unwrap_or(settings.memory);
let resolution = let resolution =
@@ -704,8 +709,12 @@ pub async fn run_credentials(
.unwrap_or(settings.custom_env_vars); .unwrap_or(settings.custom_env_vars);
// Post post exit hooks // Post post exit hooks
let post_exit_hook = let post_exit_hook = profile
profile.hooks.post_exit.clone().or(settings.hooks.post_exit); .hooks
.post_exit
.clone()
.or(settings.hooks.post_exit)
.filter(|hook_command| !hook_command.is_empty());
// Any options.txt settings that we want set, add here // Any options.txt settings that we want set, add here
let mut mc_set_options: Vec<(String, String)> = vec![]; let mut mc_set_options: Vec<(String, String)> = vec![];

View File

@@ -353,9 +353,11 @@ pub async fn install_minecraft(
} }
} }
let cp = wrap_ref_builder!(cp = processor.classpath.clone() => { let cp = {
cp.push(processor.jar.clone()) let mut cp = processor.classpath.clone();
}); cp.push(processor.jar.clone());
cp
};
let child = Command::new(&java_version.path) let child = Command::new(&java_version.path)
.arg("-cp") .arg("-cp")
@@ -578,7 +580,9 @@ pub async fn launch_minecraft(
let args = version_info.arguments.clone().unwrap_or_default(); let args = version_info.arguments.clone().unwrap_or_default();
let mut command = match wrapper { let mut command = match wrapper {
Some(hook) => { Some(hook) => {
wrap_ref_builder!(it = Command::new(hook) => {it.arg(&java_version.path)}) let mut command = Command::new(hook);
command.arg(&java_version.path);
command
} }
None => Command::new(&java_version.path), None => Command::new(&java_version.path),
}; };

View File

@@ -247,9 +247,13 @@ pub struct WindowSize(pub u16, pub u16);
/// Game initialization hooks /// Game initialization hooks
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
#[serde_with::serde_as]
pub struct Hooks { pub struct Hooks {
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub pre_launch: Option<String>, pub pre_launch: Option<String>,
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub wrapper: Option<String>, pub wrapper: Option<String>,
#[serde_as(as = "serde_with::NoneAsEmptyString")]
pub post_exit: Option<String>, pub post_exit: Option<String>,
} }

View File

@@ -4,15 +4,3 @@ pub mod io;
pub mod jre; pub mod jre;
pub mod platform; pub mod platform;
pub mod server_ping; pub mod server_ping;
/// Wrap a builder which uses a mut reference into one which outputs an owned value
macro_rules! wrap_ref_builder {
($id:ident = $init:expr => $transform:block) => {{
let mut it = $init;
{
let $id = &mut it;
$transform;
}
it
}};
}