lighty_launcher/lib.rs
1// Copyright (c) 2025 Hamadi
2// Licensed under the MIT License
3
4//! LightyLauncher - A modern Minecraft launcher library
5//!
6//! This library provides everything needed to build a custom Minecraft launcher:
7//! - Authentication (Offline, Microsoft, Azuriom) + trait-based extensibility
8//! - Java runtime management
9//! - Version metadata handling (Vanilla, Fabric, Quilt, Forge, NeoForge, LightyUpdater)
10//! - Game installation and launching
11//! - Event system for progress tracking
12//!
13//! ## Quick Start
14//!
15//! ```no_run
16//! use lighty_launcher::prelude::*;
17//! use directories::ProjectDirs;
18//!
19//! #[tokio::main]
20//! async fn main() -> anyhow::Result<()> {
21//! let launcher_dir = ProjectDirs::from("com", "MyCompany", "MyLauncher")
22//! .expect("Failed to get project directories");
23//!
24//! // Authenticate
25//! let mut auth = auth::OfflineAuth::new("Player");
26//! let profile = auth.authenticate().await?;
27//!
28//! // Build and launch
29//! let mut version = version::VersionBuilder::new(
30//! "my-instance",
31//! Loader::Vanilla,
32//! "",
33//! "1.21.1",
34//! &launcher_dir
35//! );
36//!
37//! version.launch(&profile, JavaDistribution::Temurin)
38//! .run()
39//! .await?;
40//!
41//! Ok(())
42//! }
43//! ```
44
45// ============================================================================
46// Authentication Module
47// ============================================================================
48
49pub mod auth {
50 //! Authentication providers and utilities
51 //!
52 //! ## Built-in Providers
53 //! - `OfflineAuth` - No network required
54 //! - `MicrosoftAuth` - OAuth 2.0 via Microsoft
55 //! - `AzuriomAuth` - Azuriom CMS integration
56 //!
57 //! ## Custom Authentication
58 //! Implement the `Authenticator` trait to create your own provider.
59 //! See the [`lighty_auth`](https://docs.rs/lighty-auth) documentation for examples.
60
61 pub use lighty_auth::{
62 Authenticator,
63 UserProfile,
64 UserRole,
65 AuthProvider,
66 AuthResult,
67 AuthError,
68 generate_offline_uuid,
69 offline::OfflineAuth,
70 microsoft::MicrosoftAuth,
71 azuriom::AzuriomAuth,
72 };
73}
74
75// ============================================================================
76// Events Module
77// ============================================================================
78
79#[cfg(feature = "events")]
80pub mod event {
81 //! Event system for tracking launcher operations
82 //!
83 //! Provides real-time progress updates for:
84 //! - Authentication
85 //! - Java runtime downloads
86 //! - Game installation
87 //! - Loader metadata fetching
88 //! - Archive extraction
89
90 pub use lighty_event::{
91 EventBus,
92 EventReceiver,
93 Event,
94 AuthEvent,
95 JavaEvent,
96 LaunchEvent,
97 LoaderEvent,
98 CoreEvent,
99 EventReceiveError,
100 EventTryReceiveError,
101 EventSendError,
102 };
103}
104
105// ============================================================================
106// Java Module
107// ============================================================================
108
109pub mod java {
110 //! Java runtime management
111 //!
112 //! Handles automatic download and installation of Java distributions:
113 //! - Temurin (Eclipse Adoptium)
114 //! - GraalVM
115 //! - Zulu (Azul)
116 //! - Liberica (BellSoft)
117
118 pub use lighty_java::{
119 JavaDistribution,
120 DistributionSelection,
121 runtime::JavaRuntime,
122 jre_downloader,
123 JreError,
124 JreResult,
125 JavaRuntimeError,
126 JavaRuntimeResult,
127 DistributionError,
128 DistributionResult,
129 };
130}
131
132// ============================================================================
133// Launch Module
134// ============================================================================
135
136pub mod launch {
137 //! Game launching and installation
138 //!
139 //! Coordinates the complete launch process:
140 //! - File verification and downloading
141 //! - Library installation
142 //! - Native library extraction
143 //! - Asset management
144 //! - Argument building
145 //! - Process spawning
146
147 pub use lighty_launch::{
148 launch::{Launch, LaunchBuilder, LaunchConfig},
149 installer::{
150 Installer,
151 config::{DownloaderConfig, init_downloader_config},
152 },
153 arguments::Arguments as LaunchArguments,
154 errors::{InstallerError, InstallerResult},
155 };
156
157 /// Launch argument keys for customization
158 pub mod keys {
159 pub use lighty_launch::arguments::{
160 KEY_AUTH_PLAYER_NAME,
161 KEY_AUTH_UUID,
162 KEY_AUTH_ACCESS_TOKEN,
163 KEY_AUTH_XUID,
164 KEY_CLIENT_ID,
165 KEY_USER_TYPE,
166 KEY_USER_PROPERTIES,
167 KEY_VERSION_NAME,
168 KEY_VERSION_TYPE,
169 KEY_GAME_DIRECTORY,
170 KEY_ASSETS_ROOT,
171 KEY_NATIVES_DIRECTORY,
172 KEY_LIBRARY_DIRECTORY,
173 KEY_ASSETS_INDEX_NAME,
174 KEY_LAUNCHER_NAME,
175 KEY_LAUNCHER_VERSION,
176 KEY_CLASSPATH,
177 KEY_CLASSPATH_SEPARATOR,
178 };
179 }
180}
181
182// ============================================================================
183// Loaders Module
184// ============================================================================
185
186pub mod loaders {
187 //! Minecraft mod loaders and version metadata
188 //!
189 //! Supports multiple loader types:
190 //! - Vanilla
191 //! - Fabric
192 //! - Quilt
193 //! - Forge
194 //! - NeoForge
195 //! - LightyUpdater
196 //! - OptiFine
197
198 pub use lighty_loaders::{
199 types::{
200 Loader,
201 VersionInfo,
202 LoaderExtensions,
203 version_metadata::{
204 Version,
205 VersionMetaData,
206 Library,
207 Asset,
208 AssetIndex,
209 Arguments,
210 MainClass,
211 Mods,
212 Native,
213 },
214 },
215 loaders::{
216 vanilla,
217 fabric,
218 quilt,
219 forge,
220 neoforge,
221 lighty_updater,
222 optifine,
223 },
224 utils::{cache, error, manifest, query},
225 };
226}
227
228// ============================================================================
229// Version Module
230// ============================================================================
231
232pub mod version {
233 //! Version builders for game instances
234 //!
235 //! - `VersionBuilder` - Standard Minecraft versions with loaders
236 //! - `LightyVersionBuilder` - LightyUpdater custom versions
237
238 pub use lighty_version::{
239 VersionBuilder,
240 LightyVersionBuilder,
241 };
242}
243
244// ============================================================================
245// Core Module
246// ============================================================================
247
248pub mod core {
249 //! Core utilities and system operations
250 //!
251 //! Provides low-level functionality:
252 //! - File system operations
253 //! - HTTP client management
254 //! - Archive extraction (ZIP, TAR.GZ)
255 //! - SHA1 hashing and verification
256 //! - Download utilities
257
258 pub use lighty_core::{
259 system,
260 hosts,
261 download,
262 extract,
263 hash,
264 SystemError,
265 SystemResult,
266 ExtractError,
267 ExtractResult,
268 DownloadError,
269 DownloadResult,
270 HashError,
271 HashResult,
272 verify_file_sha1,
273 verify_file_sha1_streaming,
274 calculate_file_sha1_sync,
275 verify_file_sha1_sync,
276 calculate_sha1_bytes,
277 calculate_sha1_bytes_raw,
278 };
279}
280
281// ============================================================================
282// Macros Module
283// ============================================================================
284
285pub mod macros {
286 //! Utility macros
287 //!
288 //! Provides conditional tracing macros that work with or without the `tracing` feature:
289 //! - `trace_debug!()` - Debug level logging (no-op without `tracing` feature)
290 //! - `trace_info!()` - Info level logging (no-op without `tracing` feature)
291 //! - `trace_warn!()` - Warning level logging (no-op without `tracing` feature)
292 //! - `trace_error!()` - Error level logging (no-op without `tracing` feature)
293 //! - `time_it!()` - Performance timing (no-op without `tracing` feature)
294 //!
295 //! File system utilities:
296 //! - `mkdir!()` - Async directory creation with error logging
297 //! - `join_and_mkdir!()` - Join paths and create directory
298 //! - `join_and_mkdir_vec!()` - Join multiple paths and create directory
299 //! - `mkdir_blocking!()` - Blocking directory creation
300 //!
301 //! ## Example
302 //!
303 //! ```no_run
304 //! use lighty_launcher::macros::*;
305 //!
306 //! async fn example() {
307 //! trace_info!("Starting operation");
308 //!
309 //! let result = time_it!("my_operation", {
310 //! // Some expensive operation
311 //! 42
312 //! });
313 //!
314 //! let path = std::path::Path::new("/tmp/my_dir");
315 //! mkdir!(path);
316 //! }
317 //! ```
318
319 pub use lighty_core::{
320 trace_debug,
321 trace_info,
322 trace_warn,
323 trace_error,
324 time_it,
325 mkdir,
326 join_and_mkdir,
327 join_and_mkdir_vec,
328 mkdir_blocking,
329 };
330}
331
332// ============================================================================
333// Tauri Module
334// ============================================================================
335
336#[cfg(feature = "tauri-commands")]
337pub mod tauri {
338 //! Tauri command integration
339 //!
340 //! Provides ready-to-use Tauri commands for frontend integration:
341 //! - Authentication commands (offline, Microsoft, Azuriom)
342 //! - Launch commands
343 //! - Java distribution listing
344 //! - Loader listing
345 //! - Version management
346 //! - Path utilities
347 //!
348 //! ## Quick Start
349 //!
350 //! ```no_run
351 //! use lighty_launcher::tauri::lighty_plugin;
352 //!
353 //! tauri::Builder::default()
354 //! .plugin(lighty_plugin())
355 //! .run(tauri::generate_context!())
356 //! .expect("error running tauri application");
357 //! ```
358
359 pub use lighty_tauri::lighty_plugin;
360 pub use lighty_tauri::commands::*;
361 pub use lighty_tauri::core::{
362 AppState,
363 VersionConfig,
364 LaunchConfig,
365 LaunchResult,
366 LoaderInfo,
367 JavaDistInfo,
368 };
369}
370
371// ============================================================================
372// Prelude - Commonly used imports
373// ============================================================================
374
375pub mod prelude {
376 //! Convenient re-exports of most commonly used types
377 //!
378 //! ```
379 //! use lighty_launcher::prelude::*;
380 //! ```
381
382 // Authentication
383 pub use crate::auth::{Authenticator, UserProfile, OfflineAuth, MicrosoftAuth, AzuriomAuth};
384
385 // Events
386 #[cfg(feature = "events")]
387 pub use crate::event::{EventBus, Event, AuthEvent, JavaEvent, LaunchEvent, LoaderEvent, CoreEvent};
388
389 // Java
390 pub use crate::java::JavaDistribution;
391
392 // Launch
393 pub use crate::launch::{Launch, LaunchBuilder, DownloaderConfig, init_downloader_config};
394 pub use crate::launch::keys::*;
395
396 // Loaders
397 pub use crate::loaders::{Loader, VersionInfo, LoaderExtensions};
398
399 // Version
400 pub use crate::version::{VersionBuilder, LightyVersionBuilder};
401}
402
403// ============================================================================
404// Root re-exports for convenience
405// ============================================================================
406
407// Most commonly used types at the root for convenience
408pub use loaders::Loader;
409pub use java::JavaDistribution;
410pub use launch::Launch;
411pub use auth::{Authenticator, UserProfile};
412pub use version::{VersionBuilder, LightyVersionBuilder};
413
414// Re-export the crates themselves for advanced usage
415#[doc(hidden)]
416pub use lighty_core as _core;
417#[doc(hidden)]
418pub use lighty_auth as _auth;
419#[cfg(feature = "events")]
420#[doc(hidden)]
421pub use lighty_event as _event;
422#[doc(hidden)]
423pub use lighty_java as _java;
424#[doc(hidden)]
425pub use lighty_launch as _launch;
426#[doc(hidden)]
427pub use lighty_loaders as _loaders;
428#[doc(hidden)]
429pub use lighty_version as _version;
430
431#[cfg(feature = "tauri-commands")]
432#[doc(hidden)]
433pub use lighty_tauri as _tauri;