feat: add in-TUI settings editors
This commit is contained in:
1 parent
8c94e126c3
commit
c95f2d17ff
47 files changed
+2574
-741
No files matched your search
@@ -113,7 +113,7 @@ pub fn switch_profile(
|
||||
meta_dir: &Path,
|
||||
instance_dir: &Path,
|
||||
) -> Result<Option<String>, ConfigSyncError> {
|
||||
if crate::instance::runtime::get(instance_name).is_some() {
|
||||
if crate::instance::runtime::is_active(instance_name) {
|
||||
return Err(ConfigSyncError::InstanceRunning {
|
||||
instance: instance_name.to_string(),
|
||||
});
|
||||
|
||||
@@ -151,8 +151,11 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
|
||||
let paths = InstancePaths::new(instances_dir.join(&instance_name));
|
||||
let manifest_path = paths.content_manifest();
|
||||
let minecraft_dir = paths.minecraft();
|
||||
let retry_hours = crate::config::SETTINGS.content.unmatched_retry_hours;
|
||||
let max_fingerprint_size_mib = crate::config::SETTINGS.content.max_fingerprint_size_mib;
|
||||
let retry_hours = crate::config::SETTINGS.read().content.unmatched_retry_hours;
|
||||
let max_fingerprint_size_mib = crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.max_fingerprint_size_mib;
|
||||
let inventory_progress = task.handle();
|
||||
let inventory_minecraft_dir = minecraft_dir.clone();
|
||||
let inventory = tokio::task::spawn_blocking(move || {
|
||||
@@ -400,6 +403,7 @@ fn reconcile_inventory(
|
||||
}
|
||||
let provider_unchecked = ["modrinth", "curseforge"].into_iter().any(|provider| {
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.discovery_provider_enabled(provider)
|
||||
&& provider_was_not_checked(&record, provider)
|
||||
@@ -553,8 +557,16 @@ async fn resolve_queries(
|
||||
},
|
||||
Vec::new(),
|
||||
),
|
||||
_ if !crate::config::SETTINGS.content.ask_on_provider_conflict => {
|
||||
let preferred = crate::config::SETTINGS.content.preferred_provider();
|
||||
_ if !crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.ask_on_provider_conflict =>
|
||||
{
|
||||
let preferred = crate::config::SETTINGS
|
||||
.read()
|
||||
.content
|
||||
.preferred_provider()
|
||||
.to_owned();
|
||||
if let Some(project) = candidates
|
||||
.iter()
|
||||
.find(|project| project.provider == preferred)
|
||||
|
||||
@@ -59,6 +59,18 @@ fn build_game_args(
|
||||
Ok((rendered.jvm, rendered.game))
|
||||
}
|
||||
|
||||
fn apply_custom_resolution(game_args: &mut Vec<String>, resolution: Option<(u32, u32)>) {
|
||||
let Some((width, height)) = resolution else {
|
||||
return;
|
||||
};
|
||||
if !game_args.iter().any(|arg| arg == "--width") {
|
||||
game_args.extend(["--width".to_owned(), width.to_string()]);
|
||||
}
|
||||
if !game_args.iter().any(|arg| arg == "--height") {
|
||||
game_args.extend(["--height".to_owned(), height.to_string()]);
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_java_major_version(text: &str) -> Option<u32> {
|
||||
let quoted = text
|
||||
.split_once('"')
|
||||
@@ -384,6 +396,7 @@ pub async fn build_launch_invocation(
|
||||
|
||||
let current_features = FeatureSet {
|
||||
is_quick_play_singleplayer: quick_play_world.map(|_| true),
|
||||
has_custom_resolution: config.resolution.map(|_| true),
|
||||
..Default::default()
|
||||
};
|
||||
let host_os_version = system::mojang_os_version();
|
||||
@@ -539,6 +552,7 @@ pub async fn build_launch_invocation(
|
||||
.clone()
|
||||
.or_else(|| {
|
||||
crate::config::SETTINGS
|
||||
.read()
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
@@ -560,6 +574,8 @@ pub async fn build_launch_invocation(
|
||||
.join(&config.game_version)
|
||||
.join("natives");
|
||||
let version_type = merged_profile.type_.as_deref().unwrap_or("release");
|
||||
let resolution_width = config.resolution.map(|(width, _)| width.to_string());
|
||||
let resolution_height = config.resolution.map(|(_, height)| height.to_string());
|
||||
let template_ctx = TemplateContext {
|
||||
library_directory,
|
||||
classpath_separator: sep,
|
||||
@@ -580,15 +596,30 @@ pub async fn build_launch_invocation(
|
||||
launcher_version: env!("CARGO_PKG_VERSION"),
|
||||
clientid: "0",
|
||||
quick_play_singleplayer: quick_play_world,
|
||||
resolution_width: resolution_width.as_deref(),
|
||||
resolution_height: resolution_height.as_deref(),
|
||||
};
|
||||
|
||||
let (upstream_jvm_args, game_args) =
|
||||
let (upstream_jvm_args, mut game_args) =
|
||||
build_game_args(&merged_profile, &rule_ctx, &template_ctx)?;
|
||||
// Modern Mojang profiles include feature-gated resolution arguments.
|
||||
// Older and third-party profiles may not, so add them when absent.
|
||||
apply_custom_resolution(&mut game_args, config.resolution);
|
||||
|
||||
let mut jvm_args: Vec<String> = vec![
|
||||
format!("-Xms{}", config.memory_min.as_deref().unwrap_or("512M")),
|
||||
format!("-Xmx{}", config.memory_max.as_deref().unwrap_or("2G")),
|
||||
];
|
||||
let (memory_min, memory_max) = {
|
||||
let settings = crate::config::SETTINGS.read();
|
||||
(
|
||||
config
|
||||
.memory_min
|
||||
.clone()
|
||||
.unwrap_or_else(|| settings.defaults.memory_min.clone()),
|
||||
config
|
||||
.memory_max
|
||||
.clone()
|
||||
.unwrap_or_else(|| settings.defaults.memory_max.clone()),
|
||||
)
|
||||
};
|
||||
let mut jvm_args: Vec<String> = vec![format!("-Xms{memory_min}"), format!("-Xmx{memory_max}")];
|
||||
jvm_args.extend(patch_jvm_args);
|
||||
jvm_args.extend(upstream_jvm_args);
|
||||
jvm_args.extend(config.jvm_args.clone());
|
||||
|
||||
@@ -77,6 +77,7 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
} else {
|
||||
// modern forge: run the java installer
|
||||
let java_path = crate::config::SETTINGS
|
||||
.read()
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
|
||||
@@ -57,6 +57,7 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
neoforge_api::download_neoforge_installer(client, loader_version, &installer_jar).await?;
|
||||
|
||||
let java_path = crate::config::SETTINGS
|
||||
.read()
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
|
||||
@@ -56,6 +56,25 @@ pub struct InstanceConfig {
|
||||
pub modpack_source: Option<crate::instance::ProviderProject>,
|
||||
}
|
||||
|
||||
pub fn parse_resolution(input: &str) -> Result<(u32, u32), String> {
|
||||
let (width, height) = input
|
||||
.trim()
|
||||
.split_once(['x', 'X'])
|
||||
.ok_or_else(|| "resolution must be in WxH format".to_string())?;
|
||||
let width = width
|
||||
.parse::<u32>()
|
||||
.map_err(|_| "resolution width must be a positive integer".to_string())?;
|
||||
let height = height
|
||||
.parse::<u32>()
|
||||
.map_err(|_| "resolution height must be a positive integer".to_string())?;
|
||||
|
||||
if width == 0 || height == 0 {
|
||||
return Err("resolution values must be greater than zero".to_string());
|
||||
}
|
||||
|
||||
Ok((width, height))
|
||||
}
|
||||
|
||||
pub fn normalize_memory_value(raw: &str) -> Option<String> {
|
||||
let trimmed = raw.trim();
|
||||
if trimmed.is_empty() {
|
||||
|
||||
@@ -52,6 +52,14 @@ pub fn get(name: &str) -> Option<RunState> {
|
||||
RUNNING.lock().ok().and_then(|map| map.get(name).cloned())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_active(name: &str) -> bool {
|
||||
matches!(
|
||||
get(name),
|
||||
Some(RunState::Authenticating | RunState::Starting | RunState::Running)
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn all() -> Vec<(String, RunState)> {
|
||||
RUNNING
|
||||
|
||||
@@ -57,6 +57,8 @@ fn build_game_args_renders_upstream_arguments() {
|
||||
launcher_version: "test",
|
||||
clientid: "0",
|
||||
quick_play_singleplayer: None,
|
||||
resolution_width: None,
|
||||
resolution_height: None,
|
||||
version_type: "release",
|
||||
};
|
||||
let features = FeatureSet::default();
|
||||
@@ -89,6 +91,27 @@ fn build_game_args_renders_upstream_arguments() {
|
||||
assert_eq!(game_args, vec!["--username", "Player"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_resolution_is_added_once() {
|
||||
let mut args = vec!["--username".to_owned(), "Player".to_owned()];
|
||||
apply_custom_resolution(&mut args, Some((1920, 1080)));
|
||||
assert_eq!(
|
||||
args,
|
||||
[
|
||||
"--username",
|
||||
"Player",
|
||||
"--width",
|
||||
"1920",
|
||||
"--height",
|
||||
"1080"
|
||||
]
|
||||
);
|
||||
|
||||
apply_custom_resolution(&mut args, Some((1280, 720)));
|
||||
assert_eq!(args.iter().filter(|arg| *arg == "--width").count(), 1);
|
||||
assert_eq!(args.iter().filter(|arg| *arg == "--height").count(), 1);
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -84,3 +84,16 @@ fn normalize_memory_value_rejects_invalid_values() {
|
||||
assert_eq!(normalize_memory_value("8GB"), None);
|
||||
assert_eq!(normalize_memory_value("banana"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_resolution_accepts_common_separators() {
|
||||
assert_eq!(parse_resolution("1920x1080"), Ok((1920, 1080)));
|
||||
assert_eq!(parse_resolution(" 1280X720 "), Ok((1280, 720)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_resolution_rejects_invalid_values() {
|
||||
assert!(parse_resolution("1920").is_err());
|
||||
assert!(parse_resolution("0x1080").is_err());
|
||||
assert!(parse_resolution("wide x tall").is_err());
|
||||
}
|
||||
@@ -41,6 +41,14 @@ fn crashed_state_stores_exit_code() {
|
||||
assert_eq!(get("run_test_crash"), Some(RunState::Crashed(Some(1))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crashed_instances_are_not_active() {
|
||||
set_state("run_test_inactive_crash", RunState::Crashed(Some(1)));
|
||||
assert!(!is_active("run_test_inactive_crash"));
|
||||
set_state("run_test_active_start", RunState::Starting);
|
||||
assert!(is_active("run_test_active_start"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_and_drain_last_played() {
|
||||
let time = Utc::now();
|
||||
|
||||
Reference in new issue
Block a user