lighty-event
Event system for LightyLauncher - A simple, efficient broadcast-based event system for tracking launcher operations.
Features
- Async-first - Built on tokio's broadcast channels
- Multiple subscribers - Broadcast events to multiple listeners simultaneously
- Typed events - Strongly typed event system with compile-time safety
- Comprehensive - Events for authentication, downloads, installations, and more
- Progress tracking - Real-time progress updates for long-running operations
- Zero-cost - No overhead when events feature is disabled
- Error handling - Custom error types with thiserror
- Extensible - Extend with traits for ergonomic APIs
Event Categories
Authentication Events (AuthEvent)
AuthenticationStarted- Authentication process beginsAuthenticationInProgress- Ongoing authentication with step infoAuthenticationSuccess- Authentication succeededAuthenticationFailed- Authentication failed with errorAlreadyAuthenticated- Valid session already exists
Java Events (JavaEvent)
JavaNotFound- JRE not installedJavaAlreadyInstalled- JRE already presentJavaDownloadStarted- JRE download beginsJavaDownloadProgress- Download progress updatesJavaDownloadCompleted- Download finishedJavaExtractionStarted- Extraction beginsJavaExtractionProgress- Extraction progressJavaExtractionCompleted- Extraction finished
Launch Events (LaunchEvent)
IsInstalled- Files already up-to-dateInstallStarted- Installation beginsInstallProgress- Installation progressInstallCompleted- Installation finishedLaunching- Game launch startingLaunched- Game process spawnedNotLaunched- Launch failedProcessOutput- Game process outputProcessExited- Game process exited
Loader Events (LoaderEvent)
FetchingData- Fetching loader manifestDataFetched- Manifest retrievedManifestNotFound- Version not foundManifestCached- Using cached manifestMergingLoaderData- Merging loader dataDataMerged- Merge completed
Core Events (CoreEvent)
ExtractionStarted- Archive extraction beginsExtractionProgress- Extraction progressExtractionCompleted- Extraction finished
Installation
Add this to your Cargo.toml:
[]
= "0.6"
Usage
Basic Example
use ;
async
With LightyLauncher
use ;
use ;
use ;
use ProjectDirs;
async
Progress Tracking Example
use ;
use Arc;
use ;
async
Multi-Subscriber Example
use ;
async
Error Handling
The event system provides custom error types:
EventReceiveError
BusDropped- Event bus has been closedLagged { skipped }- Receiver fell behind, some events were missed
EventTryReceiveError
Empty- No events available (non-blocking)BusDropped- Event bus has been closedLagged { skipped }- Receiver fell behind
EventSendError
NoReceivers- No active receivers (event not sent)
Example with error handling:
use ;
async
Buffer Size Recommendations
The buffer size determines how many events can be buffered before older events are dropped:
- Small applications: 100-500 events
- Medium applications: 500-2000 events
- Large applications: 2000-5000 events
- Very slow receivers: 5000+ events
// Small buffer for simple use cases
let event_bus = new;
// Larger buffer for complex applications with slow receivers
let event_bus = new;
If receivers are too slow and the buffer fills up, the oldest events will be dropped and receivers will get a Lagged error.
Non-Blocking Receive
For non-blocking event checking, use try_next():
use ;
Feature Flags
The event system is optional and can be disabled:
[]
= { = "0.6", = ["events"] }
= "0.6"
When the events feature is disabled, event-related code is compiled out with zero overhead.
Serialization
All events implement Serialize and Deserialize (via serde), making them easy to:
- Send over the network
- Store in files
- Log to JSON
- Integrate with web APIs (in Tauri)
use ;
use serde_json;
let event = Launch;
// Serialize to JSON
let json = to_string.unwrap;
println!;
// Deserialize from JSON
let deserialized: Event = from_str.unwrap;
Module Structure
lighty-event/
├── src/
│ ├── lib.rs # EventBus, EventReceiver
│ ├── errors.rs # Error types
│ └── module/ # Event definitions
│ ├── mod.rs # Module exports
│ ├── auth.rs # AuthEvent
│ ├── core.rs # CoreEvent
│ ├── java.rs # JavaEvent
│ ├── launch.rs # LaunchEvent
│ └── loader.rs # LoaderEvent
└── README.md
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Licensed under the MIT License. See LICENSE for details.
Related Crates
lighty-launcher- Main launcher cratelighty-auth- Authentication systemlighty-java- Java runtime managementlighty-core- Core utilities