feat: add instance launch settings
This commit is contained in:
1 parent
59407ee01d
commit
8de0cbaa09
25 files changed
+2463
-482
No files matched your search
@@ -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,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user