Skip to content

Commit 5dc4c8a

Browse files
EtienneLemshazron
authored andcommitted
Support iPhone XS, iPhone XS Max and iPhone XR (#236)
* Support iPhone XS, iPhone XS Max and iPhone XR * Make “iPad Pro” test case insensitive in `filterDeviceName`
1 parent a4ab922 commit 5dc4c8a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/lib.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function findFirstAvailableDevice(list) {
7171
return ret_obj;
7272
}
7373

74-
function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly) {
74+
function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly, options = {}) {
7575
/*
7676
// Example result:
7777
{
@@ -91,6 +91,9 @@ function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly)
9191
list.devices[deviceGroup].forEach(function(device) {
9292
var devicePropertyValue = device[deviceProperty];
9393

94+
if (options.lowerCase) {
95+
devicePropertyValue = devicePropertyValue.toLowerCase();
96+
}
9497
if (!runtimes[devicePropertyValue]) {
9598
runtimes[devicePropertyValue] = [];
9699
}
@@ -108,8 +111,9 @@ function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly)
108111
}
109112

110113
function findAvailableRuntime(list, device_name) {
114+
device_name = device_name.toLowerCase();
111115

112-
var all_druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true);
116+
var all_druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true, { lowerCase: true });
113117
var druntime = all_druntimes[ filterDeviceName(device_name) ] || all_druntimes[ device_name ];
114118
var runtime_found = druntime && druntime.length > 0;
115119

@@ -199,7 +203,7 @@ function getDeviceFromDeviceTypeId(devicetypeid) {
199203
// found the runtime, now find the actual device matching devicename
200204
if (deviceGroup === ret_obj.runtime) {
201205
return list.devices[deviceGroup].some(function(device) {
202-
if (filterDeviceName(device.name) === filterDeviceName(ret_obj.name)) {
206+
if (filterDeviceName(device.name).toLowerCase() === filterDeviceName(ret_obj.name).toLowerCase()) {
203207
ret_obj.id = device.udid;
204208
return true;
205209
}
@@ -260,9 +264,13 @@ function withInjectedEnvironmentVariablesToProcess(process, envVariables, action
260264
// replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices'
261265
function filterDeviceName(deviceName) {
262266
// replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices'
263-
if (deviceName.indexOf('iPad Pro') === 0) {
267+
if (/^iPad Pro/i.test(deviceName)) {
264268
return deviceName.replace(/\-/g, ' ').trim();
265269
}
270+
// replace ʀ in iPhone Xʀ
271+
if (deviceName.indexOf('ʀ') > -1) {
272+
return deviceName.replace('ʀ', 'R');
273+
}
266274
return deviceName;
267275
}
268276

@@ -345,11 +353,11 @@ var lib = {
345353
var list = simctl.list(options).json;
346354
list = fixSimCtlList(list);
347355

348-
var druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true);
356+
var druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true, { lowerCase: true });
349357
var name_id_map = {};
350358

351359
list.devicetypes.forEach(function(device) {
352-
name_id_map[ filterDeviceName(device.name) ] = device.identifier;
360+
name_id_map[ filterDeviceName(device.name).toLowerCase() ] = device.identifier;
353361
});
354362

355363
list = [];
@@ -366,7 +374,7 @@ var lib = {
366374

367375
for (var deviceName in druntimes) {
368376
var runtimes = druntimes[ deviceName ];
369-
var dname = filterDeviceName(deviceName);
377+
var dname = filterDeviceName(deviceName).toLowerCase();
370378

371379
if (!(dname in name_id_map)) {
372380
continue;

0 commit comments

Comments
 (0)