Skip to content

Use Debugger UI from a dedicated npm package #1442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/npm-installation-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
private packageSpecificDirectories: IStringDictionary = {
"tns-android": constants.PROJECT_FRAMEWORK_FOLDER_NAME,
"tns-ios": constants.PROJECT_FRAMEWORK_FOLDER_NAME,
"tns-ios-inspector": "WebInspectorUI",
"tns-template-hello-world": constants.APP_RESOURCES_FOLDER_NAME,
"tns-template-hello-world-ts": constants.APP_RESOURCES_FOLDER_NAME
};
Expand Down
59 changes: 44 additions & 15 deletions lib/services/ios-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
"use strict";

import * as iOSDevice from "../common/mobile/ios/device/ios-device";

import * as net from "net";
import * as path from "path";
import * as semver from "semver";
import byline = require("byline");

let InspectorBackendPort = 18181;
const inspectorBackendPort = 18181;
const inspectorAppName = "NativeScript Inspector.app";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the first constant name InspectorBackendPort starts with capital letter and the others do not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it was old code and I missed it. Will fix it.

const inspectorZipName = "NativeScript Inspector.zip";
const inspectorNpmPackageName = "tns-ios-inspector";
const inspectorUiDir = "WebInspectorUI/";
const TIMEOUT_SECONDS = 90;

class IOSDebugService implements IDebugService {
private static TIMEOUT_SECONDS = 90;

constructor(
private $platformService: IPlatformService,
private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices,
Expand Down Expand Up @@ -91,13 +93,13 @@ class IOSDebugService implements IDebugService {
}
});

this.wireDebuggerClient(() => net.connect(InspectorBackendPort)).wait();
this.wireDebuggerClient(() => net.connect(inspectorBackendPort)).wait();
}).future<void>()();
}

private emulatorStart(): IFuture<void> {
return (() => {
this.wireDebuggerClient(() => net.connect(InspectorBackendPort)).wait();
this.wireDebuggerClient(() => net.connect(inspectorBackendPort)).wait();

let attachRequestMessage = this.$iOSNotification.attachRequest;

Expand All @@ -120,11 +122,11 @@ class IOSDebugService implements IDebugService {

private debugBrkCore(device: Mobile.IiOSDevice): IFuture<void> {
return (() => {
let timeout = this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS);
let timeout = this.$utils.getMilliSecondsTimeout(TIMEOUT_SECONDS);
let readyForAttachTimeout = this.getReadyForAttachTimeout(timeout);

this.$iOSSocketRequestExecutor.executeLaunchRequest(device, timeout, readyForAttachTimeout).wait();
this.wireDebuggerClient(() => device.connectToPort(InspectorBackendPort)).wait();
this.wireDebuggerClient(() => device.connectToPort(inspectorBackendPort)).wait();
}).future<void>()();
}

Expand All @@ -139,7 +141,7 @@ class IOSDebugService implements IDebugService {
return (() => {
let timeout = this.getReadyForAttachTimeout();
this.$iOSSocketRequestExecutor.executeAttachRequest(device, timeout).wait();
this.wireDebuggerClient(() => device.connectToPort(InspectorBackendPort)).wait();
this.wireDebuggerClient(() => device.connectToPort(inspectorBackendPort)).wait();
}).future<void>()();
}

Expand All @@ -164,15 +166,24 @@ class IOSDebugService implements IDebugService {
return (() => {
let frameworkVersion = this.getProjectFrameworkVersion().wait();
let inspectorPath = this.getInspectorPath(frameworkVersion).wait();
let inspectorSourceLocation = path.join(inspectorPath, "Safari/Main.html");
let inspectorSourceLocation: string;
let cmd: string = null;

if(semver.lt(frameworkVersion, "1.2.0")) {
if (semver.lt(frameworkVersion, "1.2.0")) {
cmd = `open -a Safari "${inspectorSourceLocation}"`;
} else {
let inspectorApplicationPath = path.join(inspectorPath, "NativeScript Inspector.app");
let inspectorApplicationDir: string;
if (semver.lt(frameworkVersion, "1.6.0")) {
inspectorApplicationDir = inspectorPath;
inspectorSourceLocation = path.join(inspectorPath, "Safari/Main.html");
} else {
inspectorApplicationDir = path.join(inspectorPath, "..");
inspectorSourceLocation = path.join(inspectorPath, "Main.html");
}

let inspectorApplicationPath = path.join(inspectorApplicationDir, inspectorAppName);
if(!this.$fs.exists(inspectorApplicationPath).wait()) {
this.$fs.unzip(path.join(inspectorPath, "NativeScript Inspector.zip"), inspectorPath).wait();
this.$fs.unzip(path.join(inspectorApplicationDir, inspectorZipName), inspectorApplicationDir).wait();
}
cmd = `open -a '${inspectorApplicationPath}' --args '${inspectorSourceLocation}' '${this.$projectData.projectName}' '${fileDescriptor}'`;
}
Expand All @@ -190,6 +201,24 @@ class IOSDebugService implements IDebugService {
}

private getInspectorPath(frameworkVersion: string): IFuture<string> {
return (() => {
if (semver.lt(frameworkVersion, "1.6.0")) {
return this.getInspectorPathFromDebuggerPackage(frameworkVersion).wait();
} else {
return this.getInspectorPathFromTnsIosPackage(frameworkVersion).wait();
}
}).future<string>()();
}

private getInspectorPathFromDebuggerPackage(frameworkVersion: string): IFuture<string> {
return (() => {
let inspectorPackage = this.$npmInstallationManager.install(inspectorNpmPackageName).wait();
let inspectorPath = path.join(inspectorPackage, inspectorUiDir);
return inspectorPath;
}).future<string>()();
}

private getInspectorPathFromTnsIosPackage(frameworkVersion: string): IFuture<string> {
return (() => {
let tnsIosPackage = "";
if (this.$options.frameworkPath) {
Expand All @@ -201,13 +230,13 @@ class IOSDebugService implements IDebugService {
let platformData = this.$platformsData.getPlatformData(this.platform);
tnsIosPackage = this.$npmInstallationManager.install(platformData.frameworkPackageName, { version: frameworkVersion }).wait();
}
let inspectorPath = path.join(tnsIosPackage, "WebInspectorUI/");
let inspectorPath = path.join(tnsIosPackage, inspectorUiDir);
return inspectorPath;
}).future<string>()();
}

private getReadyForAttachTimeout(timeoutInMilliseconds?: number): number {
let timeout = timeoutInMilliseconds || this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS);
let timeout = timeoutInMilliseconds || this.$utils.getMilliSecondsTimeout(TIMEOUT_SECONDS);
let readyForAttachTimeout = timeout / 10 ;
let defaultReadyForAttachTimeout = 5000;
return readyForAttachTimeout > defaultReadyForAttachTimeout ? readyForAttachTimeout : defaultReadyForAttachTimeout;
Expand Down