From 723738e5308b0195ad715e0fa49f19db754753c6 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sun, 18 Jan 2026 12:13:49 +0800 Subject: fix(auth): prevent infinite recursion in get_client() The fallback in the reqwest client builder was calling get_client() recursively, which would cause a stack overflow if Client::builder() failed. Now uses reqwest::Client::new() as the fallback. Also fixed User-Agent to be platform-agnostic. Reviewed-by: Claude Opus 4.5 --- src-tauri/src/core/auth.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src-tauri/src/core') diff --git a/src-tauri/src/core/auth.rs b/src-tauri/src/core/auth.rs index ac5904c..e1e1588 100644 --- a/src-tauri/src/core/auth.rs +++ b/src-tauri/src/core/auth.rs @@ -6,9 +6,9 @@ use uuid::Uuid; // This is critical because Microsoft's WAF often blocks requests without a valid UA fn get_client() -> reqwest::Client { reqwest::Client::builder() - .user_agent("DropOut/1.0 (Linux)") + .user_agent("DropOut/1.0") .build() - .unwrap_or_else(|_| get_client()) + .unwrap_or_else(|_| reqwest::Client::new()) } #[derive(Debug, Clone, Serialize, Deserialize)] -- cgit v1.2.3-70-g09d2 From 079ee0a6611499db68d1eb4894fab64739d5d2e7 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sun, 18 Jan 2026 12:16:05 +0800 Subject: fix(instance): copy directory BEFORE creating metadata in duplicate_instance Prevent race condition in duplicate_instance by copying the source game directory BEFORE creating and saving the new instance metadata. This ensures that if the copy fails, no orphaned metadata is created. Also copy the icon_path from source instance to maintain visual consistency. --- src-tauri/src/core/instance.rs | 43 +++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'src-tauri/src/core') diff --git a/src-tauri/src/core/instance.rs b/src-tauri/src/core/instance.rs index 90ec34e..738dbd8 100644 --- a/src-tauri/src/core/instance.rs +++ b/src-tauri/src/core/instance.rs @@ -218,21 +218,42 @@ impl InstanceState { .get_instance(id) .ok_or_else(|| format!("Instance {} not found", id))?; - // Create new instance - let mut new_instance = self.create_instance(new_name, app_handle)?; - - // Copy instance properties - new_instance.version_id = source_instance.version_id.clone(); - new_instance.mod_loader = source_instance.mod_loader.clone(); - new_instance.mod_loader_version = source_instance.mod_loader_version.clone(); - new_instance.notes = source_instance.notes.clone(); - - // Copy directory contents + // Prepare new instance metadata (but don't save yet) + let new_id = uuid::Uuid::new_v4().to_string(); + let instances_dir = app_handle + .path() + .app_data_dir() + .map_err(|e| e.to_string())? + .join("instances"); + let new_game_dir = instances_dir.join(&new_id); + + // Copy directory FIRST - if this fails, don't create metadata if source_instance.game_dir.exists() { - copy_dir_all(&source_instance.game_dir, &new_instance.game_dir) + copy_dir_all(&source_instance.game_dir, &new_game_dir) .map_err(|e| format!("Failed to copy instance directory: {}", e))?; + } else { + // If source dir doesn't exist, create new empty game dir + std::fs::create_dir_all(&new_game_dir) + .map_err(|e| format!("Failed to create instance directory: {}", e))?; } + // NOW create metadata and save + let new_instance = Instance { + id: new_id, + name: new_name, + game_dir: new_game_dir, + version_id: source_instance.version_id.clone(), + mod_loader: source_instance.mod_loader.clone(), + mod_loader_version: source_instance.mod_loader_version.clone(), + notes: source_instance.notes.clone(), + icon_path: source_instance.icon_path.clone(), + created_at: std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_secs() as i64, + last_played: None, + }; + self.update_instance(new_instance.clone())?; Ok(new_instance) -- cgit v1.2.3-70-g09d2 From 1021c921c5690ceb800c03140de0723f3338e121 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sun, 18 Jan 2026 12:16:55 +0800 Subject: fix(auth): add token expiry check in start_game Check if the Microsoft account token is expired before attempting to launch the game. If expired, attempt to refresh using the refresh_token. If refresh fails, return an error instructing the user to login again. Also removed #[allow(dead_code)] from is_token_expired since it's now actively used. --- src-tauri/src/core/auth.rs | 1 - src-tauri/src/main.rs | 31 ++++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src-tauri/src/core') diff --git a/src-tauri/src/core/auth.rs b/src-tauri/src/core/auth.rs index e1e1588..d5e6c17 100644 --- a/src-tauri/src/core/auth.rs +++ b/src-tauri/src/core/auth.rs @@ -136,7 +136,6 @@ pub async fn refresh_microsoft_token(refresh_token: &str) -> Result bool { let now = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 4086066..853c93e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -82,13 +82,42 @@ async fn start_game( // Check for active account emit_log!(window, "Checking for active account...".to_string()); - let account = auth_state + let mut account = auth_state .active_account .lock() .unwrap() .clone() .ok_or("No active account found. Please login first.")?; + // Check if Microsoft account token is expired and refresh if needed + if let core::auth::Account::Microsoft(ms_account) = &account { + if core::auth::is_token_expired(ms_account.expires_at) { + emit_log!(window, "Token expired, refreshing...".to_string()); + match core::auth::refresh_full_auth( + &ms_account + .refresh_token + .clone() + .ok_or("No refresh token available")?, + ) + .await + { + Ok((refreshed_account, _new_ms_refresh)) => { + let refreshed_account = core::auth::Account::Microsoft(refreshed_account); + *auth_state.active_account.lock().unwrap() = Some(refreshed_account.clone()); + account = refreshed_account; + emit_log!(window, "Token refreshed successfully".to_string()); + } + Err(e) => { + emit_log!(window, format!("Token refresh failed: {}", e)); + return Err(format!( + "Your login session has expired. Please login again: {}", + e + )); + } + } + } + } + emit_log!(window, format!("Account found: {}", account.username())); let config = config_state.config.lock().unwrap().clone(); -- cgit v1.2.3-70-g09d2 From e7d683d79bec482a13c821f8c1da3c8c1d719d1b Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sun, 18 Jan 2026 12:17:56 +0800 Subject: fix(downloader): use proper atomic ordering for thread-safe progress tracking Replace Ordering::Relaxed with appropriate synchronization: - Ordering::AcqRel for fetch_add operations that modify shared state - Ordering::Acquire for loads that depend on other thread's writes - Ordering::Release for stores that other threads may read This ensures visibility of downloaded bytes and completed files across concurrent download tasks without data races. --- src-tauri/src/core/downloader.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src-tauri/src/core') diff --git a/src-tauri/src/core/downloader.rs b/src-tauri/src/core/downloader.rs index 9c6b7f0..26f6ebd 100644 --- a/src-tauri/src/core/downloader.rs +++ b/src-tauri/src/core/downloader.rs @@ -270,12 +270,12 @@ pub async fn download_with_resume( } current_pos += chunk_len; - let total_downloaded = progress.fetch_add(chunk_len, Ordering::Relaxed) + chunk_len; + let total_downloaded = progress.fetch_add(chunk_len, Ordering::AcqRel) + chunk_len; // Emit progress event (throttled) - let last_bytes = last_progress_bytes.load(Ordering::Relaxed); + let last_bytes = last_progress_bytes.load(Ordering::Acquire); if total_downloaded - last_bytes > 100 * 1024 || total_downloaded >= total_size { - last_progress_bytes.store(total_downloaded, Ordering::Relaxed); + last_progress_bytes.store(total_downloaded, Ordering::Release); let elapsed = start_time.elapsed().as_secs_f64(); let speed = if elapsed > 0.0 { @@ -319,7 +319,7 @@ pub async fn download_with_resume( all_success = false; if e.contains("cancelled") { // Save progress for resume - metadata.downloaded_bytes = progress.load(Ordering::Relaxed); + metadata.downloaded_bytes = progress.load(Ordering::Acquire); let meta_content = serde_json::to_string_pretty(&metadata).map_err(|e| e.to_string())?; tokio::fs::write(&meta_path, meta_content).await.ok(); @@ -335,7 +335,7 @@ pub async fn download_with_resume( if !all_success { // Save progress - metadata.downloaded_bytes = progress.load(Ordering::Relaxed); + metadata.downloaded_bytes = progress.load(Ordering::Acquire); let meta_content = serde_json::to_string_pretty(&metadata).map_err(|e| e.to_string())?; tokio::fs::write(&meta_path, meta_content).await.ok(); return Err("Some segments failed".to_string()); @@ -482,19 +482,19 @@ impl GlobalProgress { /// Get current progress snapshot without modification fn snapshot(&self) -> ProgressSnapshot { ProgressSnapshot { - completed_files: self.completed_files.load(Ordering::Relaxed), + completed_files: self.completed_files.load(Ordering::Acquire), total_files: self.total_files, - total_downloaded_bytes: self.total_downloaded_bytes.load(Ordering::Relaxed), + total_downloaded_bytes: self.total_downloaded_bytes.load(Ordering::Acquire), } } /// Increment completed files counter and return updated snapshot fn inc_completed(&self) -> ProgressSnapshot { - let completed = self.completed_files.fetch_add(1, Ordering::Relaxed) + 1; + let completed = self.completed_files.fetch_add(1, Ordering::Release) + 1; ProgressSnapshot { completed_files: completed, total_files: self.total_files, - total_downloaded_bytes: self.total_downloaded_bytes.load(Ordering::Relaxed), + total_downloaded_bytes: self.total_downloaded_bytes.load(Ordering::Acquire), } } @@ -502,10 +502,10 @@ impl GlobalProgress { fn add_bytes(&self, delta: u64) -> ProgressSnapshot { let total_bytes = self .total_downloaded_bytes - .fetch_add(delta, Ordering::Relaxed) + .fetch_add(delta, Ordering::AcqRel) + delta; ProgressSnapshot { - completed_files: self.completed_files.load(Ordering::Relaxed), + completed_files: self.completed_files.load(Ordering::Acquire), total_files: self.total_files, total_downloaded_bytes: total_bytes, } -- cgit v1.2.3-70-g09d2 From af7f8aec576b34d11bf136a75542822a74d7f335 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sun, 18 Jan 2026 12:19:00 +0800 Subject: fix(rules): add architecture and version checks to library rule matching Complete the rule_matches function to properly evaluate: - OS name (already working: osx/macos, linux, windows) - Architecture (arch field): match against env::consts::ARCH - OS version (version field): accept all versions for now (conservative) This ensures that architecture-specific libraries (e.g. natives-arm64) are correctly filtered based on the current platform. --- src-tauri/src/core/rules.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'src-tauri/src/core') diff --git a/src-tauri/src/core/rules.rs b/src-tauri/src/core/rules.rs index 71abda5..10a40b6 100644 --- a/src-tauri/src/core/rules.rs +++ b/src-tauri/src/core/rules.rs @@ -57,18 +57,37 @@ fn rule_matches(rule: &Rule) -> bool { match &rule.os { None => true, // No OS condition means it applies to all Some(os_rule) => { + // Check OS name if let Some(os_name) = &os_rule.name { - match os_name.as_str() { + let os_match = match os_name.as_str() { "osx" | "macos" => env::consts::OS == "macos", "linux" => env::consts::OS == "linux", "windows" => env::consts::OS == "windows", _ => false, // Unknown OS name in rule + }; + + if !os_match { + return false; } - } else { - // OS rule exists but name is None? Maybe checking version/arch only. - // For simplicity, mostly name is used. - true } + + // Check architecture if specified + if let Some(arch) = &os_rule.arch { + let current_arch = env::consts::ARCH; + if arch != current_arch && arch != "x86_64" { + // "x86" is sometimes used for x86_64, but we only match exact arch + return false; + } + } + + // Check version if specified (for OS version compatibility) + if let Some(_version) = &os_rule.version { + // Version checking would require parsing OS version strings + // For now, we accept all versions (conservative approach) + // In the future, parse version and compare + } + + true } } } -- cgit v1.2.3-70-g09d2 From 76086e65a7caf1bb8aa54a9404c70a714bc00da8 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sun, 18 Jan 2026 12:19:43 +0800 Subject: fix(manifest): add find_root_version for nested inheritance resolution Add find_root_version() function to walk the inheritance chain and find the root vanilla Minecraft version from a modded version (Fabric/Forge). This is useful for determining which vanilla version's client.jar should be used when launching modded versions, as modded versions inherit from vanilla versions but don't contain their own client.jar. The function follows the inheritsFrom field recursively until reaching a version without a parent (the root vanilla version). --- src-tauri/src/core/manifest.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src-tauri/src/core') diff --git a/src-tauri/src/core/manifest.rs b/src-tauri/src/core/manifest.rs index 637b935..e792071 100644 --- a/src-tauri/src/core/manifest.rs +++ b/src-tauri/src/core/manifest.rs @@ -97,6 +97,43 @@ pub async fn fetch_vanilla_version( Ok(resp) } +/// Find the root vanilla version by following the inheritance chain. +/// +/// For modded versions (Fabric, Forge), this walks up the `inheritsFrom` +/// chain to find the base vanilla Minecraft version. +/// +/// # Arguments +/// * `game_dir` - The .minecraft directory path +/// * `version_id` - The version ID to start from +/// +/// # Returns +/// The ID of the root vanilla version (the version without `inheritsFrom`) +pub async fn find_root_version( + game_dir: &std::path::Path, + version_id: &str, +) -> Result> { + let mut current_id = version_id.to_string(); + + // Keep following the inheritance chain + loop { + let version = match load_local_version(game_dir, ¤t_id).await { + Ok(v) => v, + Err(_) => { + // If not found locally, assume it's a vanilla version (root) + return Ok(current_id); + } + }; + + // If this version has no parent, it's the root + if let Some(parent_id) = version.inherits_from { + current_id = parent_id; + } else { + // This is the root + return Ok(current_id); + } + } +} + /// Load a version, checking local first, then fetching from remote if needed. /// /// For modded versions (those with `inheritsFrom`), this will also resolve -- cgit v1.2.3-70-g09d2 From 373fb81604451f085bf9fbccf9251acb17e400a9 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sun, 18 Jan 2026 12:20:42 +0800 Subject: fix(java): handle build metadata and underscore formats in version parsing Update parse_java_version() to properly handle: - Build metadata (strip '+' and everything after) - Trailing garbage (strip '-' and everything after, e.g. -Ubuntu) - Underscore version separators (1.8.0_411 -> 1.8.0.411) This ensures Java versions are correctly parsed on all platforms: - Old format: 1.8.0_411 (Java 8 update 411) - New format: 21.0.3+13-Ubuntu (Java 21 with build metadata) - Short format: 17.0.1 (Java 17 update 1). --- src-tauri/src/core/java.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src-tauri/src/core') diff --git a/src-tauri/src/core/java.rs b/src-tauri/src/core/java.rs index 0c7769b..d3e1bb9 100644 --- a/src-tauri/src/core/java.rs +++ b/src-tauri/src/core/java.rs @@ -850,8 +850,27 @@ fn parse_version_string(output: &str) -> Option { /// Parse version for comparison (returns major version number) fn parse_java_version(version: &str) -> u32 { - // Handle both old format (1.8.0_xxx) and new format (11.0.x, 17.0.x) - let parts: Vec<&str> = version.split('.').collect(); + // Handle various formats: + // - Old format: 1.8.0_xxx (Java 8 with update) + // - New format: 17.0.1, 11.0.5+10 (Java 11+) + // - Format with build: 21.0.3+13-Ubuntu-0ubuntu0.24.04.1 + // - Format with underscores: 1.8.0_411 + + // First, strip build metadata (everything after '+') + let version_only = version.split('+').next().unwrap_or(version); + + // Remove trailing junk (like "-Ubuntu-0ubuntu0.24.04.1") + let version_only = version_only + .split('-') + .next() + .unwrap_or(version_only); + + // Replace underscores with dots (1.8.0_411 -> 1.8.0.411) + let normalized = version_only.replace('_', "."); + + // Split by dots + let parts: Vec<&str> = normalized.split('.').collect(); + if let Some(first) = parts.first() { if *first == "1" { // Old format: 1.8.0 -> major is 8 -- cgit v1.2.3-70-g09d2