feat: impl From<StreamDeck> for AsyncStreamDeck

Allows opening a device via the synchronous API on a caller-chosen thread
and then handing it to the async wrapper. This matters on macOS, where
hidapi's IOHIDManager is bound to the run loop of the thread that created
the HidApi: enumerate/open must happen on that thread, but
AsyncStreamDeck::connect runs them via block_in_place on whatever tokio
worker is current, which can crash (EXC_BREAKPOINT in CoreFoundation)
when the device set changes, e.g. after sleep/wake.

With this, an application can own the HidApi on a dedicated thread, open
devices there with StreamDeck::connect, and still use the async API for
everything else.
This commit is contained in:
Brandon King authored and nekename committed 2026-06-13 11:35:17 +01:00
1 parent f7f8effd69
commit 6cfff2359f
1 file changed
+10
+10
View File
@@ -48,6 +48,16 @@ impl AsyncStreamDeck {
}
}
impl From<StreamDeck> for AsyncStreamDeck {
/// Wraps an already-opened [StreamDeck], allowing the caller to control which thread performs the HID open
fn from(device: StreamDeck) -> AsyncStreamDeck {
AsyncStreamDeck {
kind: device.kind(),
device: Arc::new(Mutex::new(device)),
}
}
}
/// Instance methods of the struct
impl AsyncStreamDeck {
/// Returns kind of the Stream Deck