From 5e9850881d35d3af9ae8a2f99402e02300f77835 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sun, 18 Jan 2026 12:58:22 +0800 Subject: fix: complete Instance/Profile System isolation and state management ## Overview Fixed critical multi-instance isolation bugs where versions, mod loaders, and instance state were not properly isolated between instances. These changes ensure full data isolation and consistent instance metadata. ## Bug Fixes - P0 (Critical Isolation Issues) ### 1. Backend: get_versions() command isolation - Problem: Used global app_data_dir instead of instance-specific game_dir - Fix: Added instance_id parameter, now queries instance.game_dir - Impact: Versions are now properly isolated per instance ### 2. Frontend: delete_version missing instanceId - Problem: Frontend passed only versionId, not instanceId - Fix: Updated VersionsView.svelte to pass instanceId parameter - Impact: Version deletion now targets correct instance ### 3. Frontend: get_version_metadata missing instanceId - Problem: Metadata queries didn't specify which instance to check - Fix: Updated VersionsView.svelte to pass instanceId parameter - Impact: Version info displayed per-instance correctly ### 4. Frontend: Instance switching doesn't refresh versions - Problem: Switching instances didn't reload version list - Fix: Added $effect hook in GameState to watch activeInstanceId changes - Impact: Version list auto-refreshes on instance switch ## Bug Fixes - P1 (State Synchronization) ### 5. Backend: install_fabric doesn't update Instance.mod_loader - Problem: Instance.mod_loader field wasn't updated after installation - Fix: Added instance_state.update_instance() call - Impact: Instance metadata stays in sync ### 6. Backend: install_forge doesn't update Instance.mod_loader - Problem: Instance.mod_loader field wasn't updated after installation - Fix: Added instance_state.update_instance() call - Impact: Instance metadata stays in sync ### 7. Backend: delete_version doesn't clean up Instance state - Problem: Deleting version didn't clear Instance.version_id or .mod_loader - Fix: Added cleanup logic to clear stale references - Impact: Instance state remains valid after deletion ## Testing - Added comprehensive integration tests in instance_isolation_tests.rs - Tests document 10 key scenarios for multi-instance isolation - All code compiles cleanly with no errors --- ui/src/stores/game.svelte.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'ui/src/stores') diff --git a/ui/src/stores/game.svelte.ts b/ui/src/stores/game.svelte.ts index 1e4119f..15dcf22 100644 --- a/ui/src/stores/game.svelte.ts +++ b/ui/src/stores/game.svelte.ts @@ -8,13 +8,31 @@ export class GameState { versions = $state([]); selectedVersion = $state(""); + constructor() { + // Refresh versions when active instance changes + $effect(() => { + if (instancesState.activeInstanceId) { + this.loadVersions(); + } else { + this.versions = []; + } + }); + } + get latestRelease() { return this.versions.find((v) => v.type === "release"); } async loadVersions() { + if (!instancesState.activeInstanceId) { + this.versions = []; + return; + } + try { - this.versions = await invoke("get_versions"); + this.versions = await invoke("get_versions", { + instanceId: instancesState.activeInstanceId, + }); // Don't auto-select version here - let BottomBar handle version selection // based on installed versions only } catch (e) { -- cgit v1.2.3-70-g09d2