-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Desktop support for USB, HID and Serial device access #198047
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
base: main
Are you sure you want to change the base?
Conversation
|
Anything required to progress this PR? |
|
Is there an associated issue with sufficient upvotes and motion to justify this change? And an explainer about the scenarios this would enable? |
Issue raised here: #236450 |
|
There are many conflicts in this PR btw. |
TBF, there weren't conflicts when I opened it a year ago and I got tired of keeping it up to date with no feedback. If there is interest in this feature I'll revisit the PR. |
Resolved |
|
The electron events ( As these run in different parts of VS Code, I've had to implement an IPC channel to send a device list for rendering and return a selected item. There isn't an existing pattern to do this, so advice on my proposal would be appreciated. |
This is a new feature to add USB, HID and Serial device access to the desktop by extending the existing WebUSB, WebHID and WebSerial functionality already offered in the web version #152310.
Since Electron version 25,
Web-*device access has been possible using the functionality described here: https://www.electronjs.org/docs/latest/tutorial/devicesThis ability is awesome because it allows access to functionality in Chrome already shipped as part of VS Code and means extension developers no longer have to include external packages such as
node-usborSerialPort. In many cases this approach should be more stable and reliable, too (e.g. chrome uses winusb for device access over libusb as used in node-usb).To implement this addition, I've wired up a QuickPick dropdown for the user to choose the requested device leveraging Electron's APIs. Unfortunately the cleanest way I've been able to find to communicate between the
electron-mainand browser process is via the globals API. Happy to hear of a better way.USB Selector:
Serial Selector:
HID Selector:
Please note: As this utilises the existing features in chrome, obtaining a concrete device after authorising it is only possible in the desktop web extension host. Therefore this feature is only available to pure web extensions (those without a
mainentrypoint inpackage.json).Notes on creating an extension to test this
To test this, create a VS Code Web Extension. This will create an extension which runs in the browser extensionHost, the only host which can see the browser
navigatorobject.Ensure there is only a
browserentrypoint. Including amainentrypoint will run the extension on the local extensionHost.Ensure there is no
extensionKindspecified. theUIextensionKind leads to errors with commands not being found.In the VS Code extension, call one of the existing experimental commands for requesting device access:
workbench.experimental.requestUsbDeviceworkbench.experimental.requestSerialPortworkbench.experimental.requestHidDeviceThis returns a string ID for the device (and authorizes the device for use).
Use this ID to then lookup the concrete device you want to use in the the relevant
navigatorobject: