allow daemon app launches to be more lenient about device ids (#6015)

This commit is contained in:
Devon Carew
2016-09-23 08:52:10 -07:00
committed by GitHub
parent 133a9c35db
commit 4c1e4a24ae

View File

@@ -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<Device> devices = discoverer.pollingGetDevices();
for (Device device in devices)
if (device.id == deviceId)
return device;
}
// No match found.
return null;
}
}
Map<String, String> _deviceToMap(Device device) {