diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index 1c013ea084..0ba100803f 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -171,8 +171,7 @@ bool DatabaseOpenWidget::event(QEvent* event) bool ret = DialogyWidget::event(event); switch (event->type()) { - case QEvent::Show: - case QEvent::WindowActivate: { + case QEvent::Show: { if (isOnQuickUnlockScreen() && (m_db.isNull() || !canPerformQuickUnlock())) { resetQuickUnlock(); } @@ -512,7 +511,10 @@ void DatabaseOpenWidget::pollHardwareKey(bool manualTrigger) m_pollingHardwareKey = true; m_manualHardwareKeyRefresh = manualTrigger; - YubiKey::instance()->findValidKeysAsync(); + // Add a delay, if this is an automatic trigger, to allow the USB device to settle as + // the device may not report a valid serial number immediately after plugging in + int delay = manualTrigger ? 0 : 1000; + QTimer::singleShot(delay, this, [this] { YubiKey::instance()->findValidKeysAsync(); }); } void DatabaseOpenWidget::hardwareKeyResponse(bool found) diff --git a/src/gui/osutils/macutils/DeviceListenerMac.cpp b/src/gui/osutils/macutils/DeviceListenerMac.cpp index 41d0ddb422..e3785a04a1 100644 --- a/src/gui/osutils/macutils/DeviceListenerMac.cpp +++ b/src/gui/osutils/macutils/DeviceListenerMac.cpp @@ -54,7 +54,7 @@ void DeviceListenerMac::registerHotplugCallback(bool arrived, bool left, int ven CFRelease(vid); } if (productId > 0) { - auto pid = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vendorId); + auto pid = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &productId); CFDictionaryAddValue(matchingDict, CFSTR(kIOHIDProductIDKey), pid); CFRelease(pid); } diff --git a/src/keys/drivers/YubiKeyInterfaceUSB.cpp b/src/keys/drivers/YubiKeyInterfaceUSB.cpp index 80d200f919..fde232d6f4 100644 --- a/src/keys/drivers/YubiKeyInterfaceUSB.cpp +++ b/src/keys/drivers/YubiKeyInterfaceUSB.cpp @@ -50,10 +50,22 @@ namespace yk_close_key(key); } + void printError() + { + if (yk_errno == YK_EUSBERR) { + qWarning("Hardware key USB error: %s", yk_usb_strerror()); + } else { + qWarning("Hardware key error: %s", yk_strerror(yk_errno)); + } + } + unsigned int getSerial(YK_KEY* key) { unsigned int serial; - yk_get_serial(key, 1, 0, &serial); + if (!yk_get_serial(key, 1, 0, &serial)) { + printError(); + return 0; + } return serial; } @@ -70,11 +82,8 @@ namespace } else if (yk_errno == YK_ENOKEY) { // No more connected keys break; - } else if (yk_errno == YK_EUSBERR) { - qWarning("Hardware key USB error: %s", yk_usb_strerror()); - } else { - qWarning("Hardware key error: %s", yk_strerror(yk_errno)); } + printError(); } return nullptr; }