Debug pin macro (#118)

* debug pin macro

* Added debug pinning macro

* working on windows

* removed remaining box pins
This commit is contained in:
Wyatt Verchere
2023-05-18 10:31:52 -07:00
committed by GitHub
parent 0801d7a145
commit 16407060f0
35 changed files with 1133 additions and 990 deletions

View File

@@ -123,47 +123,48 @@ pub async fn install(path: &Path) -> crate::Result<()> {
Ok(())
}
#[tracing::instrument]
#[theseus_macros::debug_pin]
pub async fn update_all(profile_path: &Path) -> crate::Result<()> {
Box::pin(async move {
if let Some(profile) = get(profile_path, None).await? {
let loading_bar = init_loading(
LoadingBarType::ProfileUpdate {
profile_path: profile.path.clone(),
profile_name: profile.metadata.name.clone(),
},
100.0,
"Updating profile",
)
.await?;
if let Some(profile) = get(profile_path, None).await? {
let loading_bar = init_loading(
LoadingBarType::ProfileUpdate {
profile_path: profile.path.clone(),
profile_name: profile.metadata.name.clone(),
},
100.0,
"Updating profile",
)
.await?;
use futures::StreamExt;
loading_try_for_each_concurrent(
futures::stream::iter(profile.projects.keys())
.map(Ok::<&PathBuf, crate::Error>),
None,
Some(&loading_bar),
100.0,
profile.projects.keys().len(),
None,
|project| async move {
let _ = update_project(profile_path, project).await?;
use futures::StreamExt;
loading_try_for_each_concurrent(
futures::stream::iter(profile.projects.keys())
.map(Ok::<&PathBuf, crate::Error>),
None,
Some(&loading_bar),
100.0,
profile.projects.keys().len(),
None,
|project| async move {
let _ = update_project(profile_path, project).await?;
Ok(())
},
)
.await?;
Ok(())
},
)
.await?;
Ok(())
} else {
Err(crate::ErrorKind::UnmanagedProfileError(
profile_path.display().to_string(),
)
.as_error())
}
})
.await
Ok(())
} else {
Err(crate::ErrorKind::UnmanagedProfileError(
profile_path.display().to_string(),
)
.as_error())
}
}
#[tracing::instrument]
#[theseus_macros::debug_pin]
pub async fn update_project(
profile_path: &Path,
project_path: &Path,
@@ -304,113 +305,108 @@ pub async fn remove_project(
/// failing with an error if no credentials are available
#[tracing::instrument]
pub async fn run(path: &Path) -> crate::Result<Arc<RwLock<MinecraftChild>>> {
Box::pin(async move {
let state = State::get().await?;
let state = State::get().await?;
// Get default account and refresh credentials (preferred way to log in)
let default_account = state.settings.read().await.default_user;
let credentials = if let Some(default_account) = default_account {
refresh(default_account).await?
// Get default account and refresh credentials (preferred way to log in)
let default_account = state.settings.read().await.default_user;
let credentials = if let Some(default_account) = default_account {
refresh(default_account).await?
} else {
// If no default account, try to use a logged in account
let users = auth::users().await?;
let last_account = users.first();
if let Some(last_account) = last_account {
refresh(last_account.id).await?
} else {
// If no default account, try to use a logged in account
let users = auth::users().await?;
let last_account = users.first();
if let Some(last_account) = last_account {
refresh(last_account.id).await?
} else {
return Err(crate::ErrorKind::NoCredentialsError.as_error());
}
};
run_credentials(path, &credentials).await
})
.await
return Err(crate::ErrorKind::NoCredentialsError.as_error());
}
};
run_credentials(path, &credentials).await
}
/// Run Minecraft using a profile, and credentials for authentication
/// Returns Arc pointer to RwLock to Child
#[tracing::instrument]
#[theseus_macros::debug_pin]
pub async fn run_credentials(
path: &Path,
credentials: &auth::Credentials,
) -> crate::Result<Arc<RwLock<MinecraftChild>>> {
Box::pin(async move {
let state = State::get().await?;
let settings = state.settings.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 {}!",
path.display()
))
})?;
let state = State::get().await?;
let settings = state.settings.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 {}!",
path.display()
))
})?;
let pre_launch_hooks =
&profile.hooks.as_ref().unwrap_or(&settings.hooks).pre_launch;
if let Some(hook) = pre_launch_hooks {
// TODO: hook parameters
let mut cmd = hook.split(' ');
if let Some(command) = cmd.next() {
let result = Command::new(command)
.args(&cmd.collect::<Vec<&str>>())
.current_dir(path)
.spawn()?
.wait()
.await?;
let pre_launch_hooks =
&profile.hooks.as_ref().unwrap_or(&settings.hooks).pre_launch;
if let Some(hook) = pre_launch_hooks {
// TODO: hook parameters
let mut cmd = hook.split(' ');
if let Some(command) = cmd.next() {
let result = Command::new(command)
.args(&cmd.collect::<Vec<&str>>())
.current_dir(path)
.spawn()?
.wait()
.await?;
if !result.success() {
return Err(crate::ErrorKind::LauncherError(format!(
"Non-zero exit code for pre-launch hook: {}",
result.code().unwrap_or(-1)
))
.as_error());
}
if !result.success() {
return Err(crate::ErrorKind::LauncherError(format!(
"Non-zero exit code for pre-launch hook: {}",
result.code().unwrap_or(-1)
))
.as_error());
}
}
}
let java_args = profile
.java
.as_ref()
.and_then(|it| it.extra_arguments.as_ref())
.unwrap_or(&settings.custom_java_args);
let java_args = profile
.java
.as_ref()
.and_then(|it| it.extra_arguments.as_ref())
.unwrap_or(&settings.custom_java_args);
let wrapper = profile
.hooks
.as_ref()
.map_or(&settings.hooks.wrapper, |it| &it.wrapper);
let wrapper = profile
.hooks
.as_ref()
.map_or(&settings.hooks.wrapper, |it| &it.wrapper);
let memory = profile.memory.unwrap_or(settings.memory);
let resolution = profile.resolution.unwrap_or(settings.game_resolution);
let memory = profile.memory.unwrap_or(settings.memory);
let resolution = profile.resolution.unwrap_or(settings.game_resolution);
let env_args = &settings.custom_env_args;
let env_args = &settings.custom_env_args;
// Post post exit hooks
let post_exit_hook =
&profile.hooks.as_ref().unwrap_or(&settings.hooks).post_exit;
// Post post exit hooks
let post_exit_hook =
&profile.hooks.as_ref().unwrap_or(&settings.hooks).post_exit;
let post_exit_hook = if let Some(hook) = post_exit_hook {
let mut cmd = hook.split(' ');
if let Some(command) = cmd.next() {
let mut command = Command::new(command);
command.args(&cmd.collect::<Vec<&str>>()).current_dir(path);
Some(command)
} else {
None
}
let post_exit_hook = if let Some(hook) = post_exit_hook {
let mut cmd = hook.split(' ');
if let Some(command) = cmd.next() {
let mut command = Command::new(command);
command.args(&cmd.collect::<Vec<&str>>()).current_dir(path);
Some(command)
} else {
None
};
}
} else {
None
};
let mc_process = crate::launcher::launch_minecraft(
java_args,
env_args,
wrapper,
&memory,
&resolution,
credentials,
post_exit_hook,
&profile,
)
.await?;
Ok(mc_process)
})
.await
let mc_process = crate::launcher::launch_minecraft(
java_args,
env_args,
wrapper,
&memory,
&resolution,
credentials,
post_exit_hook,
&profile,
)
.await?;
Ok(mc_process)
}