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) {
|
pids.forEach((pid, count) {
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
usbDevices.add(DeviceNode.usbYubiKey(
|
usbDevices.add(DeviceNode.usbYubiKey(
|
||||||
DevicePath(['invalid', '$pid-$i']),
|
DevicePath(['pid', pid.value.toString(), i.toString()]),
|
||||||
pid.displayName,
|
pid.displayName,
|
||||||
pid,
|
pid,
|
||||||
null) as UsbYubiKeyNode);
|
null) as UsbYubiKeyNode);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
@ -162,11 +163,17 @@ class DesktopCurrentDeviceNotifier extends CurrentDeviceNotifier {
|
|||||||
|
|
||||||
if (!devices.contains(_deviceNode)) {
|
if (!devices.contains(_deviceNode)) {
|
||||||
final lastDevice = prefs.getString(_lastDevice) ?? '';
|
final lastDevice = prefs.getString(_lastDevice) ?? '';
|
||||||
try {
|
_deviceNode =
|
||||||
_deviceNode = devices.firstWhere((dev) => dev.path.key == lastDevice,
|
devices.where((dev) => dev.path.key == lastDevice).firstOrNull;
|
||||||
orElse: () => devices.whereType<UsbYubiKeyNode>().first);
|
if (_deviceNode == null) {
|
||||||
} on StateError {
|
final parts = lastDevice.split('/');
|
||||||
_deviceNode = null;
|
if (parts.firstOrNull == 'pid') {
|
||||||
|
_deviceNode = devices
|
||||||
|
.whereType<UsbYubiKeyNode>()
|
||||||
|
.where((e) => e.pid.value.toString() == parts[1])
|
||||||
|
.firstOrNull;
|
||||||
|
}
|
||||||
|
_deviceNode ??= devices.whereType<UsbYubiKeyNode>().firstOrNull;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _deviceNode;
|
return _deviceNode;
|
||||||
|
Loading…
Reference in New Issue
Block a user