Retain device better when elevating to admin.

This commit is contained in:
Dain Nilsson 2022-12-21 15:48:22 +01:00
parent d5ce976a9a
commit e19f1a3bc5
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
2 changed files with 13 additions and 6 deletions

View File

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

View File

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