diff options
| author | 2026-01-18 13:05:29 +0800 | |
|---|---|---|
| committer | 2026-01-18 13:05:29 +0800 | |
| commit | 9a16c14b7fde683eb41526085c15852c69bed5e5 (patch) | |
| tree | 026dc5a11e81ec205302ada6a5557ca86e094c0b | |
| parent | 5e9850881d35d3af9ae8a2f99402e02300f77835 (diff) | |
| download | DropOut-9a16c14b7fde683eb41526085c15852c69bed5e5.tar.gz DropOut-9a16c14b7fde683eb41526085c15852c69bed5e5.zip | |
refactor: move version refresh logic to App.svelte and clean up GameState constructor
| -rw-r--r-- | ui/src/App.svelte | 9 | ||||
| -rw-r--r-- | ui/src/stores/game.svelte.ts | 17 |
2 files changed, 15 insertions, 11 deletions
diff --git a/ui/src/App.svelte b/ui/src/App.svelte index 127bbea..f73e0a2 100644 --- a/ui/src/App.svelte +++ b/ui/src/App.svelte @@ -48,6 +48,15 @@ window.addEventListener("mousemove", handleMouseMove); }); + // Refresh versions when active instance changes + $effect(() => { + if (instancesState.activeInstanceId) { + gameState.loadVersions(); + } else { + gameState.versions = []; + } + }); + onDestroy(() => { if (typeof window !== 'undefined') window.removeEventListener("mousemove", handleMouseMove); diff --git a/ui/src/stores/game.svelte.ts b/ui/src/stores/game.svelte.ts index 15dcf22..504d108 100644 --- a/ui/src/stores/game.svelte.ts +++ b/ui/src/stores/game.svelte.ts @@ -9,29 +9,24 @@ export class GameState { selectedVersion = $state(""); constructor() { - // Refresh versions when active instance changes - $effect(() => { - if (instancesState.activeInstanceId) { - this.loadVersions(); - } else { - this.versions = []; - } - }); + // Constructor intentionally empty + // Instance switching handled in App.svelte with $effect } get latestRelease() { return this.versions.find((v) => v.type === "release"); } - async loadVersions() { - if (!instancesState.activeInstanceId) { + async loadVersions(instanceId?: string) { + const id = instanceId || instancesState.activeInstanceId; + if (!id) { this.versions = []; return; } try { this.versions = await invoke<Version[]>("get_versions", { - instanceId: instancesState.activeInstanceId, + instanceId: id, }); // Don't auto-select version here - let BottomBar handle version selection // based on installed versions only |