Automatically reconnect attached streamdecks on replug/resume?
My streamdecks are plugged into a USB hub that's plugged into my laptop. If I take my laptop to work then come back home, I have to manually reconnect them clicking a button in the app. Maybe the app could listen to usb plugin events and automatically reconnect?
18 Replies
I haven't found a clean way to listen for device connection events in Rust, but if you do find one, please let me know
This looks promising: https://github.com/kbknapp/usbwatch-rs
GitHub
GitHub - kbknapp/usbwatch-rs: Watch for USB events and execute acti...
Watch for USB events and execute actions from rules - kbknapp/usbwatch-rs
looks like it's a command line tool but the code should serve as an example
I think udev is built into rust? https://docs.rs/udev/latest/udev/struct.Device.html
Device in udev - Rust
A structure that provides access to sysfs/kernel devices.
alternatively, an easier way could be to have a SIGHUP handler (which usually is used for a daemon to reload config) and have that scan/reconnect. or USR1.
then one could just add udev trigger rules to send that
This one looks like it only supports Linux, and the same goes for talking to udev directly
I generally only add features when they can work cross-platform
(I gave the same response to the request for switching profiles when the focused window changes, until a cross-platform solution was found and then I implemented it)
hm, tall order to have a cross-platform hotplug detection, but let's see
sorry 😅
If you want I can add a rescan devices button, so that you can refresh the list even if you have a device connected already
Of course there is the route of just polling every few seconds
spoke to soon!
GitHub
Hotplug events on device connect and disconnect · Issue #5 · kevinm...
Linux Typically udev Rust udev crate looks good, but wraps a C library. There's also a way to get events directly from the kernel with a NETLINK_KOBJECT_UEVENT socket Windows RegisterDeviceNoti...
suggests that nusb has hotplug support cross-platform
oh very cool
this project seems very interesting, maybe I should have a look at adding it as a supported backend to the hidapi library
that might resolve some inconsistencies between platforms as well (#Ajazz devices not functioning properly under Windows)
as a temporary solution, allowing to choose to rescan every minute or so when no device is currently connected according to the app would work just fine for now
@thomasvs latest commit rescans every 10 seconds
seems to work fine with my Mini
nice, will try, thanks!
are there nightly builds or should I build and run from source to try?
2.4.0 should be out by tomorrow I think
might be late but this: https://github.com/haimgel/display-switch/blob/main/src/platform/pnp_detect_libusb.rs seems to also implement similar behaviour
GitHub
display-switch/src/platform/pnp_detect_libusb.rs at main · haimgel/...
Turn a $30 USB switch into a full-featured multi-monitor KVM switch - haimgel/display-switch
Oh cool
Sorry this hasn't happened yet, waiting on the resolution of a few more things
Yea building from source might have been a better idea