Skip to content

Commit c3fccf5

Browse files
committed
feat: rewrite crate public API to be significantly easier to use
1 parent aac079b commit c3fccf5

20 files changed

Lines changed: 850 additions & 275 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/target
1+
target/
22
Cargo.lock

Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
[package]
22
name = "openaction"
3-
description = "A crate for creating plugins for the OpenAction API."
3+
description = "A crate for creating plugins for the OpenAction API"
44
categories = [
55
"api-bindings",
66
"asynchronous",
77
"data-structures",
88
"web-programming::websocket",
99
]
10-
authors = ["ninjadev64"]
11-
version = "1.1.5"
10+
authors = ["nekename"]
11+
version = "2.0.0"
1212
edition = "2024"
1313
license = "MIT"
1414
readme = "README.md"
1515
repository = "https://github.com/OpenActionAPI/rust"
1616
homepage = "https://openaction.amankhanna.me"
1717

1818
[dependencies]
19-
anyhow = "1.0"
19+
thiserror = "1.0"
20+
async-trait = "0.1"
21+
dashmap = "6.1"
2022
futures-util = "0.3"
2123
log = "0.4"
2224
serde = { version = "1.0", features = ["derive"] }
2325
serde_json = "1.0"
24-
tokio = { version = "1.42", features = ["rt", "net", "sync"] }
25-
tokio-tungstenite = "0.26"
26+
tokio = { version = "1.47", features = ["rt", "net", "sync"] }
27+
tokio-tungstenite = "0.28"

README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,52 @@
11
# openaction-rs
22

3-
A Rust crate for creating plugins for the [OpenAction API](https://openaction.amankhanna.me) (compatible with the Stream Deck SDK).
3+
A Rust crate for creating plugins for the [OpenAction API](https://openaction.amankhanna.me) (backwards-compatible with the Stream Deck SDK)
44

5-
My [Linux Media plugin](https://github.com/nekename/oampris) serves as a minimal example of using this crate.
6-
The [OpenDeck Starter Pack plugin](https://github.com/nekename/OpenDeck/tree/main/plugins/com.amansprojects.starterpack.sdPlugin) is also made with this crate.
5+
```rust
6+
use openaction::*;
7+
8+
use serde::{Deserialize, Serialize};
9+
10+
#[derive(Serialize, Deserialize, Default, Clone)]
11+
#[serde(default)]
12+
struct CounterSettings {
13+
value: u32,
14+
}
15+
16+
struct CounterAction;
17+
#[async_trait]
18+
impl Action for CounterAction {
19+
const UUID: ActionUuid = "com.example.counter.counter";
20+
type Settings = CounterSettings;
21+
22+
async fn key_up(
23+
&self,
24+
instance: &Instance,
25+
settings: &Self::Settings,
26+
) -> OpenActionResult<()> {
27+
let mut clone = settings.clone();
28+
clone.value = settings.value + 1;
29+
instance.set_settings(&clone).await?;
30+
instance.set_title(clone.value.to_string()).await
31+
}
32+
}
33+
34+
#[tokio::main]
35+
async fn main() -> OpenActionResult<()> {
36+
{
37+
use simplelog::*;
38+
if let Err(error) = TermLogger::init(
39+
LevelFilter::Debug,
40+
Config::default(),
41+
TerminalMode::Stdout,
42+
ColorChoice::Never,
43+
) {
44+
eprintln!("Logger initialization failed: {}", error);
45+
}
46+
}
47+
48+
register_action(CounterAction).await;
49+
50+
run(std::env::args().collect()).await
51+
}
52+
```

src/inbound/encoder.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use crate::SettingsValue;
2-
3-
use super::Coordinates;
1+
use super::{Coordinates, SettingsValue};
42

53
use serde::Deserialize;
64

75
#[derive(Clone, Debug, Deserialize)]
86
pub struct DialRotatePayload {
97
pub settings: SettingsValue,
8+
#[allow(dead_code)]
109
pub coordinates: Coordinates,
1110
pub ticks: i16,
1211
pub pressed: bool,
@@ -16,21 +15,25 @@ pub struct DialRotatePayload {
1615
pub struct DialRotateEvent {
1716
pub action: String,
1817
pub context: String,
18+
#[allow(dead_code)]
1919
pub device: String,
2020
pub payload: DialRotatePayload,
2121
}
2222

2323
#[derive(Clone, Debug, Deserialize)]
2424
pub struct DialPressPayload {
25+
#[allow(dead_code)]
2526
pub controller: String,
2627
pub settings: SettingsValue,
28+
#[allow(dead_code)]
2729
pub coordinates: Coordinates,
2830
}
2931

3032
#[derive(Clone, Debug, Deserialize)]
3133
pub struct DialPressEvent {
3234
pub action: String,
3335
pub context: String,
36+
#[allow(dead_code)]
3437
pub device: String,
3538
pub payload: DialPressPayload,
3639
}

src/inbound/keypad.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use serde::Deserialize;
66
pub struct KeyEvent {
77
pub action: String,
88
pub context: String,
9+
#[allow(dead_code)]
910
pub device: String,
1011
pub payload: GenericInstancePayload,
1112
}

0 commit comments

Comments
 (0)