fix: avoid crashing on non-numeric input in fan curve editor

This commit is contained in:
Ilya Zlobintsev 2024-08-16 09:18:15 +03:00
parent 48c4a8a102
commit fe0f8b5e52

View File

@ -34,7 +34,7 @@ impl PointAdjustment {
temperature_selector.connect_input(|spin| { temperature_selector.connect_input(|spin| {
let text = spin.text(); let text = spin.text();
let temp = text.trim_end_matches("°C"); let temp = text.trim_end_matches("°C");
Some(Ok(temp.parse::<f64>().unwrap())) Some(Ok(temp.parse::<f64>().unwrap_or_else(|_| spin.value())))
}); });
temperature_selector.connect_output(|spin| { temperature_selector.connect_output(|spin| {
let text = format!("{}°C", spin.value_as_int()); let text = format!("{}°C", spin.value_as_int());
@ -45,7 +45,10 @@ impl PointAdjustment {
ratio_selector.connect_input(|spin| { ratio_selector.connect_input(|spin| {
let text = spin.text(); let text = spin.text();
let percentage = text.trim_end_matches('%'); let percentage = text.trim_end_matches('%');
Some(Ok(percentage.parse::<f64>().unwrap() / 100.0)) Some(Ok(percentage
.parse::<f64>()
.map(|value| value / 100.0)
.unwrap_or_else(|_| spin.value())))
}); });
ratio_selector.connect_output(|spin| { ratio_selector.connect_output(|spin| {
let value = spin.value(); let value = spin.value();