aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/stores/settings.svelte.ts
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2026-01-14 12:09:36 +0800
committerGitHub <noreply@github.com>2026-01-14 12:09:36 +0800
commitb8cfb443b23e644ac0a7f469b500b2beaf001e9a (patch)
tree220f1968d22c4116bb86849168e242eb18234921 /ui/src/stores/settings.svelte.ts
parentf1babdf9a625ddbb661f4e0678e6258511347656 (diff)
parente636559dbc509a305dc372887fd1549322092d72 (diff)
downloadDropOut-b8cfb443b23e644ac0a7f469b500b2beaf001e9a.tar.gz
DropOut-b8cfb443b23e644ac0a7f469b500b2beaf001e9a.zip
Merge pull request #11 from NtskwK/refactor/ui
Diffstat (limited to 'ui/src/stores/settings.svelte.ts')
-rw-r--r--ui/src/stores/settings.svelte.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/ui/src/stores/settings.svelte.ts b/ui/src/stores/settings.svelte.ts
new file mode 100644
index 0000000..989172c
--- /dev/null
+++ b/ui/src/stores/settings.svelte.ts
@@ -0,0 +1,57 @@
+import { invoke } from "@tauri-apps/api/core";
+import type { LauncherConfig, JavaInstallation } from "../types";
+import { uiState } from "./ui.svelte";
+
+export class SettingsState {
+ settings = $state<LauncherConfig>({
+ min_memory: 1024,
+ max_memory: 2048,
+ java_path: "java",
+ width: 854,
+ height: 480,
+ });
+ javaInstallations = $state<JavaInstallation[]>([]);
+ isDetectingJava = $state(false);
+
+ async loadSettings() {
+ try {
+ const result = await invoke<LauncherConfig>("get_settings");
+ this.settings = result;
+ } 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();