diff --git a/src/lib.js b/src/lib.js index 0357d3f..c7fcba2 100644 --- a/src/lib.js +++ b/src/lib.js @@ -115,7 +115,7 @@ function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly) function findAvailableRuntime(list, device_name) { var all_druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true); - var druntime = all_druntimes[device_name]; + var druntime = all_druntimes[ filterDeviceName(device_name) ]; var runtime_found = druntime && druntime.length > 0; if (!runtime_found) { @@ -203,7 +203,7 @@ function getDeviceFromDeviceTypeId(devicetypeid) { // found the runtime, now find the actual device matching devicename if (deviceGroup.runtime === ret_obj.runtime) { return deviceGroup.devices.some(function(device) { - if (device.name === ret_obj.name) { + if (filterDeviceName(device.name) === filterDeviceName(ret_obj.name)) { ret_obj.id = device.id; return true; } @@ -223,6 +223,15 @@ function getDeviceFromDeviceTypeId(devicetypeid) { return ret_obj; } +// replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices' +function filterDeviceName(deviceName) { + // replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices' + if (deviceName.indexOf('iPad Pro') === 0) { + return deviceName.replace(/\-/g, ' ').trim(); + } + return deviceName; +} + var lib = { init: function() { @@ -264,11 +273,7 @@ var lib = { var name_id_map = {}; list.devicetypes.forEach(function(device) { - // replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices' - if (device.name.indexOf('iPad Pro') === 0) { - device.name = device.name.replace(/\-/g, ' ').trim(); - } - name_id_map[ device.name ] = device.id; + name_id_map[ filterDeviceName(device.name) ] = device.id; }); list = []; @@ -279,13 +284,9 @@ var lib = { for (var deviceName in druntimes) { var runtimes = druntimes[ deviceName ]; + var dname = filterDeviceName(deviceName); - // replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices' - if (deviceName.indexOf('iPad Pro') === 0) { - deviceName = deviceName.replace(/\-/g, ' ').trim(); - } - - if (!(deviceName in name_id_map)) { + if (!(dname in name_id_map)) { continue; } runtimes.forEach(remove);