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:
parent
d4de1dc9a1
commit
8a26011e76
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -8903,6 +8903,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_ini",
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
"sha1_smol",
|
||||
"sha2",
|
||||
"sqlx",
|
||||
|
||||
@ -25,9 +25,8 @@ const editProfileObject = computed(() => {
|
||||
hooks?: Hooks
|
||||
} = {}
|
||||
|
||||
if (overrideHooks.value) {
|
||||
editProfile.hooks = hooks.value
|
||||
}
|
||||
// When hooks are not overridden per-instance, we want to clear them
|
||||
editProfile.hooks = overrideHooks.value ? hooks.value : {}
|
||||
|
||||
return editProfile
|
||||
})
|
||||
|
||||
@ -9,6 +9,7 @@ bytes.workspace = true
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json.workspace = true
|
||||
serde_ini.workspace = true
|
||||
serde_with.workspace = true
|
||||
sha1_smol.workspace = true
|
||||
sha2.workspace = true
|
||||
url = { workspace = true, features = ["serde"] }
|
||||
|
||||
@ -644,7 +644,6 @@ pub async fn run(
|
||||
/// Run Minecraft using a profile, and credentials for authentication
|
||||
/// Returns Arc pointer to RwLock to Child
|
||||
#[tracing::instrument(skip(credentials))]
|
||||
|
||||
pub async fn run_credentials(
|
||||
path: &str,
|
||||
credentials: &Credentials,
|
||||
@ -662,7 +661,8 @@ pub async fn run_credentials(
|
||||
.hooks
|
||||
.pre_launch
|
||||
.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 {
|
||||
// TODO: hook parameters
|
||||
let mut cmd = hook.split(' ');
|
||||
@ -692,7 +692,12 @@ pub async fn run_credentials(
|
||||
.clone()
|
||||
.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 resolution =
|
||||
@ -704,8 +709,12 @@ pub async fn run_credentials(
|
||||
.unwrap_or(settings.custom_env_vars);
|
||||
|
||||
// Post post exit hooks
|
||||
let post_exit_hook =
|
||||
profile.hooks.post_exit.clone().or(settings.hooks.post_exit);
|
||||
let post_exit_hook = profile
|
||||
.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
|
||||
let mut mc_set_options: Vec<(String, String)> = vec![];
|
||||
|
||||
@ -353,9 +353,11 @@ pub async fn install_minecraft(
|
||||
}
|
||||
}
|
||||
|
||||
let cp = wrap_ref_builder!(cp = processor.classpath.clone() => {
|
||||
cp.push(processor.jar.clone())
|
||||
});
|
||||
let cp = {
|
||||
let mut cp = processor.classpath.clone();
|
||||
cp.push(processor.jar.clone());
|
||||
cp
|
||||
};
|
||||
|
||||
let child = Command::new(&java_version.path)
|
||||
.arg("-cp")
|
||||
@ -578,7 +580,9 @@ pub async fn launch_minecraft(
|
||||
let args = version_info.arguments.clone().unwrap_or_default();
|
||||
let mut command = match wrapper {
|
||||
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),
|
||||
};
|
||||
|
||||
@ -247,9 +247,13 @@ pub struct WindowSize(pub u16, pub u16);
|
||||
|
||||
/// Game initialization hooks
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[serde_with::serde_as]
|
||||
pub struct Hooks {
|
||||
#[serde_as(as = "serde_with::NoneAsEmptyString")]
|
||||
pub pre_launch: Option<String>,
|
||||
#[serde_as(as = "serde_with::NoneAsEmptyString")]
|
||||
pub wrapper: Option<String>,
|
||||
#[serde_as(as = "serde_with::NoneAsEmptyString")]
|
||||
pub post_exit: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
@ -4,15 +4,3 @@ pub mod io;
|
||||
pub mod jre;
|
||||
pub mod platform;
|
||||
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
|
||||
}};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user