mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-02 14:18:49 +00:00
feat: detail profile validation failure
This commit is contained in:
parent
a88c0ba802
commit
0c3f6e98f5
2 changed files with 69 additions and 20 deletions
|
@ -407,33 +407,67 @@ impl Profile {
|
|||
dup
|
||||
}
|
||||
|
||||
pub fn validate(&self) -> bool {
|
||||
!self.name.is_empty()
|
||||
&& self.editable
|
||||
&& !self.uuid.is_empty()
|
||||
&& !self.xrservice_path.is_empty()
|
||||
&& !self.prefix.is_empty()
|
||||
&& (!self.features.libsurvive.enabled
|
||||
pub fn validate(&self) -> Result<(), Vec<&str>> {
|
||||
let mut errors = vec![];
|
||||
// impossible
|
||||
if !self.editable {
|
||||
errors.push("You somehow managed to edit a non-editable profile. Congratulations, you found a bug! Please report it.");
|
||||
}
|
||||
// impossible
|
||||
if self.uuid.is_empty() {
|
||||
errors.push("For some reason this profile's UUID is empty. Congratulations, you found a bug! Please report it.");
|
||||
}
|
||||
if self.name.is_empty() {
|
||||
errors.push("The profile name cannot be empty.");
|
||||
}
|
||||
if self.xrservice_path.is_empty() {
|
||||
errors.push("The XR service path cannot be empty.")
|
||||
}
|
||||
if self.prefix.is_empty() {
|
||||
errors.push("The prefix path cannot be empty.")
|
||||
}
|
||||
if self.features.libsurvive.enabled
|
||||
&& (self.features.libsurvive.path.is_none()
|
||||
|| self
|
||||
.features
|
||||
.libsurvive
|
||||
.path
|
||||
.as_ref()
|
||||
.is_some_and(|p| !p.is_empty()))
|
||||
&& (!self.features.basalt.enabled
|
||||
.is_some_and(|p| p.is_empty()))
|
||||
{
|
||||
errors.push("You enabled Libsurvive, but its path is empty. Disable Libsurvive or set a path for it.")
|
||||
}
|
||||
if self.features.basalt.enabled
|
||||
&& (self.features.basalt.path.is_none()
|
||||
|| self
|
||||
.features
|
||||
.basalt
|
||||
.path
|
||||
.as_ref()
|
||||
.is_some_and(|p| !p.is_empty()))
|
||||
&& (!self.features.openhmd.enabled
|
||||
.is_some_and(|p| p.is_empty()))
|
||||
{
|
||||
errors.push(
|
||||
"You enabled Basalt, but its path is empty. Disable Basalt or set a path for it.",
|
||||
)
|
||||
}
|
||||
if self.features.openhmd.enabled
|
||||
&& (self.features.openhmd.path.is_none()
|
||||
|| self
|
||||
.features
|
||||
.openhmd
|
||||
.path
|
||||
.as_ref()
|
||||
.is_some_and(|p| !p.is_empty()))
|
||||
.is_some_and(|p| p.is_empty()))
|
||||
{
|
||||
errors.push(
|
||||
"You enabled OpenHMD, but its path is empty. Disable OpenHMD or set a path for it.",
|
||||
)
|
||||
}
|
||||
if errors.is_empty() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(errors)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn xrservice_binary(&self) -> PathBuf {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::{
|
||||
alert::alert,
|
||||
alert::alert_w_widget,
|
||||
factories::env_var_row_factory::{EnvVarModel, EnvVarModelInit},
|
||||
};
|
||||
use crate::{
|
||||
|
@ -359,17 +359,32 @@ impl SimpleComponent for ProfileEditor {
|
|||
}
|
||||
Self::Input::SaveProfile => {
|
||||
let prof = self.profile.borrow();
|
||||
if prof.validate() {
|
||||
if let Err(errors) = prof.validate() {
|
||||
alert_w_widget(
|
||||
"Profile validation failed",
|
||||
None,
|
||||
Some(
|
||||
>k::Label::builder()
|
||||
.label(
|
||||
errors
|
||||
.iter()
|
||||
.map(|e| format!(" \u{2022} {e}"))
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n"),
|
||||
)
|
||||
.wrap(true)
|
||||
.xalign(0.0)
|
||||
.max_width_chars(40)
|
||||
.build()
|
||||
.upcast(),
|
||||
),
|
||||
Some(&self.parent),
|
||||
);
|
||||
} else {
|
||||
sender
|
||||
.output(ProfileEditorOutMsg::SaveProfile(prof.clone()))
|
||||
.expect("Sender output failed");
|
||||
self.win.as_ref().unwrap().close();
|
||||
} else {
|
||||
alert(
|
||||
"Profile validation failed",
|
||||
Some("Check the values you set and try again"),
|
||||
Some(&self.parent),
|
||||
);
|
||||
}
|
||||
}
|
||||
Self::Input::EnvVarChanged(name, value) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue