Skip to content

Commit a2f77ef

Browse files
fix: tns debug ios --start fails
The `tns debug ios --start` command fails as we do not get the port from iOS Application on device in this case. In order to fix this, start the log parsing in case --start option is passed. Also fix the attaching to ATTACH_REQUEST_EVENT_NAME - we've incorrectly attached to device's application manager, which does not emit such event. Fix it by attaching to `iOSNotification`, which is the correct one. Also remove incorrect cache decorator and ensure we do not start logging for iOS devices more than once.
1 parent 4329c69 commit a2f77ef

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

lib/declarations.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ interface ISocketProxyFactory extends NodeJS.EventEmitter {
643643
createWebSocketProxy(factory: () => Promise<any>, deviceIdentifier: string): Promise<any>;
644644
}
645645

646-
interface IiOSNotification {
646+
interface IiOSNotification extends NodeJS.EventEmitter {
647647
getWaitForDebug(projectId: string): string;
648648
getAttachRequest(projectId: string, deviceId: string): string;
649649
getAppLaunching(projectId: string): string;
@@ -843,4 +843,4 @@ interface IAssetsGenerationService {
843843
* @returns {Promise<void>}
844844
*/
845845
generateSplashScreens(splashesGenerationData: ISplashesGenerationData): Promise<void>;
846-
}
846+
}

lib/device-sockets/ios/notification.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export class IOSNotification extends EventEmitter implements IiOSNotification {
1515
}
1616

1717
public getAttachRequest(appId: string, deviceId: string): string {
18+
// It could be too early to emit this event, but we rely that if you construct attach request,
19+
// you will execute it immediately.
1820
this.emit(ATTACH_REQUEST_EVENT_NAME, { deviceId, appId });
1921
return this.formatNotification(IOSNotification.ATTACH_REQUEST_NOTIFICATION_NAME, appId);
2022
}

lib/services/ios-debug-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
127127
}
128128

129129
private async emulatorStart(debugData: IDebugData, debugOptions: IDebugOptions): Promise<string> {
130+
const device = await this.$devicesService.getDevice(debugData.deviceIdentifier);
131+
this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device);
130132
const result = await this.wireDebuggerClient(debugData, debugOptions);
131133

132134
const attachRequestMessage = this.$iOSNotification.getAttachRequest(debugData.applicationIdentifier, debugData.deviceIdentifier);
@@ -175,6 +177,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
175177
}
176178

177179
private async deviceStartCore(device: Mobile.IiOSDevice, debugData: IDebugData, debugOptions: IDebugOptions): Promise<string> {
180+
this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device);
178181
await this.$iOSSocketRequestExecutor.executeAttachRequest(device, AWAIT_NOTIFICATION_TIMEOUT_SECONDS, debugData.applicationIdentifier);
179182
return this.wireDebuggerClient(debugData, debugOptions, device);
180183
}

lib/services/ios-debugger-port-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
99

1010
constructor(private $iOSLogParserService: IIOSLogParserService,
1111
private $iOSProjectService: IPlatformProjectService,
12+
private $iOSNotification: IiOSNotification,
1213
private $logger: ILogger,
1314
private $projectData: IProjectData) { }
1415

@@ -62,7 +63,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
6263

6364
@cache()
6465
private attachToAttachRequestEvent(device: Mobile.IDevice): void {
65-
device.applicationManager.on(ATTACH_REQUEST_EVENT_NAME, (data: IIOSDebuggerPortData) => {
66+
this.$iOSNotification.on(ATTACH_REQUEST_EVENT_NAME, (data: IIOSDebuggerPortData) => {
6667
this.$logger.trace(ATTACH_REQUEST_EVENT_NAME, data);
6768
const timer = setTimeout(() => {
6869
this.clearTimeout(data);

lib/services/ios-log-parser-service.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
import { DEBUGGER_PORT_FOUND_EVENT_NAME, DEVICE_LOG_EVENT_NAME } from "../common/constants";
2-
import { cache } from "../common/decorators";
32
import { EventEmitter } from "events";
43

54
export class IOSLogParserService extends EventEmitter implements IIOSLogParserService {
65
private static MESSAGE_REGEX = /NativeScript debugger has opened inspector socket on port (\d+?) for (.*)[.]/;
76

7+
private startedDeviceLogInstances: IDictionary<boolean> = {};
8+
89
constructor(private $deviceLogProvider: Mobile.IDeviceLogProvider,
910
private $iosDeviceOperations: IIOSDeviceOperations,
1011
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
1112
private $logger: ILogger,
1213
private $projectData: IProjectData) {
13-
super();
14-
}
14+
super();
15+
}
1516

1617
public startParsingLog(device: Mobile.IDevice): void {
1718
this.$deviceLogProvider.setProjectNameForDevice(device.deviceInfo.identifier, this.$projectData.projectName);
1819

19-
this.startParsingLogCore(device);
20-
this.startLogProcess(device);
20+
if (!this.startedDeviceLogInstances[device.deviceInfo.identifier]) {
21+
this.startParsingLogCore(device);
22+
this.startLogProcess(device);
23+
this.startedDeviceLogInstances[device.deviceInfo.identifier] = true;
24+
}
2125
}
2226

23-
@cache()
2427
private startParsingLogCore(device: Mobile.IDevice): void {
2528
const logProvider = device.isEmulator ? this.$iOSSimulatorLogProvider : this.$iosDeviceOperations;
2629
logProvider.on(DEVICE_LOG_EVENT_NAME, (response: IOSDeviceLib.IDeviceLogData) => this.processDeviceLogResponse(response));

0 commit comments

Comments
 (0)