added settings API + fixed bug (#62)

* added settings API + fixed bug

* removed redundant API funcs

* comment clarifications

---------

Co-authored-by: Wyatt <wyatt@modrinth.com>
This commit is contained in:
Wyatt Verchere
2023-04-03 13:46:04 -07:00
committed by GitHub
parent 6a05276a21
commit a13b7a2566
12 changed files with 140 additions and 22 deletions

View File

@@ -2,6 +2,7 @@
pub mod auth;
pub mod profile;
pub mod profile_create;
pub mod settings;
pub mod data {
pub use crate::state::{
@@ -15,6 +16,6 @@ pub mod prelude {
auth::{self, Credentials},
data::*,
profile::{self, Profile},
profile_create, State,
profile_create, settings, State,
};
}

View File

@@ -204,12 +204,15 @@ pub async fn run(
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 mc_process = crate::launcher::launch_minecraft(
&profile.metadata.game_version,
&profile.metadata.loader_version,
&profile.path,
java_install,
java_args,
env_args,
wrapper,
&memory,
&resolution,

View File

@@ -0,0 +1,24 @@
//! Theseus profile management interface
pub use crate::{
state::{
Hooks, JavaSettings, MemorySettings, Profile, Settings, WindowSize,
},
State,
};
/// Gets entire settings
#[tracing::instrument]
pub async fn get() -> crate::Result<Settings> {
let state = State::get().await?;
let settings = state.settings.read().await;
Ok(settings.clone())
}
/// Sets entire settings
#[tracing::instrument]
pub async fn set(settings: Settings) -> crate::Result<()> {
let state = State::get().await?;
// Replaces the settings struct in the RwLock with the passed argument
*state.settings.write().await = settings;
Ok(())
}

View File

@@ -53,6 +53,7 @@ pub async fn launch_minecraft(
instance_path: &Path,
java_install: &Path,
java_args: &[String],
env_args: &[(String, String)],
wrapper: &Option<String>,
memory: &st::MemorySettings,
resolution: &st::WindowSize,
@@ -173,6 +174,8 @@ pub async fn launch_minecraft(
None => Command::new(String::from(java_install.to_string_lossy())),
};
let env_args = Vec::from(env_args);
command
.args(
args::get_jvm_arguments(
@@ -213,6 +216,7 @@ pub async fn launch_minecraft(
)
.current_dir(instance_path.clone())
.env_clear()
.envs(env_args)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit());

View File

@@ -17,6 +17,7 @@ pub struct Settings {
pub memory: MemorySettings,
pub game_resolution: WindowSize,
pub custom_java_args: Vec<String>,
pub custom_env_args: Vec<(String, String)>,
pub java_8_path: Option<PathBuf>,
pub java_17_path: Option<PathBuf>,
pub default_user: Option<uuid::Uuid>,
@@ -31,6 +32,7 @@ impl Default for Settings {
memory: MemorySettings::default(),
game_resolution: WindowSize::default(),
custom_java_args: Vec::new(),
custom_env_args: Vec::new(),
java_8_path: None,
java_17_path: None,
default_user: None,