mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Use loops to ensure settings apply where a mutex is tried
This commit is contained in:
@@ -65,25 +65,28 @@ impl CtrlKbdLedZbus {
|
|||||||
enabled: bool,
|
enabled: bool,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> zbus::fdo::Result<()> {
|
||||||
let mut states = None;
|
let mut states = None;
|
||||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
loop {
|
||||||
for p in options.tuf {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
ctrl.config.enabled.set_tuf(p, enabled);
|
for p in options.tuf {
|
||||||
}
|
ctrl.config.enabled.set_tuf(p, enabled);
|
||||||
for p in options.x1866 {
|
}
|
||||||
ctrl.config.enabled.set_0x1866(p, enabled);
|
for p in options.x1866 {
|
||||||
}
|
ctrl.config.enabled.set_0x1866(p, enabled);
|
||||||
for p in options.x19b6 {
|
}
|
||||||
ctrl.config.enabled.set_0x19b6(p, enabled);
|
for p in options.x19b6 {
|
||||||
}
|
ctrl.config.enabled.set_0x19b6(p, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
ctrl.config.write();
|
ctrl.config.write();
|
||||||
|
|
||||||
ctrl.set_power_states().map_err(|e| {
|
ctrl.set_power_states().map_err(|e| {
|
||||||
warn!("{}", e);
|
warn!("{}", e);
|
||||||
e
|
e
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
states = Some(AuraPowerDev::from(&ctrl.config.enabled));
|
states = Some(AuraPowerDev::from(&ctrl.config.enabled));
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// Need to pull state out like this due to MutexGuard
|
// Need to pull state out like this due to MutexGuard
|
||||||
if let Some(states) = states {
|
if let Some(states) = states {
|
||||||
@@ -100,13 +103,16 @@ impl CtrlKbdLedZbus {
|
|||||||
effect: AuraEffect,
|
effect: AuraEffect,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> zbus::fdo::Result<()> {
|
||||||
let mut led = None;
|
let mut led = None;
|
||||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
loop {
|
||||||
ctrl.set_effect(effect).map_err(|e| {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
warn!("{}", e);
|
ctrl.set_effect(effect).map_err(|e| {
|
||||||
e
|
warn!("{}", e);
|
||||||
})?;
|
e
|
||||||
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
})?;
|
||||||
led = Some(mode.clone());
|
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
||||||
|
led = Some(mode.clone());
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(led) = led {
|
if let Some(led) = led {
|
||||||
@@ -122,14 +128,17 @@ impl CtrlKbdLedZbus {
|
|||||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> zbus::fdo::Result<()> {
|
||||||
let mut led = None;
|
let mut led = None;
|
||||||
if let Ok(mut ctrl) = self.0.lock() {
|
loop {
|
||||||
ctrl.toggle_mode(false).map_err(|e| {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
warn!("{}", e);
|
ctrl.toggle_mode(false).map_err(|e| {
|
||||||
e
|
warn!("{}", e);
|
||||||
})?;
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
||||||
led = Some(mode.clone());
|
led = Some(mode.clone());
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(led) = led {
|
if let Some(led) = led {
|
||||||
@@ -137,6 +146,7 @@ impl CtrlKbdLedZbus {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.unwrap_or_else(|err| warn!("{}", err));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,14 +155,17 @@ impl CtrlKbdLedZbus {
|
|||||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||||
) -> zbus::fdo::Result<()> {
|
) -> zbus::fdo::Result<()> {
|
||||||
let mut led = None;
|
let mut led = None;
|
||||||
if let Ok(mut ctrl) = self.0.lock() {
|
loop {
|
||||||
ctrl.toggle_mode(true).map_err(|e| {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
warn!("{}", e);
|
ctrl.toggle_mode(true).map_err(|e| {
|
||||||
e
|
warn!("{}", e);
|
||||||
})?;
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
||||||
led = Some(mode.clone());
|
led = Some(mode.clone());
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(led) = led {
|
if let Some(led) = led {
|
||||||
@@ -164,21 +177,27 @@ impl CtrlKbdLedZbus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn next_led_brightness(&self) -> zbus::fdo::Result<()> {
|
async fn next_led_brightness(&self) -> zbus::fdo::Result<()> {
|
||||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
loop {
|
||||||
ctrl.next_brightness().map_err(|e| {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
warn!("{}", e);
|
ctrl.next_brightness().map_err(|e| {
|
||||||
e
|
warn!("{}", e);
|
||||||
})?;
|
e
|
||||||
|
})?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn prev_led_brightness(&self) -> zbus::fdo::Result<()> {
|
async fn prev_led_brightness(&self) -> zbus::fdo::Result<()> {
|
||||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
loop {
|
||||||
ctrl.prev_brightness().map_err(|e| {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
warn!("{}", e);
|
ctrl.prev_brightness().map_err(|e| {
|
||||||
e
|
warn!("{}", e);
|
||||||
})?;
|
e
|
||||||
|
})?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -195,10 +214,11 @@ impl CtrlKbdLedZbus {
|
|||||||
|
|
||||||
/// Return the current mode data
|
/// Return the current mode data
|
||||||
async fn led_mode(&self) -> AuraModeNum {
|
async fn led_mode(&self) -> AuraModeNum {
|
||||||
if let Ok(ctrl) = self.0.try_lock() {
|
loop {
|
||||||
return ctrl.config.current_mode;
|
if let Ok(ctrl) = self.0.try_lock() {
|
||||||
|
return ctrl.config.current_mode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AuraModeNum::Static
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a list of available modes
|
/// Return a list of available modes
|
||||||
@@ -211,8 +231,11 @@ impl CtrlKbdLedZbus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn per_key_raw(&self, data: PerKeyRaw) -> zbus::fdo::Result<()> {
|
async fn per_key_raw(&self, data: PerKeyRaw) -> zbus::fdo::Result<()> {
|
||||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
loop {
|
||||||
ctrl.write_effect_block(&data)?;
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
|
ctrl.write_effect_block(&data)?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -220,11 +243,11 @@ impl CtrlKbdLedZbus {
|
|||||||
/// Return the current LED brightness
|
/// Return the current LED brightness
|
||||||
#[dbus_interface(property)]
|
#[dbus_interface(property)]
|
||||||
async fn led_brightness(&self) -> i8 {
|
async fn led_brightness(&self) -> i8 {
|
||||||
if let Ok(ctrl) = self.0.try_lock() {
|
loop {
|
||||||
return ctrl.get_brightness().map(|n| n as i8).unwrap_or(-1);
|
if let Ok(ctrl) = self.0.try_lock() {
|
||||||
|
return ctrl.get_brightness().map(|n| n as i8).unwrap_or(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
warn!("SetKeyBacklight could not serialise");
|
|
||||||
-1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[dbus_interface(signal)]
|
#[dbus_interface(signal)]
|
||||||
|
|||||||
Reference in New Issue
Block a user