diff --git a/core/src/implementations/minecraft/configurable.rs b/core/src/implementations/minecraft/configurable.rs index 9f27a800..7ccb7499 100644 --- a/core/src/implementations/minecraft/configurable.rs +++ b/core/src/implementations/minecraft/configurable.rs @@ -97,16 +97,20 @@ impl TConfigurable for MinecraftInstance { } async fn set_auto_start(&self, auto_start: bool) -> Result<(), Error> { + let _ = self.configurable_manifest.lock().await.set_auto_start(auto_start); self.config.lock().await.auto_start = auto_start; self.auto_start.store(auto_start, atomic::Ordering::Relaxed); - self.write_config_to_file().await + self.write_config_to_file().await?; + Ok(()) } async fn set_restart_on_crash(&self, restart_on_crash: bool) -> Result<(), Error> { + let _ = self.configurable_manifest.lock().await.set_restart_on_crash(restart_on_crash); self.config.lock().await.restart_on_crash = restart_on_crash; self.auto_start .store(restart_on_crash, atomic::Ordering::Relaxed); - self.write_config_to_file().await + self.write_config_to_file().await?; + Ok(()) } async fn change_version(&self, version: String) -> Result<(), Error> { @@ -188,13 +192,32 @@ impl TConfigurable for MinecraftInstance { value: ConfigurableValue, ) -> Result<(), Error> { let _ = self.read_properties().await; - self.configurable_manifest - .lock() - .await - .update_setting_value(section_id, setting_id, value.clone())?; - self.sync_configurable_to_restore_config().await; - self.write_config_to_file().await?; - self.write_properties_to_file().await + if section_id == "auto_settings" { + match value { + ConfigurableValue::Boolean(value) => { + if setting_id == "auto_start" { + let _ = self.set_auto_start(value).await; + } else { + let _ = self.set_restart_on_crash(value).await; + } + Ok(()) + }, + _ => { + Err(Error { + kind: ErrorKind::NotFound, + source: eyre!("Invalid value"), + }) + } + } + } else { + self.configurable_manifest + .lock() + .await + .update_setting_value(section_id, setting_id, value.clone())?; + self.sync_configurable_to_restore_config().await; + self.write_config_to_file().await?; + self.write_properties_to_file().await + } } } diff --git a/core/src/implementations/minecraft/mod.rs b/core/src/implementations/minecraft/mod.rs index 72d36a52..9b6a9165 100644 --- a/core/src/implementations/minecraft/mod.rs +++ b/core/src/implementations/minecraft/mod.rs @@ -423,7 +423,7 @@ impl MinecraftInstance { server_properties_section_manifest, ); - ConfigurableManifest::new(false, false, setting_sections) + ConfigurableManifest::new(restore_config.auto_start, restore_config.restart_on_crash, setting_sections) } pub async fn new( diff --git a/core/src/traits/t_configurable/manifest.rs b/core/src/traits/t_configurable/manifest.rs index 29fcb1d8..e0825004 100644 --- a/core/src/traits/t_configurable/manifest.rs +++ b/core/src/traits/t_configurable/manifest.rs @@ -666,16 +666,35 @@ impl ConfigurableManifest { setting_id: &str, value: Option, ) -> Result<(), Error> { - if let Some(setting) = self.get_setting_mut(section_id, setting_id) { - setting.set_optional_value(value) + if section_id == "auto_settings" { + if setting_id == "auto_start" { + self.auto_start = value.is_some(); + } else { + self.restart_on_crash = value.is_some(); + } + Ok(()) } else { - Err(Error { - kind: ErrorKind::NotFound, - source: eyre!("Setting not found"), - }) + if let Some(setting) = self.get_setting_mut(section_id, setting_id) { + setting.set_optional_value(value) + } else { + Err(Error { + kind: ErrorKind::NotFound, + source: eyre!("Setting not found"), + }) + } } } + pub fn set_auto_start(&mut self, value: bool) -> Result<(), Error> { + self.auto_start = value; + Ok(()) + } + + pub fn set_restart_on_crash(&mut self, value: bool) -> Result<(), Error> { + self.restart_on_crash = value; + Ok(()) + } + pub fn set_setting(&mut self, section_id: &str, setting: SettingManifest) -> Result<(), Error> { if let Some(section) = self.setting_sections.get_mut(section_id) { section.set_setting(setting) diff --git a/dashboard/src/components/Instance/InstanceSettingsCreate/SettingObject.ts b/dashboard/src/components/Instance/InstanceSettingsCreate/SettingObject.ts index ee4dd815..5a5dae3f 100644 --- a/dashboard/src/components/Instance/InstanceSettingsCreate/SettingObject.ts +++ b/dashboard/src/components/Instance/InstanceSettingsCreate/SettingObject.ts @@ -83,6 +83,35 @@ export const iterateSections = (manifest: ConfigurableManifest) => { const section = manifest['setting_sections'][sectionKey]; fieldSections.push(generateSectionDataObject(section)); }); + console.log(manifest) + const auto_settings: SectionFieldObject = { + name: "Auto Settings", + section_id: 'auto_settings', + description: 'Automatically configure your server.', + settings: { + auto_start: { + name: 'Auto Start', + type: 'toggle', + value: { + type: "Boolean", + value: manifest['auto_start'] + }, + description: 'The instance will start automatically when the application starts', + is_mutable: true + }, + restart_on_crash: { + name: 'Restart on crash', + type: 'toggle', + value: { + type: "Boolean", + value: manifest['restart_on_crash'] + }, + description: 'The instance will restart automatically if it crashes', + is_mutable: true + } + } + } + fieldSections.push(auto_settings); return fieldSections; }; diff --git a/dashboard/tailwind.config.js b/dashboard/tailwind.config.js index 062a6817..3ad69b31 100644 --- a/dashboard/tailwind.config.js +++ b/dashboard/tailwind.config.js @@ -106,12 +106,41 @@ module.exports = { spacing: 'margin, padding', dimensions: 'height, width', }, + scrollbarGutter: { + 'stable': 'stable', + 'both': 'both-edges', + 'force': 'force', + 'force-stable': 'force stable', + 'force-both': 'force both-edges', + } }, }, plugins: [ function ({ addVariant }) { addVariant('child', '& > *'); }, + function ({ addUtilities }) { + addUtilities({ + '.scrollbar-gutter-auto': { + 'scrollbar-gutter': 'auto', + }, + '.scrollbar-gutter-stable': { + 'scrollbar-gutter': 'stable', + }, + '.scrollbar-gutter-both': { + 'scrollbar-gutter': 'both-edges', + }, + '.scrollbar-gutter-force': { + 'scrollbar-gutter': 'force', + }, + '.scrollbar-gutter-force-stable': { + 'scrollbar-gutter': 'force stable', + }, + '.scrollbar-gutter-force-both': { + 'scrollbar-gutter': 'force both-edges', + }, + }); + }, require('@tailwindcss/container-queries'), require('@headlessui/tailwindcss')({ prefix: 'ui' }), ],