Skip to content

Commit 2dc1738

Browse files
FatmeFatme Havaluova
Fatme
authored and
Fatme Havaluova
committed
Fix tns debug ios --emulator
Fixes NativeScript/nativescript-cli#1253
1 parent 2173df3 commit 2dc1738

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ interface ISimulator {
5555
interface IExecuteOptions {
5656
canRunMainLoop: boolean;
5757
appPath?: string;
58+
applicationIdentifier?: string;
5859
}
5960

6061
interface ISdk {

lib/iphone-interop-simulator-base.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export class IPhoneInteropSimulatorBase {
2626

2727
private static DEFAULT_TIMEOUT_IN_SECONDS = 90;
2828

29-
public run(appPath: string): IFuture<void> {
30-
return this.execute(this.launch, { canRunMainLoop: true, appPath: appPath });
29+
public run(appPath: string, applicationIdentifier: string): IFuture<void> {
30+
return this.execute(this.launch, { canRunMainLoop: true, appPath: appPath, applicationIdentifier: applicationIdentifier });
3131
}
32-
33-
private setupSessionDelegate(appPath: string): any {
32+
33+
private setupSessionDelegate(appPath: string, applicationIdentifier: string): any {
3434
let sessionDelegate = $.NSObject.extend("DTiPhoneSimulatorSessionDelegate");
3535
sessionDelegate.addMethod("session:didEndWithError:", "v@:@@", function(self: any, sel: any, sess: any, error: any) {
3636
IPhoneInteropSimulatorBase.logSessionInfo(error, "Session ended without errors.", "Session ended with error ");
@@ -39,16 +39,16 @@ export class IPhoneInteropSimulatorBase {
3939
sessionDelegate.addMethod("session:didStart:withError:", "v@:@c@", function(self: any, sel: string, session: any, started: boolean, error:any) {
4040
IPhoneInteropSimulatorBase.logSessionInfo(error, "Session started without errors.", "Session started with error ");
4141

42-
console.log(`${appPath}: ${session("simulatedApplicationPID")}`);
42+
console.log(`${applicationIdentifier}: ${session("simulatedApplicationPID")}`);
4343
if (options.exit) {
4444
process.exit(0);
4545
}
4646
});
4747
sessionDelegate.register();
48-
48+
4949
return sessionDelegate;
5050
}
51-
51+
5252
private getTimeout(): number {
5353
let timeoutParam = IPhoneInteropSimulatorBase.DEFAULT_TIMEOUT_IN_SECONDS;
5454
if (options.timeout || options.timeout === 0) {
@@ -62,7 +62,7 @@ export class IPhoneInteropSimulatorBase {
6262
}
6363
return timeoutParam;
6464
}
65-
65+
6666
private validateDevice() {
6767
if (options.device) {
6868
let devices = this.simulator.getDevices().wait();
@@ -73,8 +73,8 @@ export class IPhoneInteropSimulatorBase {
7373
}
7474
}
7575

76-
private launch(appPath: string): void {
77-
let sessionDelegate = this.setupSessionDelegate(appPath);
76+
private launch(appPath: string, applicationIdentifier: string): void {
77+
let sessionDelegate = this.setupSessionDelegate(appPath, applicationIdentifier);
7878

7979
let appSpec = this.getClassByName("DTiPhoneSimulatorApplicationSpecifier")("specifierWithApplicationPath", $(appPath));
8080
let config = this.getClassByName("DTiPhoneSimulatorSessionConfig")("alloc")("init")("autorelease");
@@ -125,7 +125,7 @@ export class IPhoneInteropSimulatorBase {
125125
}
126126
}
127127

128-
protected execute(action: (appPath?: string) => any, opts: IExecuteOptions): IFuture<any> {
128+
protected execute(action: (appPath?: string, applicationIdentifier?: string) => any, opts: IExecuteOptions): IFuture<any> {
129129
$.importFramework(IPhoneInteropSimulatorBase.FOUNDATION_FRAMEWORK_NAME);
130130
$.importFramework(IPhoneInteropSimulatorBase.APPKIT_FRAMEWORK_NAME);
131131

@@ -136,14 +136,14 @@ export class IPhoneInteropSimulatorBase {
136136

137137
this.loadFrameworks(developerDirectoryPath);
138138

139-
let result = action.apply(this, [opts.appPath]);
139+
let result = action.apply(this, [opts.appPath, opts.applicationIdentifier]);
140140
return this.runCFLoop(opts.canRunMainLoop, result);
141141
}
142-
142+
143143
private runCFLoop(canRunMainLoop: boolean, result: any): IFuture<any> {
144144
let pool = $.NSAutoreleasePool("alloc")("init");
145145
let future = new Future<any>();
146-
146+
147147
if (canRunMainLoop) {
148148
// Keeps the Node loop running
149149
(function runLoop() {
@@ -157,7 +157,7 @@ export class IPhoneInteropSimulatorBase {
157157
} else {
158158
future.return(result);
159159
}
160-
160+
161161
return future;
162162
}
163163

lib/simctl.ts

+19-10
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,28 @@ import options = require("./options");
99
export class Simctl implements ISimctl {
1010

1111
public launch(deviceId: string, applicationIdentifier: string): IFuture<string> {
12-
let args: string[] = [];
13-
if (options.waitForDebugger) {
14-
args.push("-w");
15-
}
12+
return (() => {
13+
let args: string[] = [];
14+
if (options.waitForDebugger) {
15+
args.push("-w");
16+
}
1617

17-
args = args.concat([deviceId, applicationIdentifier]);
18+
args = args.concat([deviceId, applicationIdentifier]);
19+
20+
if(options.args) {
21+
let applicationArgs = options.args.trim().split(/\s+/);
22+
_.each(applicationArgs, (arg: string) => args.push(arg));
23+
}
24+
25+
let result = this.simctlExec("launch", args).wait();
26+
27+
if (options.waitForDebugger) {
28+
console.log(`${applicationIdentifier}: ${applicationIdentifier}`);
29+
}
1830

19-
if(options.args) {
20-
let applicationArgs = options.args.trim().split(/\s+/);
21-
_.each(applicationArgs, (arg: string) => args.push(arg));
22-
}
31+
return result;
2332

24-
return this.simctlExec("launch", args);
33+
}).future<string>()();
2534
}
2635

2736
public install(deviceId: string, applicationPath: string): IFuture<void> {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ios-sim-portable",
3-
"version": "1.0.13",
3+
"version": "1.0.14",
44
"description": "",
55
"main": "./lib/ios-sim.js",
66
"scripts": {

0 commit comments

Comments
 (0)