From 64b939e6ac0b196d18ee183a37a40b0bf7927a80 Mon Sep 17 00:00:00 2001 From: Natsuu Date: Wed, 14 Jan 2026 03:41:18 +0000 Subject: refactor: split App.svelte into components --- ui/src/stores/settings.svelte.ts | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 ui/src/stores/settings.svelte.ts (limited to 'ui/src/stores/settings.svelte.ts') diff --git a/ui/src/stores/settings.svelte.ts b/ui/src/stores/settings.svelte.ts new file mode 100644 index 0000000..a1f687c --- /dev/null +++ b/ui/src/stores/settings.svelte.ts @@ -0,0 +1,56 @@ +import { invoke } from "@tauri-apps/api/core"; +import type { LauncherConfig, JavaInstallation } from "../types"; +import { uiState } from "./ui.svelte"; + +export class SettingsState { + settings = $state({ + min_memory: 1024, + max_memory: 2048, + java_path: "java", + width: 854, + height: 480, + }); + javaInstallations = $state([]); + isDetectingJava = $state(false); + + async loadSettings() { + try { + this.settings = await invoke("get_settings"); + } catch (e) { + console.error("Failed to load settings:", e); + } + } + + async saveSettings() { + try { + await invoke("save_settings", { config: this.settings }); + uiState.setStatus("Settings saved!"); + } catch (e) { + console.error("Failed to save settings:", e); + uiState.setStatus("Error saving settings: " + e); + } + } + + async detectJava() { + this.isDetectingJava = true; + try { + this.javaInstallations = await invoke("detect_java"); + if (this.javaInstallations.length === 0) { + uiState.setStatus("No Java installations found"); + } else { + uiState.setStatus(`Found ${this.javaInstallations.length} Java installation(s)`); + } + } catch (e) { + console.error("Failed to detect Java:", e); + uiState.setStatus("Error detecting Java: " + e); + } finally { + this.isDetectingJava = false; + } + } + + selectJava(path: string) { + this.settings.java_path = path; + } +} + +export const settingsState = new SettingsState(); -- cgit v1.2.3-70-g09d2 From caeec0304d0f6c592b6ce24d8c6c932eea6a5225 Mon Sep 17 00:00:00 2001 From: Natsuu Date: Wed, 14 Jan 2026 03:46:48 +0000 Subject: chore: improve loadSettings method for better result handling --- ui/src/stores/settings.svelte.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'ui/src/stores/settings.svelte.ts') diff --git a/ui/src/stores/settings.svelte.ts b/ui/src/stores/settings.svelte.ts index a1f687c..9bc122e 100644 --- a/ui/src/stores/settings.svelte.ts +++ b/ui/src/stores/settings.svelte.ts @@ -15,7 +15,10 @@ export class SettingsState { async loadSettings() { try { - this.settings = await invoke("get_settings"); + const result = await invoke("get_settings"); + if (result && typeof result === "object") { + this.settings = result as LauncherConfig; + } } catch (e) { console.error("Failed to load settings:", e); } -- cgit v1.2.3-70-g09d2 From ce4f190c4cc33c5ffdae7c0d93df2232e2257179 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Wed, 14 Jan 2026 12:01:45 +0800 Subject: fix: avoid any/object process Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- ui/src/stores/settings.svelte.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'ui/src/stores/settings.svelte.ts') diff --git a/ui/src/stores/settings.svelte.ts b/ui/src/stores/settings.svelte.ts index 9bc122e..989172c 100644 --- a/ui/src/stores/settings.svelte.ts +++ b/ui/src/stores/settings.svelte.ts @@ -15,10 +15,8 @@ export class SettingsState { async loadSettings() { try { - const result = await invoke("get_settings"); - if (result && typeof result === "object") { - this.settings = result as LauncherConfig; - } + const result = await invoke("get_settings"); + this.settings = result; } catch (e) { console.error("Failed to load settings:", e); } -- cgit v1.2.3-70-g09d2