Our great sponsors
-
serialport
Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
We use node-serialport instead of the WebSerial API, since it was only recently that Electron supported WebSerial permission overrides to make things like a 'devices screen' viable. The WebBluetooth APIs are still in a situation where you have to do polling shenanigans to get a full device list. I've found the mutated permissions system leaves a lot to be desired when debugging, whereas the NAPI modules are a lot more straightforward.
We use node-usb for USB hotplug detection, and rerun the serial poll, diffing the output with the ID information from node-usb to produce reliable device hinting.
I wouldn't recommend using the main process to access the device. Any long-running blocking calls will cause all kinds of hard to debug problems. Ideally the main process does literally nothing except message passing and window handling. Defer any work to a hidden renderer window, or if you're on the latest Electron version, perhaps the UtilityProcess API would be a good fit.