streamdeck-rs icon indicating copy to clipboard operation
streamdeck-rs copied to clipboard

Simple example missing

Open FibreFoX opened this issue 3 years ago • 1 comments

Hi there,

I'm quite new to the Rust ecosystem, but I wanted to create some small Stream Deck plugin, so I ended up here, but I'm failing to understand how a sample plugin could look like using this library.

Can you show with a simple "hello world" like example project, how this library is ment to be used? Thanks.

FibreFoX avatar Oct 03 '21 18:10 FibreFoX

I use it for this plugin: https://github.com/mdonoughe/sbzdeck/blob/master/plugin/src/main.rs

You want to make something like this:

#[tokio::main(max_threads=1)]
async fn main() {
    let params = &RegistrationParams::from_args(env::args()).unwrap();
    let (mut sink, mut stream) = StreamDeckSocket::<MyGlobalSettings, MyActionSettings, FromInspector, ToInspector>::connect(
        params.port,
        params.event.to_string(),
        params.uuid.to_string(),
    ).await.expect("connection failed").split();
}

Then you can use the usual async stream stuff to receive events from the Stream Deck software via stream using the Message type and send events to the Stream Deck software via sink using the MessageOut type. If you want to do something simple you can make a loop that reads from sink and only reacts to that, but in my case I needed to initiate actions from the plugin so I needed something more complicated.

For any of the type parameters to StreamDeckSocket if you aren't going to use them you can just define a struct Empty:

#[derive(Debug, Deserialize, Serialize)]
pub struct Empty {}

You'll still need to set up the plugin manifest. This library only handles opening the connection and serialization/deserialization of messages.

mdonoughe avatar Oct 05 '21 01:10 mdonoughe