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 --- src-tauri/src/main.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src-tauri/src/main.rs') diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index fdd0794..402f58f 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,6 +1,8 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +use tauri::State; + mod core; mod launcher; @@ -23,10 +25,41 @@ async fn start_game() -> Result { } } +#[tauri::command] +async fn get_versions() -> Result, String> { + match core::manifest::fetch_version_manifest().await { + Ok(manifest) => Ok(manifest.versions), + Err(e) => Err(e.to_string()), + } +} + +#[tauri::command] +async fn login_offline( + state: State<'_, core::auth::AccountState>, + username: String, +) -> Result { + let uuid = core::auth::generate_offline_uuid(&username); + let account = core::auth::OfflineAccount { + username, + uuid, + }; + + *state.active_account.lock().unwrap() = Some(account.clone()); + Ok(account) +} + +#[tauri::command] +async fn get_active_account( + state: State<'_, core::auth::AccountState>, +) -> Result, String> { + Ok(state.active_account.lock().unwrap().clone()) +} + fn main() { tauri::Builder::default() .plugin(tauri_plugin_shell::init()) - .invoke_handler(tauri::generate_handler![start_game]) + .manage(core::auth::AccountState::new()) + .invoke_handler(tauri::generate_handler![start_game, get_versions, login_offline, get_active_account]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } -- cgit v1.2.3-70-g09d2