aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/stores/settings.svelte.ts
diff options
context:
space:
mode:
authorBegonia, HE <163421589+BegoniaHe@users.noreply.github.com>2026-01-14 22:06:55 +0100
committerBegonia, HE <163421589+BegoniaHe@users.noreply.github.com>2026-01-14 22:06:55 +0100
commit3000190d4f9d43bd33b074cc1c242ff0b87d8235 (patch)
tree22364896adb1a7c08a9a79cc00f11eaf4d41fef7 /ui/src/stores/settings.svelte.ts
parentb473aa744e1382e946a92a116707b93151558888 (diff)
downloadDropOut-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/src/stores/settings.svelte.ts')
-rw-r--r--ui/src/stores/settings.svelte.ts63
1 files changed, 62 insertions, 1 deletions
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();