balena-io-modules / drivelist

List all connected drives in your computer, in all major operating systems
Apache License 2.0
242 stars 90 forks source link

How to trigger event upon new/removed device? #341

Open redmission84 opened 5 years ago

redmission84 commented 5 years ago

Not an issue with this module exactly, but is there a way to detect when a new device is added or an existing device is removed?

lurch commented 5 years ago

I think you'd need to run it in a polling loop, and look for any differences in the output between one run and the next. This is how etcher-sdk does it: https://github.com/balena-io-modules/etcher-sdk/blob/master/lib/scanner/adapters/block-device.ts