Implement loading (#104)

* Implement loading

* LoadingBar

* Run linter

* Update App.vue

* Loading bar all the things

* Update SplashScreen.vue

* Update SplashScreen.vue

* Update App.vue

* initial revert

* Update Instance.vue

* revert css

* Fix instance

* More reverting

* Run lint

* Finalize changes

* Revert "Merge branch 'master' into loading"

This reverts commit 3014e765fb6fb343f3030fd8a822edd97fb2af41, reversing
changes made to b780e859d2b53a203eb3561ba3be88af083d9c15.

* Fix loading issues

* fix lint

* Revert "Revert "Merge branch 'master' into loading""

This reverts commit 971ef8466613579b7f523edbd25b692df62d0f86.

---------

Co-authored-by: Jai A <jaiagr+gpg@pm.me>
This commit is contained in:
Adrian O.V
2023-05-10 18:50:42 -04:00
committed by GitHub
parent 9be0d16f75
commit 71cf2c53f5
21 changed files with 463 additions and 188 deletions

View File

@@ -62,7 +62,6 @@ pub async fn install_minecraft(
let state = State::get().await?;
let instance_path = &canonicalize(&profile.path)?;
let metadata = state.metadata.read().await;
let version = metadata
.minecraft
.versions
@@ -72,7 +71,7 @@ pub async fn install_minecraft(
"Invalid game version: {}",
profile.metadata.game_version
)))?;
let version_jar = profile
.metadata
.loader_version
@@ -80,7 +79,7 @@ pub async fn install_minecraft(
.map_or(version.id.clone(), |it| {
format!("{}-{}", version.id.clone(), it.id.clone())
});
let loading_bar = init_or_edit_loading(
existing_loading_bar,
LoadingBarType::MinecraftDownload {
@@ -92,8 +91,8 @@ pub async fn install_minecraft(
"Downloading Minecraft",
)
.await?;
// Download version info
// Download version info (5)
let mut version_info = download::download_version_info(
&state,
version,
@@ -102,16 +101,16 @@ pub async fn install_minecraft(
Some(&loading_bar),
)
.await?;
// Download minecraft (5-90)
download::download_minecraft(&state, &version_info, &loading_bar).await?;
let client_path = state
.directories
.version_dir(&version_jar)
.join(format!("{version_jar}.jar"));
if let Some(processors) = &version_info.processors {
let client_path = state
.directories
.version_dir(&version_jar)
.join(format!("{version_jar}.jar"));
if let Some(ref mut data) = version_info.data {
processor_rules! {
data;
@@ -131,33 +130,23 @@ pub async fn install_minecraft(
client => state.directories.libraries_dir().to_string_lossy(),
server => "";
}
emit_loading(&loading_bar, 0.0, Some("Running forge processors"))
.await?;
let total_length = processors.len();
// Forge processors (90-100)
for (index, processor) in processors.iter().enumerate() {
emit_loading(
&loading_bar,
10.0 / total_length as f64,
Some(&format!(
"Running forge processor {}/{}",
index, total_length
)),
)
.await?;
if let Some(sides) = &processor.sides {
if !sides.contains(&String::from("client")) {
continue;
}
}
let cp = wrap_ref_builder!(cp = processor.classpath.clone() => {
cp.push(processor.jar.clone())
});
let child = Command::new("java")
.arg("-cp")
.arg(args::get_class_paths_jar(
@@ -190,7 +179,7 @@ pub async fn install_minecraft(
"Error running processor: {err}",
))
})?;
if !child.status.success() {
return Err(crate::ErrorKind::LauncherError(format!(
"Processor error: {}",
@@ -198,20 +187,35 @@ pub async fn install_minecraft(
))
.as_error());
}
emit_loading(
&loading_bar,
30.0 / total_length as f64,
Some(&format!(
"Running forge processor {}/{}",
index, total_length
)),
)
.await?;
}
}
}
crate::api::profile::edit(&profile.path, |prof| {
prof.installed = true;
async { Ok(()) }
})
.await?;
State::sync().await?;
emit_loading(
&loading_bar,
1.0,
Some("Finished installing"),
)
.await?;
Ok(())
}).await
}
@@ -231,11 +235,11 @@ pub async fn launch_minecraft(
if !profile.installed {
install_minecraft(profile, None).await?;
}
let state = State::get().await?;
let metadata = state.metadata.read().await;
let instance_path = &canonicalize(&profile.path)?;
let version = metadata
.minecraft
.versions
@@ -245,7 +249,7 @@ pub async fn launch_minecraft(
"Invalid game version: {}",
profile.metadata.game_version
)))?;
let version_jar = profile
.metadata
.loader_version
@@ -253,7 +257,7 @@ pub async fn launch_minecraft(
.map_or(version.id.clone(), |it| {
format!("{}-{}", version.id.clone(), it.id.clone())
});
let version_info = download::download_version_info(
&state,
version,
@@ -262,12 +266,12 @@ pub async fn launch_minecraft(
None,
)
.await?;
let client_path = state
.directories
.version_dir(&version_jar)
.join(format!("{version_jar}.jar"));
let args = version_info.arguments.clone().unwrap_or_default();
let mut command = match wrapper {
Some(hook) => {
@@ -275,9 +279,9 @@ pub async fn launch_minecraft(
}
None => Command::new(String::from(java_install.to_string_lossy())),
};
let env_args = Vec::from(env_args);
// Check if profile has a running profile, and reject running the command if it does
// Done late so a quick double call doesn't launch two instances
let existing_processes =
@@ -289,7 +293,7 @@ pub async fn launch_minecraft(
))
.as_error());
}
command
.args(
args::get_jvm_arguments(
@@ -329,14 +333,14 @@ pub async fn launch_minecraft(
.current_dir(instance_path.clone())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
// CARGO-set DYLD_LIBRARY_PATH breaks Minecraft on macOS during testing on playground
#[cfg(target_os = "macos")]
if std::env::var("CARGO").is_ok() {
command.env_remove("DYLD_FALLBACK_LIBRARY_PATH");
}
command.envs(env_args);
// Get Modrinth logs directories
let datetime_string =
chrono::Local::now().format("%Y%m%y_%H%M%S").to_string();
@@ -347,10 +351,10 @@ pub async fn launch_minecraft(
.join(&datetime_string)
};
fs::create_dir_all(&logs_dir)?;
let stdout_log_path = logs_dir.join("stdout.log");
let stderr_log_path = logs_dir.join("stderr.log");
// Create Minecraft child by inserting it into the state
// This also spawns the process and prepares the subsequent processes
let mut state_children = state.children.write().await;
@@ -364,6 +368,5 @@ pub async fn launch_minecraft(
post_exit_hook,
)
.await
}).await
}