diff --git a/lib/desktop/devices.dart b/lib/desktop/devices.dart index dab692ef..7c35404f 100755 --- a/lib/desktop/devices.dart +++ b/lib/desktop/devices.dart @@ -118,7 +118,7 @@ class UsbDeviceNotifier extends StateNotifier> { pids.forEach((pid, count) { for (var i = 0; i < count; i++) { usbDevices.add(DeviceNode.usbYubiKey( - DevicePath(['invalid', '$pid-$i']), + DevicePath(['pid', pid.value.toString(), i.toString()]), pid.displayName, pid, null) as UsbYubiKeyNode); diff --git a/lib/desktop/state.dart b/lib/desktop/state.dart index 5965dbef..5e95e28e 100755 --- a/lib/desktop/state.dart +++ b/lib/desktop/state.dart @@ -17,6 +17,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -162,11 +163,17 @@ class DesktopCurrentDeviceNotifier extends CurrentDeviceNotifier { if (!devices.contains(_deviceNode)) { final lastDevice = prefs.getString(_lastDevice) ?? ''; - try { - _deviceNode = devices.firstWhere((dev) => dev.path.key == lastDevice, - orElse: () => devices.whereType().first); - } on StateError { - _deviceNode = null; + _deviceNode = + devices.where((dev) => dev.path.key == lastDevice).firstOrNull; + if (_deviceNode == null) { + final parts = lastDevice.split('/'); + if (parts.firstOrNull == 'pid') { + _deviceNode = devices + .whereType() + .where((e) => e.pid.value.toString() == parts[1]) + .firstOrNull; + } + _deviceNode ??= devices.whereType().firstOrNull; } } return _deviceNode;