From cd82fabfac3120179f947fba331025676dc1af7f Mon Sep 17 00:00:00 2001 From: Natsuu Date: Wed, 14 Jan 2026 04:40:03 +0000 Subject: feat: add functionality to retrieve installed game versions --- src-tauri/src/main.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d7ae9a4..bf7504d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -586,6 +586,42 @@ async fn get_versions() -> Result, String> { } } +#[tauri::command] +async fn get_installed_versions(app_handle: tauri::AppHandle) -> Result, String> { + let game_dir = app_handle + .path() + .app_data_dir() + .map_err(|e| format!("Failed to get app data dir: {}", e))?; + + let versions_dir = game_dir.join("versions"); + + if !versions_dir.exists() { + return Ok(Vec::new()); + } + + let mut installed_versions = Vec::new(); + + if let Ok(entries) = std::fs::read_dir(versions_dir) { + for entry in entries { + if let Ok(entry) = entry { + if let Ok(file_type) = entry.file_type() { + if file_type.is_dir() { + if let Ok(file_name) = entry.file_name().into_string() { + // Optionally verify if {version_id}.json exists inside + let json_path = entry.path().join(format!("{}.json", file_name)); + if json_path.exists() { + installed_versions.push(file_name); + } + } + } + } + } + } + } + + Ok(installed_versions) +} + #[tauri::command] async fn login_offline( window: Window, @@ -784,6 +820,7 @@ fn main() { .invoke_handler(tauri::generate_handler![ start_game, get_versions, + get_installed_versions, login_offline, get_active_account, logout, -- cgit v1.2.3-70-g09d2 From 11a604f7e03d1a6f1b4ad381fdcf0ccaef440cff Mon Sep 17 00:00:00 2001 From: Natsuu Date: Wed, 14 Jan 2026 04:51:46 +0000 Subject: refactor: simplify get_installed_versions function by using iterator methods --- src-tauri/src/main.rs | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index bf7504d..c1b882c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -595,29 +595,23 @@ async fn get_installed_versions(app_handle: tauri::AppHandle) -> Result Date: Wed, 14 Jan 2026 13:05:38 +0800 Subject: Update src-tauri/src/main.rs Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- src-tauri/src/main.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c1b882c..bb79f3e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -594,9 +594,21 @@ async fn get_installed_versions(app_handle: tauri::AppHandle) -> Result entries, + Err(e) if e.kind() == std::io::ErrorKind::NotFound => { + // No versions directory yet; treat as "no versions installed" + return Ok(Vec::new()); + } + Err(e) => { + eprintln!( + "Failed to read versions directory {}: {}", + versions_dir.display(), + e + ); + return Err(format!("Failed to read versions directory: {}", e)); + } }; let installed_versions = entries -- cgit v1.2.3-70-g09d2 From 791bd84d175d8d454d8a7846dea63d57653ed7e1 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Wed, 14 Jan 2026 13:35:29 +0800 Subject: feat: add download_threads to LauncherConfig and update download logging --- src-tauri/src/core/config.rs | 2 ++ src-tauri/src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/core/config.rs b/src-tauri/src/core/config.rs index 47c5306..dc72dcb 100644 --- a/src-tauri/src/core/config.rs +++ b/src-tauri/src/core/config.rs @@ -11,6 +11,7 @@ pub struct LauncherConfig { pub java_path: String, pub width: u32, pub height: u32, + pub download_threads: u32, // concurrent download threads } impl Default for LauncherConfig { @@ -21,6 +22,7 @@ impl Default for LauncherConfig { java_path: "java".to_string(), width: 854, height: 480, + download_threads: 32, } } } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d7ae9a4..73310d5 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -262,8 +262,8 @@ async fn start_game( )); // 4. Start Download - emit_log!(window, "Starting downloads...".to_string()); - core::downloader::download_files(window.clone(), download_tasks) + emit_log!(window, format!("Starting downloads with {} concurrent threads...", config.download_threads)); + core::downloader::download_files(window.clone(), download_tasks, config.download_threads as usize) .await .map_err(|e| e.to_string())?; emit_log!(window, "All downloads completed successfully".to_string()); -- cgit v1.2.3-70-g09d2 From 21c66d00d8d300b33a353a366fa23d0773deb413 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Wed, 14 Jan 2026 14:19:15 +0800 Subject: Revert "feat: add functionality to retrieve installed game versions" --- src-tauri/src/main.rs | 43 -------------------------------------- ui/src/components/BottomBar.svelte | 7 ++----- ui/src/stores/game.svelte.ts | 32 ++++------------------------ 3 files changed, 6 insertions(+), 76 deletions(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 53d9388..73310d5 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -586,48 +586,6 @@ async fn get_versions() -> Result, String> { } } -#[tauri::command] -async fn get_installed_versions(app_handle: tauri::AppHandle) -> Result, String> { - let game_dir = app_handle - .path() - .app_data_dir() - .map_err(|e| format!("Failed to get app data dir: {}", e))?; - - let versions_dir = game_dir.join("versions"); - - let entries = match std::fs::read_dir(&versions_dir) { - Ok(entries) => entries, - Err(e) if e.kind() == std::io::ErrorKind::NotFound => { - // No versions directory yet; treat as "no versions installed" - return Ok(Vec::new()); - } - Err(e) => { - eprintln!( - "Failed to read versions directory {}: {}", - versions_dir.display(), - e - ); - return Err(format!("Failed to read versions directory: {}", e)); - } - }; - - let installed_versions = entries - .flatten() - .filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false)) - .filter_map(|entry| { - let file_name = entry.file_name().into_string().ok()?; - let json_path = entry.path().join(format!("{}.json", file_name)); - if json_path.exists() { - Some(file_name) - } else { - None - } - }) - .collect(); - - Ok(installed_versions) -} - #[tauri::command] async fn login_offline( window: Window, @@ -826,7 +784,6 @@ fn main() { .invoke_handler(tauri::generate_handler![ start_game, get_versions, - get_installed_versions, login_offline, get_active_account, logout, diff --git a/ui/src/components/BottomBar.svelte b/ui/src/components/BottomBar.svelte index a96b086..dcad9e8 100644 --- a/ui/src/components/BottomBar.svelte +++ b/ui/src/components/BottomBar.svelte @@ -65,13 +65,10 @@ > {#if gameState.versions.length === 0} - {:else if gameState.installedVersionIds.length === 0} - {:else} {#each gameState.versions as version} - {#if gameState.installedVersionIds.includes(version.id)} - - {/if} + {/each} {/if} diff --git a/ui/src/stores/game.svelte.ts b/ui/src/stores/game.svelte.ts index f66cc71..0af3daf 100644 --- a/ui/src/stores/game.svelte.ts +++ b/ui/src/stores/game.svelte.ts @@ -5,38 +5,14 @@ import { authState } from "./auth.svelte"; export class GameState { versions = $state([]); - installedVersionIds = $state([]); selectedVersion = $state(""); async loadVersions() { try { - // Fetch both full version list and installed versions - const [allVersions, installedIds] = await Promise.all([ - invoke("get_versions"), - invoke("get_installed_versions") - ]); - - this.versions = allVersions; - this.installedVersionIds = installedIds; - - if (this.installedVersionIds.length > 0) { - // Find the first installed version that appears in our manifest (preserving order) - // Usually we want the latest release that is installed - const installedVersions = this.versions.filter(v => this.installedVersionIds.includes(v.id)); - - // Try to find latest release among installed - const latestInstalledRelease = installedVersions.find(v => v.type === "release"); - - if (latestInstalledRelease) { - this.selectedVersion = latestInstalledRelease.id; - } else if (installedVersions.length > 0) { - this.selectedVersion = installedVersions[0].id; - } else { - // Fallback to just the first ID if not in manifest - this.selectedVersion = this.installedVersionIds[0]; - } - } else { - this.selectedVersion = ""; + this.versions = await invoke("get_versions"); + if (this.versions.length > 0) { + const latest = this.versions.find((v) => v.type === "release"); + this.selectedVersion = latest ? latest.id : this.versions[0].id; } } catch (e) { console.error("Failed to fetch versions:", e); -- cgit v1.2.3-70-g09d2