Skip to content

Commit

Permalink
Fixes #202 - (Re-fix) lib.js/getdevicetypes gets wrong list of device…
Browse files Browse the repository at this point in the history
…s versus showdevicetypes
  • Loading branch information
shazron committed Nov 28, 2016
1 parent aaf3b2e commit 840bf11
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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);
Expand Down

0 comments on commit 840bf11

Please sign in to comment.