diff options
| author | 2026-01-14 22:06:55 +0100 | |
|---|---|---|
| committer | 2026-01-14 22:06:55 +0100 | |
| commit | 3000190d4f9d43bd33b074cc1c242ff0b87d8235 (patch) | |
| tree | 22364896adb1a7c08a9a79cc00f11eaf4d41fef7 /ui | |
| parent | b473aa744e1382e946a92a116707b93151558888 (diff) | |
| download | DropOut-3000190d4f9d43bd33b074cc1c242ff0b87d8235.tar.gz DropOut-3000190d4f9d43bd33b074cc1c242ff0b87d8235.zip | |
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
Diffstat (limited to 'ui')
| -rw-r--r-- | ui/src/components/SettingsView.svelte | 77 | ||||
| -rw-r--r-- | ui/src/stores/settings.svelte.ts | 63 | ||||
| -rw-r--r-- | ui/src/types/index.ts | 10 |
3 files changed, 149 insertions, 1 deletions
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"} </button> + <button + onclick={() => settingsState.openJavaDownloadModal()} + class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-xl transition-colors whitespace-nowrap text-sm font-medium" + > + Download Java + </button> </div> </div> @@ -297,3 +303,74 @@ </div> </div> </div> + +<!-- Java Download Modal --> +{#if settingsState.showJavaDownloadModal} + <div class="fixed inset-0 z-[100] flex items-center justify-center backdrop-blur-sm bg-black/70"> + <div class="bg-zinc-900 rounded-2xl border border-white/10 p-8 max-w-md w-full mx-4 shadow-2xl"> + <h3 class="text-2xl font-bold mb-6 text-white">Download Java</h3> + + <div class="space-y-6"> + <!-- Java Version Selection --> + <div> + <label class="block text-sm font-medium text-white/70 mb-2">Java Version</label> + <select + bind:value={settingsState.selectedJavaVersion} + class="bg-black/40 text-white w-full px-4 py-3 rounded-xl border border-white/10 focus:border-indigo-500/50 outline-none" + > + {#each settingsState.availableJavaVersions as version} + <option value={version}>Java {version}</option> + {/each} + </select> + </div> + + <!-- Image Type Selection --> + <div> + <label class="block text-sm font-medium text-white/70 mb-2">Image Type</label> + <div class="grid grid-cols-2 gap-3"> + <button + onclick={() => settingsState.selectedImageType = "jre"} + class="px-4 py-3 rounded-xl border transition-all {settingsState.selectedImageType === 'jre' ? 'bg-indigo-500/20 border-indigo-500/50 text-white' : 'bg-black/20 border-white/10 text-white/60 hover:bg-white/5'}" + > + JRE + </button> + <button + onclick={() => settingsState.selectedImageType = "jdk"} + class="px-4 py-3 rounded-xl border transition-all {settingsState.selectedImageType === 'jdk' ? 'bg-indigo-500/20 border-indigo-500/50 text-white' : 'bg-black/20 border-white/10 text-white/60 hover:bg-white/5'}" + > + JDK + </button> + </div> + <p class="text-xs text-white/40 mt-2"> + JRE: Runtime only (smaller). JDK: Includes development tools. + </p> + </div> + + <!-- Status --> + {#if settingsState.javaDownloadStatus} + <div class="bg-black/40 border border-white/10 rounded-xl p-4 text-sm text-white/80"> + {settingsState.javaDownloadStatus} + </div> + {/if} + + <!-- Actions --> + <div class="flex gap-3 pt-2"> + <button + onclick={() => settingsState.closeJavaDownloadModal()} + disabled={settingsState.isDownloadingJava} + class="flex-1 bg-white/10 hover:bg-white/20 disabled:opacity-50 text-white px-4 py-3 rounded-xl border border-white/5 transition-colors font-medium" + > + Cancel + </button> + <button + onclick={() => settingsState.downloadJava()} + disabled={settingsState.isDownloadingJava} + class="flex-1 bg-indigo-600 hover:bg-indigo-500 disabled:opacity-50 text-white px-4 py-3 rounded-xl transition-colors font-medium" + > + {settingsState.isDownloadingJava ? "Downloading..." : "Download & Install"} + </button> + </div> + </div> + </div> + </div> +{/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<JavaInstallation[]>([]); isDetectingJava = $state(false); + + // Java download state + showJavaDownloadModal = $state(false); + availableJavaVersions = $state<number[]>([]); + 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 { |