From 026a524c2067f36de15fe76e8a4d98146a8b6ba4 Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Tue, 9 Jan 2024 23:16:44 +0100 Subject: [PATCH] commit --- deckster/examples/full/key-pages/default.toml | 1 - deckster/examples/full/key-pages/emojis.toml | 12 +++--- deckster/examples/full/key-pages/numpad.toml | 18 ++++----- .../full/key-pages/special_chars.toml | 12 +++--- deckster/src/model/key_page.rs | 7 ++-- deckster/src/modes/key/command.rs | 37 +++++++++++++++++++ deckster/src/modes/key/mod.rs | 7 +++- deckster/src/modes/key/vibrate.rs | 3 +- 8 files changed, 69 insertions(+), 28 deletions(-) create mode 100644 deckster/src/modes/key/command.rs diff --git a/deckster/examples/full/key-pages/default.toml b/deckster/examples/full/key-pages/default.toml index 2f9b22a..7677da0 100644 --- a/deckster/examples/full/key-pages/default.toml +++ b/deckster/examples/full/key-pages/default.toml @@ -17,7 +17,6 @@ mode.playerctl__button.style.inactive.icon = "@ph/skip-forward[alpha=0.4]" [keys.1x2] icon = "@fad/shuffle[alpha=0.4]" mode.playerctl__shuffle.style.on.icon = "@fad/shuffle[color=#58fc11]" -mode.playerctl__shuffle.style.off.icon = "@fad/shuffle" [keys.2x2] icon = "@fad/repeat[alpha=0.4]" diff --git a/deckster/examples/full/key-pages/emojis.toml b/deckster/examples/full/key-pages/emojis.toml index 792a6e6..d6d9199 100644 --- a/deckster/examples/full/key-pages/emojis.toml +++ b/deckster/examples/full/key-pages/emojis.toml @@ -5,24 +5,24 @@ delta = 1 [keys.4x1] label = "๐Ÿ˜€" -mode.keyboard.key = "๐Ÿ˜€" +mode.command.command = "wtype ๐Ÿ˜€" [keys.4x2] label = "๐Ÿ˜„" -mode.keyboard.key = "๐Ÿ˜„" +mode.command.command = "wtype ๐Ÿ˜„" [keys.4x3] label = "๐Ÿ˜…" -mode.keyboard.key = "๐Ÿ˜…" +mode.command.command = "wtype ๐Ÿ˜…" [keys.4x4] label = "๐Ÿ˜‚" -mode.keyboard.key = "๐Ÿ˜‚" +mode.command.command = "wtype ๐Ÿ˜‚" [keys.4x5] label = "๐Ÿ˜" -mode.keyboard.key = "๐Ÿ˜" +mode.command.command = "wtype ๐Ÿ˜" [keys.4x6] label = "๐Ÿ˜‡" -mode.keyboard.key = "๐Ÿ˜‡" \ No newline at end of file +mode.command.command = "wtype ๐Ÿ˜‡" \ No newline at end of file diff --git a/deckster/examples/full/key-pages/numpad.toml b/deckster/examples/full/key-pages/numpad.toml index 8736120..cf96fec 100644 --- a/deckster/examples/full/key-pages/numpad.toml +++ b/deckster/examples/full/key-pages/numpad.toml @@ -1,35 +1,35 @@ [keys.4x1] label = "9" -mode.keyboard.key = "9" +mode.command.command = "wtype 9" [keys.3x1] label = "8" -mode.keyboard.key = "8" +mode.command.command = "wtype 8" [keys.2x1] label = "7" -mode.keyboard.key = "7" +mode.command.command = "wtype 7" [keys.4x2] label = "6" -mode.keyboard.key = "6" +mode.command.command = "wtype 6" [keys.3x2] label = "5" -mode.keyboard.key = "5" +mode.command.command = "wtype 5" [keys.2x2] label = "4" -mode.keyboard.key = "4" +mode.command.command = "wtype 4" [keys.4x3] label = "3" -mode.keyboard.key = "3" +mode.command.command = "wtype 3" [keys.3x3] label = "2" -mode.keyboard.key = "2" +mode.command.command = "wtype 2" [keys.2x3] label = "1" -mode.keyboard.key = "1" \ No newline at end of file +mode.command.command = "wtype 1" \ No newline at end of file diff --git a/deckster/examples/full/key-pages/special_chars.toml b/deckster/examples/full/key-pages/special_chars.toml index e0188f4..c2bf749 100644 --- a/deckster/examples/full/key-pages/special_chars.toml +++ b/deckster/examples/full/key-pages/special_chars.toml @@ -6,24 +6,24 @@ delta = 4 [keys.1x1] label = "โ€™" -mode.keyboard.key = "โ€™" +mode.command.command = "wtype โ€™" [keys.2x1] label = "โ€ฆ" -mode.keyboard.key = "โ€ฆ" +mode.command.command = "wtype โ€ฆ" [keys.3x1] label = "โ€”" -mode.keyboard.key = "โ€”" +mode.command.command = "wtype โ€”" [keys.4x1] label = "โ€“" -mode.keyboard.key = "โ€“" +mode.command.command = "wtype โ€“" [keys.5x1] label = "ยท" -mode.keyboard.key = "ยท" +mode.command.command = "wtype ยท" [keys.6x1] label = "โ†’" -mode.keyboard.key = "โ†’" \ No newline at end of file +mode.command.command = "wtype โ†’" \ No newline at end of file diff --git a/deckster/src/model/key_page.rs b/deckster/src/model/key_page.rs index ca3cddd..9767fa8 100644 --- a/deckster/src/model/key_page.rs +++ b/deckster/src/model/key_page.rs @@ -75,12 +75,13 @@ pub struct KeyConfig { #[allow(non_snake_case)] #[derive(Debug, Default, Deserialize)] pub struct KeyModes { - pub vibrate: Option>, + pub command: Option>, + pub home_assistant__switch: Option>, + pub home_assistant__button: Option>, pub playerctl__button: Option>, pub playerctl__shuffle: Option>, pub playerctl__loop: Option>, - pub home_assistant__switch: Option>, - pub home_assistant__button: Option>, + pub vibrate: Option>, } pub type StyleByStateMap = HashMap; diff --git a/deckster/src/modes/key/command.rs b/deckster/src/modes/key/command.rs new file mode 100644 index 0000000..dc8e92b --- /dev/null +++ b/deckster/src/modes/key/command.rs @@ -0,0 +1,37 @@ +use std::process::{Command, Stdio}; +use std::sync::Arc; + +use log::{error, trace, warn}; +use serde::Deserialize; +use tokio::sync::broadcast; + +use crate::modes::key::KeyEvent; + +#[derive(Debug, Deserialize)] +pub struct Config { + pub command: String, +} + +pub async fn handle(config: Arc, mut events: broadcast::Receiver) { + while let Ok(event) = events.recv().await { + if let KeyEvent::Press = event { + let result = Command::new("sh") + .args(["-c", &config.command]) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .stdin(Stdio::null()) + .status(); + + match result { + Ok(status) => { + if status.success() { + trace!("Command `{}` exited with status code 0", config.command); + } else { + warn!("Command `{}` exited with status code {}", config.command, status); + } + } + Err(error) => error!("Command `{}` could not be executed: {}", config.command, error), + } + } + } +} diff --git a/deckster/src/modes/key/mod.rs b/deckster/src/modes/key/mod.rs index b469169..24eb533 100644 --- a/deckster/src/modes/key/mod.rs +++ b/deckster/src/modes/key/mod.rs @@ -7,6 +7,7 @@ use crate::model; use crate::model::position::KeyPath; use crate::runner::command::IoWorkerCommand; +pub mod command; pub mod home_assistant; pub mod playerctl; pub mod timer; @@ -35,6 +36,10 @@ pub fn start_handlers( let mut events = events.subscribe(); let own_events = broadcast::Sender::new(5); + if let Some(c) = &config.mode.command { + tokio::spawn(command::handle(Arc::clone(c), own_events.subscribe())); + } + if let Some(c) = &config.mode.playerctl__button { tokio::spawn(playerctl::handle_button(path.clone(), Arc::clone(c), own_events.subscribe(), commands.clone())); } @@ -48,7 +53,7 @@ pub fn start_handlers( } if let Some(c) = &config.mode.vibrate { - tokio::spawn(vibrate::handle(path.clone(), Arc::clone(c), own_events.subscribe(), commands.clone())); + tokio::spawn(vibrate::handle(Arc::clone(c), own_events.subscribe(), commands.clone())); } tokio::spawn(async move { diff --git a/deckster/src/modes/key/vibrate.rs b/deckster/src/modes/key/vibrate.rs index 1bff1ac..ebb78ba 100644 --- a/deckster/src/modes/key/vibrate.rs +++ b/deckster/src/modes/key/vibrate.rs @@ -5,7 +5,6 @@ use tokio::sync::broadcast; use loupedeck_serial::commands::VibrationPattern; -use crate::model::position::KeyPath; use crate::modes::key::{KeyEvent, KeyTouchEventKind}; use crate::runner::command::IoWorkerCommand; @@ -14,7 +13,7 @@ pub struct Config { pub pattern: VibrationPattern, } -pub async fn handle(_: KeyPath, config: Arc, mut events: broadcast::Receiver, commands: flume::Sender) { +pub async fn handle(config: Arc, mut events: broadcast::Receiver, commands: flume::Sender) { while let Ok(event) = events.recv().await { if let KeyEvent::Touch { kind, .. } = event { if kind == KeyTouchEventKind::Start {