Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

362 autostart in dashboard #391

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions core/src/implementations/minecraft/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/implementations/minecraft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
31 changes: 25 additions & 6 deletions core/src/traits/t_configurable/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,16 +666,35 @@
setting_id: &str,
value: Option<ConfigurableValue>,
) -> 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"),
})
}
}

Check warning on line 685 in core/src/traits/t_configurable/manifest.rs

View workflow job for this annotation

GitHub Actions / clippy

this `else { if .. }` block can be collapsed

warning: this `else { if .. }` block can be collapsed --> core/src/traits/t_configurable/manifest.rs:676:16 | 676 | } else { | ________________^ 677 | | if let Some(setting) = self.get_setting_mut(section_id, setting_id) { 678 | | setting.set_optional_value(value) 679 | | } else { ... | 684 | | } 685 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if = note: `#[warn(clippy::collapsible_else_if)]` on by default help: collapse nested if block | 676 ~ } else if let Some(setting) = self.get_setting_mut(section_id, setting_id) { 677 + setting.set_optional_value(value) 678 + } else { 679 + Err(Error { 680 + kind: ErrorKind::NotFound, 681 + source: eyre!("Setting not found"), 682 + }) 683 + } |
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
29 changes: 29 additions & 0 deletions dashboard/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }),
],
Expand Down
Loading