Created
January 15, 2019 21:51
-
-
Save sudipp/2bd654432bb477eec819701a5d3198dc to your computer and use it in GitHub Desktop.
usb-drive-util-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const drives = require('../src/drives').Drives; | |
function loadUSBDrvList(){ | |
drives.loadUSBDriveDetails().then(function(result){ | |
if(result && result.length== 0){ | |
console.log('No USB drive found in the system'); | |
return; | |
} | |
console.log('Loading USB drive(s) details'); | |
_.forEach(result, function (driveStats){ | |
console.log(driveStats); | |
}) | |
}).catch(function(err) { | |
console.log(err.message); | |
}); | |
} | |
loadUSBDrvList(); | |
let drv = new drives(); | |
//Track events when drive is attached and removed | |
drv.on("usbadd",(device)=>{ | |
console.log('An USB drive is attached to system'); | |
setTimeout(function() { | |
loadUSBDrvList(); | |
}, 1000); | |
}) | |
.on("usbremove", (device)=>{ | |
console.log('drive removed'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment