Skip to content

Commit 10f83b1

Browse files
Fatme HavaluovaFatme Havaluova
authored andcommitted
Fix broken device option
1 parent 5f7e33c commit 10f83b1

8 files changed

+110
-54
lines changed

lib/declarations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ interface ICommandExecutor {
1717

1818
interface IDevice {
1919
device: any; // NodObjC wrapper to device
20-
deviceTypeIdentifier: string;
20+
deviceIdentifier: string;
21+
fullDeviceIdentifier: string;
2122
runtimeVersion: string;
2223
}
2324

@@ -27,6 +28,7 @@ interface IDictionary<T> {
2728

2829
interface ISimulator {
2930
validDeviceIdentifiers: string[];
31+
deviceIdentifiersInfo: string[];
3032
setSimulatedDevice(config: any): void;
3133
}
3234

lib/iphone-simulator-xcode-5.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/iphone-simulator-xcode-5.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export class XCode5Simulator implements ISimulator {
2626
return _.keys(XCode5Simulator.allowedDeviceIdentifiers);
2727
}
2828

29+
public get deviceIdentifiersInfo(): string[] {
30+
return _.keys(XCode5Simulator.allowedDeviceIdentifiers);
31+
}
32+
2933
public setSimulatedDevice(config:any): void {
3034
config("setSimulatedDeviceInfoName", $(this.deviceIdentifier));
3135
}

lib/iphone-simulator-xcode-6.js

Lines changed: 51 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/iphone-simulator-xcode-6.ts

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,69 @@ export class XCode6Simulator implements ISimulator {
1313
private static DEFAULT_DEVICE_IDENTIFIER = "iPhone-4s";
1414

1515

16-
private availableDevices: IDictionary<IDevice>;
16+
private availableDevices: IDictionary<IDevice[]>;
1717

1818
constructor() {
1919
this.availableDevices = Object.create(null);
2020
}
2121

2222
public get validDeviceIdentifiers(): string[] {
23-
var simDeviceSet = $.classDefinition.getClassByName("SimDeviceSet");
24-
var devicesInfo: string[] = [];
25-
26-
if(simDeviceSet) {
27-
var deviceSet = simDeviceSet("defaultSet");
28-
var devices = deviceSet("availableDevices");
29-
30-
var count = devices("count");
31-
for(var index=0; index < count; index++) {
32-
var device = devices("objectAtIndex", index);
33-
34-
var deviceIdentifier = device("deviceType")("identifier").toString();
35-
var deviceIdentifierPrefixIndex = deviceIdentifier.indexOf(XCode6Simulator.DEFAULT_DEVICE_IDENTIFIER);
36-
var deviceIdentifierWithoutPrefix = deviceIdentifier.substring(deviceIdentifierPrefixIndex + XCode6Simulator.DEVICE_IDENTIFIER_PREFIX.length + 2);
37-
38-
var runtimeVersion = device("runtime")("versionString").toString();
39-
var deviceInfo = [util.format("Device Identifier: %s", deviceIdentifierWithoutPrefix),
40-
util.format("Runtime Version: %s", runtimeVersion)].join(os.EOL);
41-
devicesInfo.push(deviceInfo + os.EOL);
42-
}
43-
}
23+
var devices = this.getDevicesInfo();
24+
return _.map(devices, device => device.deviceIdentifier);
25+
}
4426

45-
return devicesInfo;
27+
public get deviceIdentifiersInfo(): string[] {
28+
var devices = this.getDevicesInfo();
29+
return _.map(devices, device => util.format("Device Identifier: %s. %sRuntime Version: %s %s", device.fullDeviceIdentifier, os.EOL, device.runtimeVersion, os.EOL));
4630
}
4731

4832
public setSimulatedDevice(config: any): void {
4933
var device = this.getDeviceByIdentifier(this.deviceIdentifier);
5034
config("setDevice", device);
5135
}
5236

37+
private getDevicesInfo(): IDevice[] {
38+
var availableDeviceIdentifiers = this.getAvailableDevices();
39+
var keys = _.keys(availableDeviceIdentifiers);
40+
var result: IDevice[] = [];
41+
42+
_.each(keys, deviceIdentifier => {
43+
var devices = availableDeviceIdentifiers[deviceIdentifier];
44+
_.each(devices, device => result.push(device));
45+
});
46+
47+
return result;
48+
}
49+
5350
private get deviceIdentifier(): string {
5451
return options.device || XCode6Simulator.DEFAULT_DEVICE_IDENTIFIER;
5552
}
5653

57-
private getAvailableDevices(): IDictionary<IDevice> {
54+
private getAvailableDevices(): IDictionary<IDevice[]> {
5855
if(_.isEmpty(this.availableDevices)) {
5956
var deviceSet = $.classDefinition.getClassByName("SimDeviceSet")("defaultSet");
6057
var devices = deviceSet("availableDevices");
6158
var count = devices("count");
6259
if(count > 0) {
6360
for(var index=0; index<count; index++) {
6461
var device = devices("objectAtIndex", index);
65-
var deviceTypeIdentifier = device("deviceType")("identifier").toString();
62+
63+
var deviceIdentifier = device("deviceType")("identifier").toString();
64+
var deviceIdentifierPrefixIndex = deviceIdentifier.indexOf(XCode6Simulator.DEVICE_IDENTIFIER_PREFIX);
65+
var deviceIdentifierWithoutPrefix = deviceIdentifier.substring(deviceIdentifierPrefixIndex + XCode6Simulator.DEVICE_IDENTIFIER_PREFIX.length + 1);
66+
6667
var runtimeVersion = device("runtime")("versionString").toString();
67-
this.availableDevices[deviceTypeIdentifier] = {
68+
69+
if(!this.availableDevices[deviceIdentifier]) {
70+
this.availableDevices[deviceIdentifier] = [];
71+
}
72+
73+
this.availableDevices[deviceIdentifier].push({
6874
device: device,
69-
deviceTypeIdentifier: deviceTypeIdentifier,
75+
deviceIdentifier: deviceIdentifierWithoutPrefix,
76+
fullDeviceIdentifier: this.buildFullDeviceIdentifier(deviceIdentifier),
7077
runtimeVersion: runtimeVersion
71-
};
78+
});
7279
}
7380
}
7481
}
@@ -77,15 +84,19 @@ export class XCode6Simulator implements ISimulator {
7784
}
7885

7986
private getDeviceByIdentifier(deviceIdentifier: string): any {
80-
var fullDeviceIdentifier = util.format("%s.%s", XCode6Simulator.DEVICE_IDENTIFIER_PREFIX, deviceIdentifier);
8187
var availableDevices = this.getAvailableDevices();
8288
if(!_.isEmpty(availableDevices)) {
89+
var fullDeviceIdentifier = this.buildFullDeviceIdentifier(deviceIdentifier);
8390
var selectedDevice = availableDevices[fullDeviceIdentifier];
8491
if(selectedDevice) {
85-
return selectedDevice.device;
92+
return selectedDevice[0].device;
8693
}
8794
}
8895

8996
errors.fail("Unable to find device with identifier ", deviceIdentifier);
9097
}
98+
99+
private buildFullDeviceIdentifier(deviceIdentifier: string): string {
100+
return util.format("%s.%s", XCode6Simulator.DEVICE_IDENTIFIER_PREFIX, deviceIdentifier);
101+
}
91102
}

lib/iphone-simulator.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/iphone-simulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class iPhoneSimulator implements IiPhoneSimulator {
4040
public printDeviceTypes(): IFuture<void> {
4141
var action = () => {
4242
var simulator = this.createSimulator();
43-
_.each(simulator.validDeviceIdentifiers, (identifier: any) => console.log(identifier));
43+
_.each(simulator.deviceIdentifiersInfo, (identifier: any) => console.log(identifier));
4444
}
4545

4646
return this.execute(action, { canRunMainLoop: false });

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ios-sim-portable",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "",
55
"main": "./lib/ios-sim.js",
66
"scripts": {

0 commit comments

Comments
 (0)