Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ui/src/components/config-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const launcherConfigSchema: ZodType<LauncherConfig> = z.object({
javaPath: z.string(),
width: z.number(),
height: z.number(),
downloadThreads: z.number(),
downloadThreads: z.number().min(1).max(64),
customBackgroundPath: z.string().nullable(),
enableGpuAcceleration: z.boolean(),
enableVisualEffects: z.boolean(),
Expand Down
14 changes: 11 additions & 3 deletions src-tauri/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct LauncherConfig {
pub java_path: String,
pub width: u32,
pub height: u32,
pub download_threads: u32, // concurrent download threads (1-128)
pub download_threads: u32, // concurrent download threads (1-64)
pub custom_background_path: Option<String>,
pub enable_gpu_acceleration: bool,
pub enable_visual_effects: bool,
Expand All @@ -109,7 +109,7 @@ impl Default for LauncherConfig {
java_path: "java".to_string(),
width: 854,
height: 480,
download_threads: 32,
download_threads: 8,
custom_background_path: None,
enable_gpu_acceleration: false,
enable_visual_effects: true,
Expand All @@ -125,6 +125,12 @@ impl Default for LauncherConfig {
}
}

impl LauncherConfig {
pub fn sanitize(&mut self) {
self.download_threads = self.download_threads.clamp(1, 64);
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
}
}

pub struct ConfigState {
pub config: Mutex<LauncherConfig>,
pub file_path: PathBuf,
Expand All @@ -137,7 +143,9 @@ impl ConfigState {

let config = if config_path.exists() {
let content = fs::read_to_string(&config_path).unwrap_or_default();
serde_json::from_str(&content).unwrap_or_default()
let mut config: LauncherConfig = serde_json::from_str(&content).unwrap_or_default();
config.sanitize();
config
} else {
LauncherConfig::default()
};
Expand Down
8 changes: 6 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,11 +1646,15 @@ async fn save_raw_config(
content: String,
) -> Result<(), String> {
// Validate JSON
let new_config: core::config::LauncherConfig =
let mut new_config: core::config::LauncherConfig =
serde_json::from_str(&content).map_err(|e| format!("Invalid JSON: {}", e))?;
new_config.sanitize();

let normalized_content =
serde_json::to_string_pretty(&new_config).map_err(|e| format!("Invalid JSON: {}", e))?;
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated

// Save to file
tokio::fs::write(&state.file_path, &content)
tokio::fs::write(&state.file_path, &normalized_content)
.await
.map_err(|e| e.to_string())?;

Expand Down