fix #1783: crash after disabling USB devices on Linux

pull/1856/head
antelle 2 years ago
parent 9d0e608454
commit 19a42b7463
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C

@ -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();
}
});
}

@ -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

Loading…
Cancel
Save