You've already forked AstralRinth
forked from didirus/AstralRinth
Various final backend fixes (#117)
* Various final backend fixes * Add FS watching * run lint * Autodetect installed jars
This commit is contained in:
@@ -5,7 +5,6 @@ use crate::state::ProjectMetadata;
|
||||
use crate::{
|
||||
auth::{self, refresh},
|
||||
event::{emit::emit_profile, ProfilePayloadType},
|
||||
launcher::download,
|
||||
state::MinecraftChild,
|
||||
};
|
||||
pub use crate::{
|
||||
@@ -109,40 +108,10 @@ pub async fn list(
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Query + sync profile's projects with the UI from the FS
|
||||
#[tracing::instrument]
|
||||
pub async fn sync(path: &Path) -> crate::Result<()> {
|
||||
Box::pin({
|
||||
async move {
|
||||
let state = State::get().await?;
|
||||
let result = {
|
||||
let mut profiles: tokio::sync::RwLockWriteGuard<
|
||||
crate::state::Profiles,
|
||||
> = state.profiles.write().await;
|
||||
|
||||
if let Some(profile) = profiles.0.get_mut(path) {
|
||||
profile.sync_projects().await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(crate::ErrorKind::UnmanagedProfileError(
|
||||
path.display().to_string(),
|
||||
)
|
||||
.as_error())
|
||||
}
|
||||
};
|
||||
State::sync().await?;
|
||||
result
|
||||
}
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// Installs/Repairs a profile
|
||||
#[tracing::instrument]
|
||||
pub async fn install(path: &Path) -> crate::Result<()> {
|
||||
let profile = get(path, None).await?;
|
||||
|
||||
if let Some(profile) = profile {
|
||||
if let Some(profile) = get(path, None).await? {
|
||||
crate::launcher::install_minecraft(&profile, None).await?;
|
||||
} else {
|
||||
return Err(crate::ErrorKind::UnmanagedProfileError(
|
||||
@@ -155,11 +124,8 @@ pub async fn install(path: &Path) -> crate::Result<()> {
|
||||
}
|
||||
|
||||
pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
|
||||
let state = State::get().await?;
|
||||
Box::pin(async move {
|
||||
let mut profiles = state.profiles.write().await;
|
||||
|
||||
if let Some(profile) = profiles.0.get_mut(profile_path) {
|
||||
if let Some(profile) = get(profile_path, None).await? {
|
||||
let loading_bar = init_loading(
|
||||
LoadingBarType::ProfileUpdate {
|
||||
profile_path: profile.path.clone(),
|
||||
@@ -187,8 +153,6 @@ pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
|
||||
)
|
||||
.await?;
|
||||
|
||||
profile.sync_projects().await?;
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err(crate::ErrorKind::UnmanagedProfileError(
|
||||
@@ -204,10 +168,7 @@ pub async fn update_project(
|
||||
profile_path: &Path,
|
||||
project_path: &Path,
|
||||
) -> crate::Result<PathBuf> {
|
||||
let state = State::get().await?;
|
||||
let mut profiles = state.profiles.write().await;
|
||||
|
||||
if let Some(profile) = profiles.0.get_mut(profile_path) {
|
||||
if let Some(profile) = get(profile_path, None).await? {
|
||||
if let Some(project) = profile.projects.get(project_path) {
|
||||
if let ProjectMetadata::Modrinth {
|
||||
update_version: Some(update_version),
|
||||
@@ -222,15 +183,20 @@ pub async fn update_project(
|
||||
profile.remove_project(project_path, Some(true)).await?;
|
||||
}
|
||||
|
||||
let value = profile.projects.remove(project_path);
|
||||
if let Some(mut project) = value {
|
||||
if let ProjectMetadata::Modrinth {
|
||||
ref mut version, ..
|
||||
} = project.metadata
|
||||
{
|
||||
*version = Box::new(new_version);
|
||||
let state = State::get().await?;
|
||||
let mut profiles = state.profiles.write().await;
|
||||
if let Some(profile) = profiles.0.get_mut(project_path) {
|
||||
let value = profile.projects.remove(project_path);
|
||||
if let Some(mut project) = value {
|
||||
if let ProjectMetadata::Modrinth {
|
||||
ref mut version,
|
||||
..
|
||||
} = project.metadata
|
||||
{
|
||||
*version = Box::new(new_version);
|
||||
}
|
||||
profile.projects.insert(path.clone(), project);
|
||||
}
|
||||
profile.projects.insert(path.clone(), project);
|
||||
}
|
||||
|
||||
return Ok(path);
|
||||
@@ -249,57 +215,15 @@ pub async fn update_project(
|
||||
}
|
||||
}
|
||||
|
||||
/// Replaces a project given a new version ID
|
||||
pub async fn replace_project(
|
||||
profile_path: &Path,
|
||||
project: &Path,
|
||||
version_id: String,
|
||||
) -> crate::Result<PathBuf> {
|
||||
let state = State::get().await?;
|
||||
let mut profiles = state.profiles.write().await;
|
||||
|
||||
if let Some(profile) = profiles.0.get_mut(profile_path) {
|
||||
let (path, new_version) =
|
||||
profile.add_project_version(version_id).await?;
|
||||
|
||||
if path != project {
|
||||
profile.remove_project(project, Some(true)).await?;
|
||||
}
|
||||
|
||||
let value = profile.projects.remove(project);
|
||||
if let Some(mut project) = value {
|
||||
if let ProjectMetadata::Modrinth {
|
||||
ref mut version, ..
|
||||
} = project.metadata
|
||||
{
|
||||
*version = Box::new(new_version);
|
||||
}
|
||||
profile.projects.insert(path.clone(), project);
|
||||
}
|
||||
|
||||
Ok(path)
|
||||
} else {
|
||||
Err(crate::ErrorKind::UnmanagedProfileError(
|
||||
profile_path.display().to_string(),
|
||||
)
|
||||
.as_error())
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a project from a version
|
||||
#[tracing::instrument]
|
||||
pub async fn add_project_from_version(
|
||||
profile_path: &Path,
|
||||
version_id: String,
|
||||
) -> crate::Result<PathBuf> {
|
||||
let state = State::get().await?;
|
||||
let mut profiles = state.profiles.write().await;
|
||||
|
||||
if let Some(profile) = profiles.0.get_mut(profile_path) {
|
||||
if let Some(profile) = get(profile_path, None).await? {
|
||||
let (path, _) = profile.add_project_version(version_id).await?;
|
||||
|
||||
Profile::sync_projects_task(profile.path.clone());
|
||||
|
||||
Ok(path)
|
||||
} else {
|
||||
Err(crate::ErrorKind::UnmanagedProfileError(
|
||||
@@ -316,10 +240,7 @@ pub async fn add_project_from_path(
|
||||
path: &Path,
|
||||
project_type: Option<String>,
|
||||
) -> crate::Result<PathBuf> {
|
||||
let state = State::get().await?;
|
||||
let mut profiles = state.profiles.write().await;
|
||||
|
||||
if let Some(profile) = profiles.0.get_mut(profile_path) {
|
||||
if let Some(profile) = get(profile_path, None).await? {
|
||||
let file = fs::read(path).await?;
|
||||
let file_name = path
|
||||
.file_name()
|
||||
@@ -335,8 +256,6 @@ pub async fn add_project_from_path(
|
||||
)
|
||||
.await?;
|
||||
|
||||
Profile::sync_projects_task(profile.path.clone());
|
||||
|
||||
Ok(path)
|
||||
} else {
|
||||
Err(crate::ErrorKind::UnmanagedProfileError(
|
||||
@@ -352,10 +271,7 @@ pub async fn toggle_disable_project(
|
||||
profile: &Path,
|
||||
project: &Path,
|
||||
) -> crate::Result<()> {
|
||||
let state = State::get().await?;
|
||||
let mut profiles = state.profiles.write().await;
|
||||
|
||||
if let Some(profile) = profiles.0.get_mut(profile) {
|
||||
if let Some(profile) = get(profile, None).await? {
|
||||
profile.toggle_disable_project(project).await?;
|
||||
|
||||
Ok(())
|
||||
@@ -373,10 +289,7 @@ pub async fn remove_project(
|
||||
profile: &Path,
|
||||
project: &Path,
|
||||
) -> crate::Result<()> {
|
||||
let state = State::get().await?;
|
||||
let mut profiles = state.profiles.write().await;
|
||||
|
||||
if let Some(profile) = profiles.0.get_mut(profile) {
|
||||
if let Some(profile) = get(profile, None).await? {
|
||||
profile.remove_project(project, None).await?;
|
||||
|
||||
Ok(())
|
||||
@@ -423,7 +336,6 @@ pub async fn run_credentials(
|
||||
Box::pin(async move {
|
||||
let state = State::get().await?;
|
||||
let settings = state.settings.read().await;
|
||||
let metadata = state.metadata.read().await;
|
||||
let profile = get(path, None).await?.ok_or_else(|| {
|
||||
crate::ErrorKind::OtherError(format!(
|
||||
"Tried to run a nonexistent or unloaded profile at path {}!",
|
||||
@@ -431,25 +343,6 @@ pub async fn run_credentials(
|
||||
))
|
||||
})?;
|
||||
|
||||
let version = metadata
|
||||
.minecraft
|
||||
.versions
|
||||
.iter()
|
||||
.find(|it| it.id == profile.metadata.game_version)
|
||||
.ok_or_else(|| {
|
||||
crate::ErrorKind::LauncherError(format!(
|
||||
"Invalid or unknown Minecraft version: {}",
|
||||
profile.metadata.game_version
|
||||
))
|
||||
})?;
|
||||
let version_info = download::download_version_info(
|
||||
&state,
|
||||
version,
|
||||
profile.metadata.loader_version.as_ref(),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
let pre_launch_hooks =
|
||||
&profile.hooks.as_ref().unwrap_or(&settings.hooks).pre_launch;
|
||||
if let Some(hook) = pre_launch_hooks {
|
||||
@@ -473,49 +366,6 @@ pub async fn run_credentials(
|
||||
}
|
||||
}
|
||||
|
||||
let java_version = match profile.java {
|
||||
// Load profile-specific Java implementation choice
|
||||
// (This defaults to Daedalus-decided key on init, but can be changed by the user)
|
||||
Some(JavaSettings {
|
||||
jre_key: Some(ref jre_key),
|
||||
..
|
||||
}) => settings.java_globals.get(jre_key),
|
||||
// Fall back to Daedalus-decided key if no profile-specific key is set
|
||||
_ => {
|
||||
match version_info
|
||||
.java_version
|
||||
.as_ref()
|
||||
.map(|it| it.major_version)
|
||||
.unwrap_or(0)
|
||||
{
|
||||
0..=16 => settings
|
||||
.java_globals
|
||||
.get(&crate::jre::JAVA_8_KEY.to_string()),
|
||||
17 => settings
|
||||
.java_globals
|
||||
.get(&crate::jre::JAVA_17_KEY.to_string()),
|
||||
_ => settings
|
||||
.java_globals
|
||||
.get(&crate::jre::JAVA_18PLUS_KEY.to_string()),
|
||||
}
|
||||
}
|
||||
};
|
||||
let java_version = java_version.as_ref().ok_or_else(|| {
|
||||
crate::ErrorKind::LauncherError(format!(
|
||||
"No Java stored for version {}",
|
||||
version_info.java_version.map_or(8, |it| it.major_version),
|
||||
))
|
||||
})?;
|
||||
|
||||
// Get the path to the Java executable from the chosen Java implementation key
|
||||
let java_install: &Path = &PathBuf::from(&java_version.path);
|
||||
if !java_install.exists() {
|
||||
return Err(crate::ErrorKind::LauncherError(format!(
|
||||
"Could not find Java install: {}",
|
||||
java_install.display()
|
||||
))
|
||||
.as_error());
|
||||
}
|
||||
let java_args = profile
|
||||
.java
|
||||
.as_ref()
|
||||
@@ -550,7 +400,6 @@ pub async fn run_credentials(
|
||||
};
|
||||
|
||||
let mc_process = crate::launcher::launch_minecraft(
|
||||
java_install,
|
||||
java_args,
|
||||
env_args,
|
||||
wrapper,
|
||||
|
||||
Reference in New Issue
Block a user