mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
chore: make the settings save code prettier
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use config_traits::StdConfig;
|
use config_traits::StdConfig;
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info, warn};
|
||||||
use rog_platform::asus_armoury::{AttrValue, Attribute, FirmwareAttribute, FirmwareAttributes};
|
use rog_platform::asus_armoury::{AttrValue, Attribute, FirmwareAttribute, FirmwareAttributes};
|
||||||
use rog_platform::platform::{PlatformProfile, RogPlatform};
|
use rog_platform::platform::{PlatformProfile, RogPlatform};
|
||||||
use rog_platform::power::AsusPower;
|
use rog_platform::power::AsusPower;
|
||||||
@@ -397,44 +397,44 @@ impl AsusArmouryAttribute {
|
|||||||
self.attr
|
self.attr
|
||||||
.set_current_value(&AttrValue::Integer(value))
|
.set_current_value(&AttrValue::Integer(value))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
error!("Could not set value: {e:?}");
|
error!(
|
||||||
|
"Could not set value to PPT property {}: {e:?}",
|
||||||
|
self.attr.name()
|
||||||
|
);
|
||||||
e
|
e
|
||||||
})?;
|
})?;
|
||||||
|
} else {
|
||||||
|
warn!(
|
||||||
|
"Tuning group is disabled: skipping setting value to PPT property {}",
|
||||||
|
self.attr.name()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.attr
|
self.attr
|
||||||
.set_current_value(&AttrValue::Integer(value))
|
.set_current_value(&AttrValue::Integer(value))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
error!("Could not set value: {e:?}");
|
error!(
|
||||||
|
"Could not set value {value} to attribute {}: {e:?}",
|
||||||
|
self.attr.name()
|
||||||
|
);
|
||||||
e
|
e
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let has_attr = self
|
let mut settings = self.config.lock().await;
|
||||||
.config
|
settings
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.armoury_settings
|
.armoury_settings
|
||||||
.contains_key(&self.name());
|
.entry(self.name())
|
||||||
if has_attr {
|
.and_modify(|setting| {
|
||||||
if let Some(setting) = self
|
debug!("Set config for {} = {value}", self.attr.name());
|
||||||
.config
|
*setting = value;
|
||||||
.lock()
|
})
|
||||||
.await
|
.or_insert_with(|| {
|
||||||
.armoury_settings
|
debug!("Adding config for {} = {value}", self.attr.name());
|
||||||
.get_mut(&self.name())
|
value
|
||||||
{
|
});
|
||||||
*setting = value
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug!("Adding config for {}", self.attr.name());
|
|
||||||
self.config
|
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.armoury_settings
|
|
||||||
.insert(self.name(), value);
|
|
||||||
debug!("Set config for {} = {:?}", self.attr.name(), value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write config after setting value
|
||||||
self.config.lock().await.write();
|
self.config.lock().await.write();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user