diff --git a/desktop/native-module-host.js b/desktop/native-module-host.js index 2e516ccf..bf3ac12c 100644 --- a/desktop/native-module-host.js +++ b/desktop/native-module-host.js @@ -4,6 +4,7 @@ const { reqNative } = require('./scripts/util/req-native'); const YubiKeyVendorIds = [0x1050]; const attachedYubiKeys = []; let usbListenerRunning = false; +let usbListenerInitialized = false; let autoType; let callback; @@ -15,12 +16,16 @@ const messageHandlers = { return; } - const usbDetection = reqNative('usb-detection'); + if (!usbListenerInitialized) { + const usbDetection = reqNative('usb-detection'); - usbDetection.registerAdded(usbDeviceAttached); - usbDetection.registerRemoved(usbDeviceDetached); + usbDetection.registerAdded(usbDeviceAttached); + usbDetection.registerRemoved(usbDeviceDetached); - usbDetection.startMonitoring(); + usbDetection.startMonitoring(); + + usbListenerInitialized = true; + } fillAttachedYubiKeys(); @@ -32,10 +37,6 @@ const messageHandlers = { return; } - const usbDetection = reqNative('usb-detection'); - - usbDetection.stopMonitoring(); - usbListenerRunning = false; attachedYubiKeys.length = 0; }, @@ -150,6 +151,9 @@ function isYubiKey(device) { } function usbDeviceAttached(device) { + if (!usbListenerRunning) { + return; + } if (isYubiKey(device)) { attachedYubiKeys.push(device); reportYubiKeys(); @@ -157,6 +161,9 @@ function usbDeviceAttached(device) { } function usbDeviceDetached(device) { + if (!usbListenerRunning) { + return; + } if (isYubiKey(device)) { const index = attachedYubiKeys.findIndex((yk) => yk.deviceAddress === device.deviceAddress); if (index >= 0) { @@ -296,7 +303,9 @@ function startInMain(channel) { const { app } = require('electron'); app.on('will-quit', () => { - messageHandlers.stopUsbListener(); + if (usbListenerInitialized) { + reqNative('usb-detection').stopMonitoring(); + } }); } diff --git a/release-notes.md b/release-notes.md index f0d559e4..2cc5f6dd 100644 --- a/release-notes.md +++ b/release-notes.md @@ -7,6 +7,7 @@ Release notes `*` password generator now includes all selected character ranges `+` better Touch ID error messages `-` legacy auto-type removed +`-` fixed a crash after disabling USB devices on Linux ##### v1.17.6 (2021-04-09) `+` team drives support in Google Drive