-
Notifications
You must be signed in to change notification settings - Fork 114
Events no longer fired after stopping and restarting monitoring #53
Comments
Ok, so my initial thoughts were why are we even disabling usb detection when the device is in sleep. Testing on Windows 10 and macOS High Sierra seems to suggest that usb detection works perfectly well after coming out of suspend even if monitoring was left enabled throughout sleep. This then begs the question whether it's possible to restart monitoring after its been stopped. If the |
Hi @timfish, |
I actually only found out that AtExit exists from that bug 🙂 |
@timfish Sorry for the delay. In the 2.x release, I tried removing the side-effects and require
On macOS, I suspect after stopping, you can't start again because we stop those threads and don't start them back up in node-usb-detection/src/detection_mac.cpp Line 390 in 9164178
On Windows, node-usb-detection/src/detection_win.cpp Line 167 in 9164178
For reference, here is a test I wrote to cover this basis but it doesn't succeed 100% of the time. describe('multiple start/stop', () => {
it('should only listen when monitoring', function(done) {
usbDetect.startMonitoring();
console.log(chalk.black.bgCyan('Add/Insert or Remove a USB device (again)'));
once('change')
.then(function(device) {
testDeviceShape(device);
})
.then(() => {
usbDetect.stopMonitoring();
// Make sure we don't detect anything while not monitoring
console.log(chalk.black.bgCyan(`Add/Insert or Remove a USB device (again). We don't want to detect anything for ${MANUAL_INTERACTION_TIMEOUT / 1000} seconds!`));
var shouldDetect = false;
once('change')
.then(() => {
if(!shouldDetect) {
done.fail('We detected an `add` event when we were NOT monitoring anything');
}
});
return getSetTimeoutPromise(MANUAL_INTERACTION_TIMEOUT)
.then(() => {
shouldDetect = true;
});
})
.then(() => {
usbDetect.startMonitoring();
console.log(chalk.black.bgCyan('Add/Insert or Remove a USB device (again)'));
return once('change');
})
.then(() => {
console.log('gfjewfakefakljfewajlkfewalkjafewjlkafewjlkafewjlk');
usbDetect.stopMonitoring();
})
.then(done)
.catch(done.fail);
}, 3 * MANUAL_INTERACTION_TIMEOUT);
}); |
We're using this library rather successfully in our Electron app but I'm trying to fix an issue on both Windows and macOS.
We use Electrons powerMonitor API to
stopMonitoring
andstartMonitoring
from thesuspend
andresume
events respectively. After stopping and restarting monitoring, we no longer get USB change events. Is this the expected behaviour?The text was updated successfully, but these errors were encountered: