Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple example missing #5

Open
FibreFoX opened this issue Oct 3, 2021 · 1 comment
Open

Simple example missing #5

FibreFoX opened this issue Oct 3, 2021 · 1 comment

Comments

@FibreFoX
Copy link

FibreFoX commented Oct 3, 2021

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.

@mdonoughe
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants