mirror of
https://github.com/nekename/OpenDeck.git
synced 2026-10-28 09:44:01 +00:00
fix: prevent further processing of input events that wake device from sleep to prevent unwanted triggers
This commit is contained in:
3 files changed
+23
-11
No files matched your search
@@ -30,7 +30,7 @@ pub fn update_timeout_minutes(minutes: u16) {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn note_activity(device: &str) -> Result<(), anyhow::Error> {
|
||||
pub async fn note_activity(device: &str) -> Result<bool, anyhow::Error> {
|
||||
LAST_ACTIVITY.insert(device.to_owned(), Instant::now());
|
||||
wake_device(device).await
|
||||
}
|
||||
@@ -63,11 +63,12 @@ async fn sleep_idle_devices() -> Result<(), anyhow::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn wake_device(device: &str) -> Result<(), anyhow::Error> {
|
||||
async fn wake_device(device: &str) -> Result<bool, anyhow::Error> {
|
||||
if SLEEPING_DEVICES.remove(device).is_some() {
|
||||
let brightness = crate::store::get_settings().map(|s| s.value.brightness).unwrap_or(50);
|
||||
crate::events::outbound::devices::set_device_brightness(device, brightness).await?;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(false)
|
||||
}
|
||||
@@ -83,12 +83,16 @@ pub struct PressPayload {
|
||||
}
|
||||
|
||||
pub async fn key_down(event: PayloadEvent<PressPayload>) -> Result<(), anyhow::Error> {
|
||||
let _ = crate::device_sleep::note_activity(&event.payload.device).await;
|
||||
if crate::device_sleep::note_activity(&event.payload.device).await.unwrap_or(false) {
|
||||
return Ok(());
|
||||
}
|
||||
crate::events::outbound::keypad::key_down(&event.payload.device, event.payload.position).await
|
||||
}
|
||||
|
||||
pub async fn key_up(event: PayloadEvent<PressPayload>) -> Result<(), anyhow::Error> {
|
||||
let _ = crate::device_sleep::note_activity(&event.payload.device).await;
|
||||
if crate::device_sleep::note_activity(&event.payload.device).await.unwrap_or(false) {
|
||||
return Ok(());
|
||||
}
|
||||
crate::events::outbound::keypad::key_up(&event.payload.device, event.payload.position).await
|
||||
}
|
||||
|
||||
@@ -100,17 +104,23 @@ pub struct TicksPayload {
|
||||
}
|
||||
|
||||
pub async fn encoder_change(event: PayloadEvent<TicksPayload>) -> Result<(), anyhow::Error> {
|
||||
let _ = crate::device_sleep::note_activity(&event.payload.device).await;
|
||||
if crate::device_sleep::note_activity(&event.payload.device).await.unwrap_or(false) {
|
||||
return Ok(());
|
||||
}
|
||||
crate::events::outbound::encoder::dial_rotate(&event.payload.device, event.payload.position, event.payload.ticks).await
|
||||
}
|
||||
|
||||
pub async fn encoder_down(event: PayloadEvent<PressPayload>) -> Result<(), anyhow::Error> {
|
||||
let _ = crate::device_sleep::note_activity(&event.payload.device).await;
|
||||
if crate::device_sleep::note_activity(&event.payload.device).await.unwrap_or(false) {
|
||||
return Ok(());
|
||||
}
|
||||
crate::events::outbound::encoder::dial_press(&event.payload.device, "dialDown", event.payload.position).await
|
||||
}
|
||||
|
||||
pub async fn encoder_up(event: PayloadEvent<PressPayload>) -> Result<(), anyhow::Error> {
|
||||
let _ = crate::device_sleep::note_activity(&event.payload.device).await;
|
||||
if crate::device_sleep::note_activity(&event.payload.device).await.unwrap_or(false) {
|
||||
return Ok(());
|
||||
}
|
||||
crate::events::outbound::encoder::dial_press(&event.payload.device, "dialUp", event.payload.position).await
|
||||
}
|
||||
|
||||
|
||||
@@ -121,9 +121,10 @@ pub async fn key_up(device: &str, key: u8) -> Result<(), anyhow::Error> {
|
||||
};
|
||||
|
||||
let _ = key_moved(crate::APP_HANDLE.get().unwrap(), context.clone(), false).await;
|
||||
if let Some((_, expected_context)) = KEY_DOWN_TARGETS.remove(&(device.to_owned(), key))
|
||||
&& context != expected_context
|
||||
{
|
||||
let Some((_, expected_context)) = KEY_DOWN_TARGETS.remove(&(device.to_owned(), key)) else {
|
||||
return Ok(());
|
||||
};
|
||||
if context != expected_context {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user