mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-29 23:20:03 +03:00
Retain device better when elevating to admin.
This commit is contained in:
parent
d5ce976a9a
commit
e19f1a3bc5
@ -118,7 +118,7 @@ class UsbDeviceNotifier extends StateNotifier<List<UsbYubiKeyNode>> {
|
||||
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);
|
||||
|
@ -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<UsbYubiKeyNode>().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<UsbYubiKeyNode>()
|
||||
.where((e) => e.pid.value.toString() == parts[1])
|
||||
.firstOrNull;
|
||||
}
|
||||
_deviceNode ??= devices.whereType<UsbYubiKeyNode>().firstOrNull;
|
||||
}
|
||||
}
|
||||
return _deviceNode;
|
||||
|
Loading…
Reference in New Issue
Block a user