mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Safely index modes
This commit is contained in:
@@ -37,8 +37,8 @@ impl Config {
|
||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
|
||||
self = c;
|
||||
} else {
|
||||
self =
|
||||
toml::from_str(&buf).expect(&format!("Could not deserialise {}", CONFIG_PATH));
|
||||
self = toml::from_str(&buf)
|
||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
|
||||
}
|
||||
}
|
||||
self
|
||||
|
||||
@@ -238,14 +238,17 @@ where
|
||||
|
||||
#[inline]
|
||||
async fn set_builtin(&self, config: &mut Config, index: usize) -> Result<(), AuraError> {
|
||||
let mode_next = config
|
||||
.builtin_modes
|
||||
.get_field_from(self.supported_modes[index].into())
|
||||
.ok_or(AuraError::NotSupported)?
|
||||
.to_owned();
|
||||
println!("{:X?}", &mode_next);
|
||||
self.set_and_save(&mode_next, config).await?;
|
||||
info!("Switched LED mode to {:#?}", self.supported_modes[index]);
|
||||
Ok(())
|
||||
if let Some(mode) = self.supported_modes.get(index) {
|
||||
let mode_next = config
|
||||
.builtin_modes
|
||||
.get_field_from(mode.to_owned().into())
|
||||
.ok_or(AuraError::NotSupported)?
|
||||
.to_owned();
|
||||
println!("{:X?}", &mode_next);
|
||||
self.set_and_save(&mode_next, config).await?;
|
||||
info!("Switched LED mode to {:#?}", self.supported_modes[index]);
|
||||
return Ok(());
|
||||
}
|
||||
Err(AuraError::NotSupported)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use rog_client::{
|
||||
AuraDbusWriter, LED_MSG_LEN,
|
||||
};
|
||||
|
||||
static VERSION: &str = "0.11.0";
|
||||
static VERSION: &str = "0.11.1";
|
||||
|
||||
#[derive(Debug, Options)]
|
||||
struct CLIStart {
|
||||
|
||||
Reference in New Issue
Block a user