From 144bc1f20ef15a6a5f21280bdf769a34cbb86804 Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Thu, 12 Jan 2023 13:14:31 +0100 Subject: [PATCH] Fix current device state for desktop. --- lib/desktop/state.dart | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/desktop/state.dart b/lib/desktop/state.dart index 5e95e28e..c5cce453 100755 --- a/lib/desktop/state.dart +++ b/lib/desktop/state.dart @@ -154,29 +154,24 @@ final desktopSupportedThemesProvider = StateProvider>( class DesktopCurrentDeviceNotifier extends CurrentDeviceNotifier { static const String _lastDevice = 'APP_STATE_LAST_DEVICE'; - DeviceNode? _deviceNode; @override DeviceNode? build() { SharedPreferences prefs = ref.watch(prefProvider); - var devices = ref.watch(attachedDevicesProvider); + final devices = ref.watch(attachedDevicesProvider); + final lastDevice = prefs.getString(_lastDevice) ?? ''; - if (!devices.contains(_deviceNode)) { - final lastDevice = prefs.getString(_lastDevice) ?? ''; - _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; + var node = devices.where((dev) => dev.path.key == lastDevice).firstOrNull; + if (node == null) { + final parts = lastDevice.split('/'); + if (parts.firstOrNull == 'pid') { + node = devices + .whereType() + .where((e) => e.pid.value.toString() == parts[1]) + .firstOrNull; } } - return _deviceNode; + return node ?? devices.whereType().firstOrNull; } @override