Commit 4c1e4a24 authored by Devon Carew's avatar Devon Carew Committed by GitHub

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

parent 133a9c35
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment