Module Structure
The backend is organized into four primary modules:Application State
The backend maintains application state using Tauri’s state management:src-tauri/src/app/gui/mod.rs:31-41
The
AppState tracks the running game instance and provides a termination channel for stopping the game process.Tauri Commands
Tauri commands are the primary interface between frontend and backend. They are registered ingui_main():
src-tauri/src/app/gui/mod.rs:46-82
Command Categories
Client Commands (client.rs)
Client Commands (client.rs)
request_branches
Fetches available branches (stable, beta, etc.) from the LiquidBounce API:src-tauri/src/app/gui/commands/client.rs:43-52
request_builds
Fetches builds for a specific branch:src-tauri/src/app/gui/commands/client.rs:56-65
run_client
The most complex command - launches the Minecraft client. See Launcher Core for details.terminate
Stops the running game process:src-tauri/src/app/gui/commands/client.rs:405-415
Authentication Commands (auth.rs)
Authentication Commands (auth.rs)
Handles Minecraft account authentication:
login_offline- Creates offline accountlogin_microsoft- Initiates Microsoft OAuth flowlogout- Removes stored accountrefresh- Refreshes Microsoft account tokensclient_account_authenticate- Authenticates with LiquidBounce APIclient_account_update- Updates account information
Data Commands (data.rs)
Data Commands (data.rs)
Manages application data and configuration:
get_options- Loads user options from diskstore_options- Saves user options to diskclear_data- Clears launcher datadefault_data_folder_path- Returns default data directoryget_custom_mods- Lists custom modsinstall_custom_mod- Installs a custom mod filedelete_custom_mod- Removes a custom mod
System Commands (system.rs)
System Commands (system.rs)
System information and checks:
check_system- Validates system configurationsys_memory- Returns available system memoryget_launcher_version- Returns launcher version string
Error Handling
LiquidLauncher uses Rust’sResult type with custom error enums:
src-tauri/src/error.rs:22-28
Error Propagation
pub async fn setup_assets() -> Result<()> {
let data = download_file(url)?; // Propagates error
Ok(())
}
#[tauri::command]
pub async fn my_command() -> Result<Data, String> {
let result = fallible_operation()
.map_err(|e| format!("Operation failed: {:?}", e))?;
Ok(result)
}
Connection Error Helper
For network errors, a helper provides user-friendly messages:src-tauri/src/error.rs:30-35
Event System
For asynchronous updates (progress, logs), the backend emits events:src-tauri/src/app/gui/commands/client.rs:234-247
Event Types
progress-update- Download/installation progressprocess-output- Game stdout/stderrclient-error- Launch errorsclient-exited- Game process terminated
HTTP Client
A shared HTTP client is used throughout the application:src-tauri/src/main.rs:52-62
The HTTP client includes retry logic using the
backon crate with exponential backoff for reliability.Async Runtime
Tauri commands run in Tokio’s async runtime:src-tauri/src/app/gui/commands/client.rs:355-361
Logging
The backend usestracing for structured logging:
src-tauri/src/main.rs:67-86
Logs are written to both console (with ANSI colors) and rotating daily files, kept for 7 days.
Utilities Module
Theutils module provides shared functionality:
Available Utilities
Available Utilities
Best Practices
Use
? for error propagation - Don’t use .unwrap() or .expect() in production code pathsPrefer async operations - Use
tokio::fs instead of std::fs for file I/O to avoid blockingEmit events for updates - Use the event system for progress updates rather than returning large data structures
Log appropriately - Use
trace!, debug!, info!, warn!, error! at appropriate levelsNext Steps
Frontend Architecture
Learn about Svelte components and UI structure
Launcher Core
Understand the game launch process in depth