You've already forked AstralRinth
forked from didirus/AstralRinth
String settings hooks (#82)
* added theme; env change * began refactoring * added process hook * now singular string for each hook * fixed splitting by comma to by space * profile_create function updated * prettier * added jre validator * restructured so that it doesnt look like a vec * fixed merge issue * snake case * resolved merge issues + added process events * clippy, fmt * removed unnecssary func
This commit is contained in:
@@ -2,14 +2,17 @@ use crate::api::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use theseus::prelude::*;
|
||||
|
||||
use super::TheseusSerializableError;
|
||||
|
||||
// Identical to theseus::settings::Settings except for the custom_java_args field
|
||||
// This allows us to split the custom_java_args string into a Vec<String> here and join it back into a string in the backend
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct FrontendSettings {
|
||||
pub theme: Theme,
|
||||
pub memory: MemorySettings,
|
||||
pub game_resolution: WindowSize,
|
||||
pub custom_java_args: String,
|
||||
pub custom_env_args: Vec<(String, String)>,
|
||||
pub custom_env_args: String,
|
||||
pub java_globals: JavaGlobals,
|
||||
pub default_user: Option<uuid::Uuid>,
|
||||
pub hooks: Hooks,
|
||||
@@ -23,10 +26,16 @@ pub struct FrontendSettings {
|
||||
pub async fn settings_get() -> Result<FrontendSettings> {
|
||||
let backend_settings = settings::get().await?;
|
||||
let frontend_settings = FrontendSettings {
|
||||
theme: backend_settings.theme,
|
||||
memory: backend_settings.memory,
|
||||
game_resolution: backend_settings.game_resolution,
|
||||
custom_java_args: backend_settings.custom_java_args.join(" "),
|
||||
custom_env_args: backend_settings.custom_env_args,
|
||||
custom_env_args: backend_settings
|
||||
.custom_env_args
|
||||
.into_iter()
|
||||
.map(|(s1, s2)| format!("{s1}={s2}"))
|
||||
.collect::<Vec<String>>()
|
||||
.join(" "),
|
||||
java_globals: backend_settings.java_globals,
|
||||
default_user: backend_settings.default_user,
|
||||
hooks: backend_settings.hooks,
|
||||
@@ -40,7 +49,25 @@ pub async fn settings_get() -> Result<FrontendSettings> {
|
||||
// invoke('settings_set', settings)
|
||||
#[tauri::command]
|
||||
pub async fn settings_set(settings: FrontendSettings) -> Result<()> {
|
||||
let custom_env_args: Vec<(String, String)> = settings
|
||||
.custom_env_args
|
||||
.split_whitespace()
|
||||
.map(|s| s.to_string())
|
||||
.map(|f| {
|
||||
let mut split = f.split('=');
|
||||
if let (Some(name), Some(value)) = (split.next(), split.next()) {
|
||||
Ok((name.to_string(), value.to_string()))
|
||||
} else {
|
||||
Err(TheseusSerializableError::BadEnvVars(
|
||||
"Invalid environment variable: {}".to_string(),
|
||||
)
|
||||
.into())
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<(String, String)>>>()?;
|
||||
|
||||
let backend_settings = Settings {
|
||||
theme: settings.theme,
|
||||
memory: settings.memory,
|
||||
game_resolution: settings.game_resolution,
|
||||
custom_java_args: settings
|
||||
@@ -48,7 +75,7 @@ pub async fn settings_set(settings: FrontendSettings) -> Result<()> {
|
||||
.split_whitespace()
|
||||
.map(|s| s.to_string())
|
||||
.collect(),
|
||||
custom_env_args: settings.custom_env_args,
|
||||
custom_env_args,
|
||||
java_globals: settings.java_globals,
|
||||
default_user: settings.default_user,
|
||||
hooks: settings.hooks,
|
||||
|
||||
Reference in New Issue
Block a user