Copy use lighty_event::{EventBus, Event, LaunchEvent};
use lighty_launch::InstanceControl;
use lighty_core::AppState;
use lighty_launcher::prelude::*;
use lighty_java::JavaDistribution;
const QUALIFIER: &str = "com";
const ORGANIZATION: &str = "MyLauncher";
const APPLICATION: &str = "";
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let _app = AppState::new(
QUALIFIER.to_string(),
ORGANIZATION.to_string(),
APPLICATION.to_string(),
)?;
let event_bus = EventBus::new(1000);
let mut receiver = event_bus.subscribe();
tokio::spawn(async move {
while let Ok(event) = receiver.next().await {
match event {
Event::Launch(LaunchEvent::DownloadingLibraries { current, total }) => {
println!("📦 Libraries: {}/{}", current, total);
}
Event::Launch(LaunchEvent::DownloadingNatives { current, total }) => {
println!("🔧 Natives: {}/{}", current, total);
}
Event::Launch(LaunchEvent::DownloadingAssets { current, total }) => {
println!("🎨 Assets: {}/{}", current, total);
}
Event::Launch(LaunchEvent::DownloadingMods { current, total }) => {
println!("🧩 Mods: {}/{}", current, total);
}
Event::Launch(LaunchEvent::InstanceLaunched { instance_name, pid }) => {
println!("✓ Launched {} (PID: {})", instance_name, pid);
}
Event::Launch(LaunchEvent::ConsoleOutput { pid, line }) => {
print!("[{}] {}", pid, line);
}
Event::Launch(LaunchEvent::InstanceExited { pid, exit_code }) => {
match exit_code {
Some(0) => println!("✓ Instance {} exited normally", pid),
Some(code) => println!("✗ Instance {} crashed (code: {})", pid, code),
None => println!("⚠ Instance {} was killed", pid),
}
}
Event::Launch(LaunchEvent::InstanceDeleted { instance_name }) => {
println!("🗑 Deleted {}", instance_name);
}
_ => {}
}
}
});
let launcher_dir = AppState::get_project_dirs();
let mut instance = VersionBuilder::new(
"fabric-1.21",
Loader::Fabric,
"0.16.9",
"1.21.1",
launcher_dir
);
let mut auth = OfflineAuth::new("Player");
let profile = auth.authenticate(None).await?;
instance.launch(&profile, JavaDistribution::Temurin)
.run()
.await?;
// Keep alive to see console output
tokio::time::sleep(tokio::time::Duration::from_secs(120)).await;
Ok(())
}