@@ -27,11 +27,25 @@ export class iPhoneSimulator implements IiPhoneSimulator {
27
27
private static SIMULATOR_FRAMEWORK_RELATIVE_PATH = "../SharedFrameworks/DVTiPhoneSimulatorRemoteClient.framework" ;
28
28
29
29
public run ( appPath : string ) : IFuture < void > {
30
- return ( ( ) => {
31
- if ( ! fs . existsSync ( appPath ) ) {
32
- errors . fail ( "Path does not exist " , appPath ) ;
33
- }
30
+ if ( ! fs . existsSync ( appPath ) ) {
31
+ errors . fail ( "Path does not exist " , appPath ) ;
32
+ }
33
+
34
+ return this . execute ( this . launch , { canRunMainLoop : true , appPath : appPath } ) ;
35
+ }
36
+
37
+ public printDeviceTypes ( ) : IFuture < void > {
38
+
39
+ var action = ( ) => {
40
+ var simulator = this . createSimulator ( ) ;
41
+ _ . each ( simulator . validDeviceIdentifiers , ( identifier : any ) => console . log ( identifier ) ) ;
42
+ }
34
43
44
+ return this . execute ( action , { canRunMainLoop : false } ) ;
45
+ }
46
+
47
+ private execute ( action : ( appPath ?: string ) => any , opts : IExecuteOptions ) : IFuture < void > {
48
+ return ( ( ) => {
35
49
$ . importFramework ( iPhoneSimulator . FOUNDATION_FRAMEWORK_NAME ) ;
36
50
$ . importFramework ( iPhoneSimulator . APPKIT_FRAMEWORK_NAME ) ;
37
51
@@ -43,17 +57,18 @@ export class iPhoneSimulator implements IiPhoneSimulator {
43
57
}
44
58
45
59
this . loadFrameworks ( developerDirectoryPath ) ;
46
- this . launch ( developerDirectoryPath , appPath ) ;
47
60
48
- $ . NSRunLoop ( "mainRunLoop" ) ( "run" ) ;
61
+ action . apply ( this , [ opts . appPath ] ) ;
62
+
63
+ if ( opts . canRunMainLoop ) {
64
+ $ . NSRunLoop ( "mainRunLoop" ) ( "run" ) ;
65
+ }
49
66
50
67
pool ( "release" ) ;
51
68
} ) . future < void > ( ) ( ) ;
52
69
}
53
70
54
- private launch ( developerDirectoryPath : string , appPath : string ) : void {
55
- this . loadFrameworks ( developerDirectoryPath ) ;
56
-
71
+ private launch ( appPath : string ) : void {
57
72
var sessionDelegate = $ . NSObject . extend ( "DTiPhoneSimulatorSessionDelegate" ) ;
58
73
sessionDelegate . addMethod ( "session:didEndWithError:" , "v@:@@" , function ( self : any , sel : any , sess : any , error : any ) {
59
74
iPhoneSimulator . logSessionInfo ( error , "Session ended without errors." , "Session ended with error " ) ;
@@ -71,13 +86,7 @@ export class iPhoneSimulator implements IiPhoneSimulator {
71
86
var sdkRoot = options . sdkRoot ? $ ( options . sdkRoot ) : this . getClassByName ( "DTiPhoneSimulatorSystemRoot" ) ( "defaultRoot" ) ;
72
87
config ( "setSimulatedSystemRoot" , sdkRoot ) ;
73
88
74
- var simulator : ISimulator ;
75
- if ( _ . contains ( config . methods ( ) , "setDevice:" ) ) {
76
- simulator = new xcode6SimulatorLib . XCode6Simulator ( ) ;
77
- } else {
78
- simulator = new xcode5SimulatorLib . XCode5Simulator ( ) ;
79
- }
80
-
89
+ var simulator = this . createSimulator ( config ) ;
81
90
if ( options . device ) {
82
91
var validDeviceIdentifiers = simulator . validDeviceIdentifiers ;
83
92
if ( ! _ . contains ( validDeviceIdentifiers , options . device ) ) {
@@ -168,8 +177,23 @@ export class iPhoneSimulator implements IiPhoneSimulator {
168
177
if ( error ) {
169
178
console . log ( util . format ( "%s %s" , errorMessage , error ) ) ;
170
179
process . exit ( 1 ) ;
180
+ }
181
+
182
+ console . log ( successfulMessage ) ;
183
+ }
184
+
185
+ private createSimulator ( config ?: any ) : ISimulator {
186
+ if ( ! config ) {
187
+ config = this . getClassByName ( "DTiPhoneSimulatorSessionConfig" ) ( "alloc" ) ( "init" ) ( "autorelease" ) ;
188
+ }
189
+
190
+ var simulator : ISimulator ;
191
+ if ( _ . contains ( config . methods ( ) , "setDevice:" ) ) {
192
+ simulator = new xcode6SimulatorLib . XCode6Simulator ( ) ;
171
193
} else {
172
- console . log ( successfulMessage ) ;
194
+ simulator = new xcode5SimulatorLib . XCode5Simulator ( ) ;
173
195
}
196
+
197
+ return simulator ;
174
198
}
175
199
}
0 commit comments