feat: add instance launch settings

This commit is contained in:
objz committed 2026-09-04 20:06:22 +02:00
1 parent 59407ee01d
commit 8de0cbaa09
25 files changed
+2463 -482

No files matched your search

@@ -244,7 +244,13 @@ fn instance() -> InstanceConfig {
memory_max: None,
memory_min: None,
jvm_args: Vec::new(),
environment: Default::default(),
window_mode: Default::default(),
resolution: None,
preferred_account: None,
pre_launch_command: Default::default(),
post_exit_command: Default::default(),
glfw_path: None,
config_sync_profile: None,
modpack_source: None,
}
+6
View File
@@ -49,7 +49,13 @@ fn job(name: &str) -> ReconcileJob {
memory_max: None,
memory_min: None,
jvm_args: Vec::new(),
environment: Default::default(),
window_mode: Default::default(),
resolution: None,
preferred_account: None,
pre_launch_command: Default::default(),
post_exit_command: Default::default(),
glfw_path: None,
config_sync_profile: None,
modpack_source: None,
},
+128
View File
@@ -112,6 +112,122 @@ fn custom_resolution_is_added_once() {
assert_eq!(args.iter().filter(|arg| *arg == "--height").count(), 1);
}
#[test]
fn fullscreen_is_added_once() {
let mut args = vec!["--username".to_owned(), "Player".to_owned()];
apply_window_mode(&mut args, WindowMode::Fullscreen);
apply_window_mode(&mut args, WindowMode::Fullscreen);
assert_eq!(
args.iter()
.filter(|argument| *argument == "--fullscreen")
.count(),
1
);
let mut windowed = vec![
"--username".to_owned(),
"Player".to_owned(),
"--fullscreen".to_owned(),
];
apply_window_mode(&mut windowed, WindowMode::Windowed);
assert_eq!(windowed, ["--username", "Player"]);
}
#[test]
fn preferred_account_falls_back_to_the_active_account() {
let accounts = vec![
crate::auth::Account {
uuid: "active".to_owned(),
username: "Active".to_owned(),
account_type: AccountType::Microsoft,
active: true,
refresh_token: None,
cached_mc_token: None,
cached_mc_token_expires_at: None,
},
crate::auth::Account {
uuid: "preferred".to_owned(),
username: "Preferred".to_owned(),
account_type: AccountType::Offline,
active: false,
refresh_token: None,
cached_mc_token: None,
cached_mc_token_expires_at: None,
},
];
assert_eq!(
select_launch_account(&accounts, Some("preferred")).map(|account| account.uuid.as_str()),
Some("preferred")
);
assert_eq!(
select_launch_account(&accounts, Some("removed")).map(|account| account.uuid.as_str()),
Some("active")
);
assert_eq!(
select_launch_account(&accounts, None).map(|account| account.uuid.as_str()),
Some("active")
);
}
#[cfg(unix)]
#[tokio::test]
async fn launch_commands_receive_instance_environment() {
use chrono::Utc;
let temp = tempfile::tempdir().unwrap();
let minecraft = temp.path().join("minecraft");
std::fs::create_dir_all(&minecraft).unwrap();
let mut config = InstanceConfig {
name: "Hook Test".to_owned(),
game_version: "1.21.1".to_owned(),
loader: ModLoader::Vanilla,
loader_version: None,
created: Utc::now(),
last_played: None,
java_path: None,
memory_max: None,
memory_min: None,
jvm_args: Vec::new(),
environment: Default::default(),
window_mode: Default::default(),
resolution: None,
preferred_account: None,
pre_launch_command: Default::default(),
post_exit_command: Default::default(),
glfw_path: None,
config_sync_profile: None,
modpack_source: None,
};
config
.environment
.insert("CUSTOM_VALUE".to_owned(), "available".to_owned());
let invocation = LaunchInvocation {
java: "/usr/bin/java".to_owned(),
jvm_args: vec!["-Xmx2G".to_owned()],
classpath: Vec::new(),
classpath_string: String::new(),
main_class: String::new(),
extra_args: Vec::new(),
game_args: Vec::new(),
environment: config.environment.clone(),
working_dir: minecraft.clone(),
};
let command = LaunchCommand {
enabled: true,
command: "printf '%s|%s' \"$CUSTOM_VALUE\" \"$INST_NAME\" > hook-result".to_owned(),
};
run_launch_command("Pre-launch", &command, &config, &invocation, temp.path())
.await
.unwrap();
assert_eq!(
std::fs::read_to_string(minecraft.join("hook-result")).unwrap(),
"available|Hook Test"
);
}
// exercises the early-return branch of migrate_legacy_meta_if_needed.
// a profile with either arguments or minecraftArguments is not legacy
// and must produce Ok(None) without touching the network. covers both
@@ -203,7 +319,13 @@ async fn migrate_legacy_loader_profile_skips_modern_with_inherits_from() {
memory_max: None,
memory_min: None,
jvm_args: Vec::new(),
environment: Default::default(),
window_mode: Default::default(),
resolution: None,
preferred_account: None,
pre_launch_command: Default::default(),
post_exit_command: Default::default(),
glfw_path: None,
config_sync_profile: None,
modpack_source: None,
};
@@ -252,7 +374,13 @@ async fn migrate_legacy_loader_profile_skips_fabric() {
memory_max: None,
memory_min: None,
jvm_args: Vec::new(),
environment: Default::default(),
window_mode: Default::default(),
resolution: None,
preferred_account: None,
pre_launch_command: Default::default(),
post_exit_command: Default::default(),
glfw_path: None,
config_sync_profile: None,
modpack_source: None,
};
+6
View File
@@ -27,7 +27,13 @@ fn dummy_config(name: &str) -> InstanceConfig {
memory_max: None,
memory_min: None,
jvm_args: vec![],
environment: Default::default(),
window_mode: Default::default(),
resolution: None,
preferred_account: None,
pre_launch_command: Default::default(),
post_exit_command: Default::default(),
glfw_path: None,
config_sync_profile: None,
modpack_source: None,
}
+12
View File
@@ -16,7 +16,13 @@ fn instance_config_roundtrips_through_json() {
memory_max: Some("4G".to_string()),
memory_min: Some("512M".to_string()),
jvm_args: vec![],
environment: Default::default(),
window_mode: Default::default(),
resolution: Some((1920, 1080)),
preferred_account: None,
pre_launch_command: Default::default(),
post_exit_command: Default::default(),
glfw_path: None,
config_sync_profile: None,
modpack_source: Some(crate::instance::ProviderProject {
provider: "modrinth".to_owned(),
@@ -47,6 +53,12 @@ fn instance_config_accepts_numeric_memory() {
let parsed: InstanceConfig = serde_json::from_str(json).expect("deserialize");
assert_eq!(parsed.memory_max.as_deref(), Some("8G"));
assert_eq!(parsed.memory_min.as_deref(), Some("512M"));
assert!(parsed.environment.is_empty());
assert_eq!(parsed.window_mode, WindowMode::Windowed);
assert_eq!(parsed.preferred_account, None);
assert_eq!(parsed.pre_launch_command, LaunchCommand::default());
assert_eq!(parsed.post_exit_command, LaunchCommand::default());
assert_eq!(parsed.glfw_path, None);
}
#[test]