From 4c1e4a24ae3b3504f1ccc588eaeb1e7310a61336 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 23 Sep 2016 08:52:10 -0700 Subject: [PATCH] allow daemon app launches to be more lenient about device ids (#6015) --- .../lib/src/commands/daemon.dart | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 4e662b293a..2ac2a1fbec 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -295,7 +295,7 @@ class AppDomain extends Domain { String target = _getStringArg(args, 'target'); bool hotMode = _getBoolArg(args, 'hot') ?? false; - Device device = daemon.deviceDomain._getDevice(deviceId); + Device device = daemon.deviceDomain._getOrLocateDevice(deviceId); if (device == null) throw "device '$deviceId' not found"; @@ -536,6 +536,25 @@ class DeviceDomain extends Domain { }).toList(); return devices.firstWhere((Device device) => device.id == deviceId, orElse: () => null); } + + /// Return a known matching device, or scan for devices if no known match is found. + Device _getOrLocateDevice(String deviceId) { + // Look for an already known device. + Device device = _getDevice(deviceId); + if (device != null) + return device; + + // Scan the different device providers for a match. + for (PollingDeviceDiscovery discoverer in _discoverers) { + List devices = discoverer.pollingGetDevices(); + for (Device device in devices) + if (device.id == deviceId) + return device; + } + + // No match found. + return null; + } } Map _deviceToMap(Device device) {