Profile bindings (#55)

* basic framework. still has errors

* added functionality for main endpoints + some structuring

* formatting

* unused code

* mimicked CLI function with wait_for process

* made PR changes, added playground

* cargo fmt

* removed missed println

* misc tests fixes

* cargo fmt

* added windows support

* cargo fmt

* all OS use dunce

* restructured profile slightly; fixed mac bug

* profile changes, new main.rs

* fixed requested pr + canonicaliation bug

* fixed regressed bug in ui

* fixed regressed bugs

* fixed git error

* typo

* ran prettier

* clippy

* playground clippy

* ported profile loading fix

* profile change for real, url println and clippy

* PR changes

---------

Co-authored-by: Wyatt <wyatt@modrinth.com>
This commit is contained in:
Wyatt Verchere
2023-03-31 11:00:43 -07:00
committed by GitHub
parent 24ba986cf1
commit f48959a816
30 changed files with 857 additions and 80 deletions

View File

@@ -7,8 +7,12 @@ use daedalus as d;
use std::{
future::Future,
path::{Path, PathBuf},
sync::Arc,
};
use tokio::{
process::{Child, Command},
sync::RwLock,
};
use tokio::process::{Child, Command};
/// Add a profile to the in-memory state
#[tracing::instrument]
@@ -105,11 +109,12 @@ pub async fn list(
}
/// Run Minecraft using a profile
/// Returns Arc pointer to RwLock to Child
#[tracing::instrument(skip_all)]
pub async fn run(
path: &Path,
credentials: &crate::auth::Credentials,
) -> crate::Result<Child> {
) -> crate::Result<Arc<RwLock<Child>>> {
let state = State::get().await.unwrap();
let settings = state.settings.read().await;
let profile = get(path).await?.ok_or_else(|| {
@@ -199,7 +204,7 @@ pub async fn run(
let memory = profile.memory.unwrap_or(settings.memory);
let resolution = profile.resolution.unwrap_or(settings.game_resolution);
crate::launcher::launch_minecraft(
let mc_process = crate::launcher::launch_minecraft(
&profile.metadata.game_version,
&profile.metadata.loader_version,
&profile.path,
@@ -210,7 +215,18 @@ pub async fn run(
&resolution,
credentials,
)
.await
.await?;
// Insert child into state
let mut state_children = state.children.write().await;
let pid = mc_process.id().ok_or_else(|| {
crate::ErrorKind::LauncherError(
"Process failed to stay open.".to_string(),
)
})?;
let child_arc = state_children.insert(pid, mc_process);
Ok(child_arc)
}
#[tracing::instrument]