Simple working launch

This commit is contained in:
2026-04-04 06:57:42 +02:00
parent 8f292e777d
commit 89a607f678
5 changed files with 740 additions and 89 deletions
+673 -59
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -27,3 +27,4 @@ directories = "6.0"
once_cell = "1.21" once_cell = "1.21"
tracing-subscriber = "0.3" tracing-subscriber = "0.3"
anyhow = "1.0" anyhow = "1.0"
lyceris = "1.1.3"
+64 -28
View File
@@ -1,10 +1,9 @@
use directories::ProjectDirs; use directories::ProjectDirs;
use lighty_launcher::{ use lyceris::minecraft::{
auth::{Authenticator, OfflineAuth}, config::ConfigBuilder,
java::JavaDistribution, emitter::{Emitter, Event},
launch::Launch, install::install,
loaders::Loader, launch::launch,
version::VersionBuilder,
}; };
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@@ -14,33 +13,70 @@ static LAUNCHER_DIR: Lazy<ProjectDirs> = Lazy::new(|| {
}); });
#[tauri::command] #[tauri::command]
pub async fn launch() -> Result<(), String> { pub async fn launch_game() -> Result<(), String> {
println!("Launcher directory: {:?}", LAUNCHER_DIR); // Emitter uses `EventEmitter` inside of it
// and it uses tokio::Mutex for locking.
// That causes emitter methods to be async.
let emitter = Emitter::default();
tracing_subscriber::fmt::init(); // Single download progress event send when
// a file is being downloaded.
emitter
.on(
Event::SingleDownloadProgress,
|(path, current, total): (String, u64, u64)| {
println!("Downloading {} - {}/{}", path, current, total);
},
)
.await;
// Authenticate // Multiple download progress event send when
let mut auth = OfflineAuth::new("PlayerName"); // multiple files are being downloaded.
let profile = auth // Java, libraries and assets are downloaded in parallel and
.authenticate() // this event is triggered for each file.
emitter
.on(
Event::MultipleDownloadProgress,
|(_, current, total, _): (String, u64, u64, String)| {
println!("Downloading {}/{}", current, total);
},
)
.await;
// Console event send when a line is printed to the console.
// It uses a seperated tokio thread to handle this operation.
emitter
.on(Event::Console, |line: String| {
println!("Line: {}", line);
})
.await;
let current_dir = LAUNCHER_DIR.data_dir();
let config = ConfigBuilder::new(
current_dir.join("game"),
"1.21.4".into(),
lyceris::auth::AuthMethod::Offline {
username: "Lyceris".into(),
// If none given, it will be generated.
uuid: None,
},
)
.build();
// Install method also checks for broken files
// and downloads them again if they are broken.
install(&config, Some(&emitter))
.await .await
.map_err(|e| format!("Authentication failed: {}", e))?; .map_err(|e| e.to_string())?;
// Create version instance // This method never downloads any file and just runs the game.
let mut version = VersionBuilder::new( launch(&config, Some(&emitter))
"vanilla-1.21.1",
Loader::Vanilla,
"",
"1.21.1",
&LAUNCHER_DIR,
);
// Launch the game
version
.launch(&profile, JavaDistribution::Temurin)
.run()
.await .await
.map_err(|e| format!("Launch failed: {}", e))?; .map_err(|e| e.to_string())?
.wait()
.await
.map_err(|e| e.to_string())?;
Ok(()) Ok(())
} }
+1 -1
View File
@@ -15,7 +15,7 @@ fn main() {
install_mod, install_mod,
get_settings, get_settings,
update_settings, update_settings,
saturn_launcher_lib::launcher::launch saturn_launcher_lib::launcher::launch_game
]) ])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
+1 -1
View File
@@ -9,5 +9,5 @@ export async function authenticate() {
} }
export async function launch() { export async function launch() {
return await invoke("launch"); return await invoke("launch_game");
} }