From 6fbb5f19cab02f3a0f18cdeda3da02e717b69cd6 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Tue, 13 Jan 2026 15:37:55 +0800 Subject: feat: add offline account management and version fetching functionality --- ui/src/App.svelte | 85 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/src/App.svelte b/ui/src/App.svelte index 292c719..18ef5e5 100644 --- a/ui/src/App.svelte +++ b/ui/src/App.svelte @@ -4,6 +4,65 @@ let status = "Ready"; + interface Version { + id: string; + type: string; + url: string; + time: string; + releaseTime: string; + } + + interface OfflineAccount { + username: string; + uuid: string; + } + + let versions: Version[] = []; + let selectedVersion = ""; + let currentAccount: OfflineAccount | null = null; + + onMount(async () => { + checkAccount(); + try { + versions = await invoke("get_versions"); + if (versions.length > 0) { + // Find latest release or default to first + const latest = versions.find(v => v.type === 'release'); + selectedVersion = latest ? latest.id : versions[0].id; + } + } catch (e) { + console.error("Failed to fetch versions:", e); + status = "Error fetching versions: " + e; + } + }); + + async function checkAccount() { + try { + const acc = await invoke("get_active_account"); + currentAccount = acc as OfflineAccount | null; + } catch (e) { + console.error("Failed to check account:", e); + } + } + + async function login() { + if (currentAccount) { + if (confirm("Logout " + currentAccount.username + "?")) { + currentAccount = null; + // Note: Backend state persists until restarted or overwritten. + } + return; + } + const username = prompt("Enter username for offline login:"); + if (username) { + try { + currentAccount = await invoke("login_offline", { username }); + } catch(e) { + alert("Login failed: " + e); + } + } + } + async function startGame() { status = "Launching (Simulated)..."; console.log("Invoking start_game..."); @@ -73,12 +132,18 @@
-
-
S
+
e.key === 'Enter' && login()}> +
+ {#if currentAccount} + {currentAccount.username} + {:else} + ? + {/if} +
-
Steve
+
{currentAccount ? currentAccount.username : "Click to Login"}
- Online + {currentAccount ? 'Ready' : 'Guest'}
@@ -86,10 +151,14 @@
- + {#if versions.length === 0} + + {:else} + {#each versions as version} + + {/each} + {/if}
-- cgit v1.2.3-70-g09d2