mirror of
https://github.com/OpenActionAPI/rust-elgato-streamdeck.git
synced 2026-10-28 09:44:56 +00:00
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:
1 parent
f7f8effd69
commit
6cfff2359f
1 file changed
+10
@@ -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
|
||||
|
||||
Reference in new issue
Block a user