stream_deck_plugin_template/
plugin.rs

1use stream_deck_plugin::ClientResponse;
2use color_eyre::Result;
3use stream_deck_plugin::Client;
4
5#[derive(Debug)]
6pub struct Plugin {
7	client: Client,
8}
9
10impl Plugin {
11
12	pub async fn new_from_args() -> Result<Self> {
13		let client = Client::new_from_args().await?;
14		Ok( Self {
15			client,
16
17		} )
18	}
19
20	async fn handle_update(&mut self) -> Result<()> {
21		//tracing::info!("Handling update");
22		// handle polling of external status here
23		Ok(())
24	}
25	async fn handle_response(&mut self, response: ClientResponse) -> Result<()> {
26		//tracing::info!("Handling {response:?}");
27		match response {
28			ClientResponse::WillAppear{ .. } => {
29
30			},
31			ClientResponse::KeyUp { context, payload, .. } => {
32				let settings = payload.settings;
33				tracing::info!("KeyUp [{context}] -> Settings {settings:?}");
34				let state = 1-payload.state;
35				self.client.send_set_state( context, state ).await?;
36			},
37			o => {
38				// Note: It might be ok to just ignore some responses, depending on your use case
39				tracing::warn!("Unhandled response: {o:?}");
40			}
41		}
42		Ok(())
43	}
44	pub async fn run( &mut self ) -> Result<()> {
45	    loop {
46	        let timeout = tokio::time::sleep(tokio::time::Duration::from_millis(1000));
47	        tokio::select! {
48	            _ = timeout => {
49	                let _todo = self.handle_update( ).await;
50	            }
51	            Some( response ) = self.client.recv() => {
52	                let _todo = self.handle_response( response ).await;
53	            }
54	        }
55	    }
56
57//		Ok(())
58	}
59}