From 3000190d4f9d43bd33b074cc1c242ff0b87d8235 Mon Sep 17 00:00:00 2001 From: "Begonia, HE" <163421589+BegoniaHe@users.noreply.github.com> Date: Wed, 14 Jan 2026 22:06:55 +0100 Subject: feat: re-integrate Java download UI into new component architecture - Add Java download functionality to settings store - Add JavaDownloadInfo type definition - Add Download Java button and modal to SettingsView - Support JRE/JDK selection with version picker - Maintain integration with Adoptium API backend --- ui/src/components/SettingsView.svelte | 77 +++++++++++++++++++++++++++++++++++ ui/src/stores/settings.svelte.ts | 63 +++++++++++++++++++++++++++- ui/src/types/index.ts | 10 +++++ 3 files changed, 149 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/src/components/SettingsView.svelte b/ui/src/components/SettingsView.svelte index 86bcce1..d409784 100644 --- a/ui/src/components/SettingsView.svelte +++ b/ui/src/components/SettingsView.svelte @@ -183,6 +183,12 @@ > {settingsState.isDetectingJava ? "Detecting..." : "Auto Detect"} + @@ -297,3 +303,74 @@ + + +{#if settingsState.showJavaDownloadModal} +
+
+

Download Java

+ +
+ +
+ + +
+ + +
+ +
+ + +
+

+ JRE: Runtime only (smaller). JDK: Includes development tools. +

+
+ + + {#if settingsState.javaDownloadStatus} +
+ {settingsState.javaDownloadStatus} +
+ {/if} + + +
+ + +
+
+
+
+{/if} diff --git a/ui/src/stores/settings.svelte.ts b/ui/src/stores/settings.svelte.ts index b67cdc3..34b6b4c 100644 --- a/ui/src/stores/settings.svelte.ts +++ b/ui/src/stores/settings.svelte.ts @@ -1,5 +1,5 @@ import { invoke } from "@tauri-apps/api/core"; -import type { LauncherConfig, JavaInstallation } from "../types"; +import type { LauncherConfig, JavaInstallation, JavaDownloadInfo } from "../types"; import { uiState } from "./ui.svelte"; export class SettingsState { @@ -17,6 +17,14 @@ export class SettingsState { }); javaInstallations = $state([]); isDetectingJava = $state(false); + + // Java download state + showJavaDownloadModal = $state(false); + availableJavaVersions = $state([]); + selectedJavaVersion = $state(21); + selectedImageType = $state<"jre" | "jdk">("jre"); + isDownloadingJava = $state(false); + javaDownloadStatus = $state(""); async loadSettings() { try { @@ -62,6 +70,59 @@ export class SettingsState { selectJava(path: string) { this.settings.java_path = path; } + + async openJavaDownloadModal() { + this.showJavaDownloadModal = true; + this.javaDownloadStatus = ""; + try { + this.availableJavaVersions = await invoke("fetch_available_java_versions"); + // Default selection logic + if (this.availableJavaVersions.includes(21)) { + this.selectedJavaVersion = 21; + } else if (this.availableJavaVersions.includes(17)) { + this.selectedJavaVersion = 17; + } else if (this.availableJavaVersions.length > 0) { + this.selectedJavaVersion = this.availableJavaVersions[this.availableJavaVersions.length - 1]; + } + } catch (e) { + console.error("Failed to fetch available Java versions:", e); + this.javaDownloadStatus = "Error fetching Java versions: " + e; + } + } + + closeJavaDownloadModal() { + if (!this.isDownloadingJava) { + this.showJavaDownloadModal = false; + } + } + + async downloadJava() { + this.isDownloadingJava = true; + this.javaDownloadStatus = `Downloading Java ${this.selectedJavaVersion} ${this.selectedImageType.toUpperCase()}...`; + + try { + const result: JavaInstallation = await invoke("download_adoptium_java", { + majorVersion: this.selectedJavaVersion, + imageType: this.selectedImageType, + customPath: null, + }); + + this.javaDownloadStatus = `Java ${this.selectedJavaVersion} installed at ${result.path}`; + this.settings.java_path = result.path; + + await this.detectJava(); + + setTimeout(() => { + this.showJavaDownloadModal = false; + uiState.setStatus(`Java ${this.selectedJavaVersion} is ready to use!`); + }, 1500); + } catch (e) { + console.error("Failed to download Java:", e); + this.javaDownloadStatus = "Download failed: " + e; + } finally { + this.isDownloadingJava = false; + } + } } export const settingsState = new SettingsState(); diff --git a/ui/src/types/index.ts b/ui/src/types/index.ts index 7e2cc67..f92cbf2 100644 --- a/ui/src/types/index.ts +++ b/ui/src/types/index.ts @@ -43,6 +43,16 @@ export interface JavaInstallation { is_64bit: boolean; } +export interface JavaDownloadInfo { + version: string; + release_name: string; + download_url: string; + file_name: string; + file_size: number; + checksum: string | null; + image_type: string; +} + // ==================== Fabric Types ==================== export interface FabricGameVersion { -- cgit v1.2.3-70-g09d2