From 55b5813c7837200c624ff634ec57f3c0e343bd3f Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 1 Jun 2018 12:14:31 +0300 Subject: [PATCH 1/2] fix(livesync): fix `tns run ios --justlaunch` on real iOS device Fixes https://github.com/NativeScript/nativescript-cli/issues/3644 --- lib/definitions/livesync.d.ts | 1 + lib/services/debug-service.ts | 8 +++----- lib/services/ios-debug-service.ts | 8 +++----- .../livesync/android-livesync-service.ts | 7 ++++--- .../livesync/ios-device-livesync-service.ts | 1 - lib/services/livesync/ios-livesync-service.ts | 16 +++++++++------- lib/services/livesync/livesync-service.ts | 5 ++++- .../livesync/platform-livesync-service-base.ts | 1 - 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index d46f9ff3ad..c91e0a9c93 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -337,6 +337,7 @@ interface IPlatformLiveSyncService { fullSync(syncInfo: IFullSyncInfo): Promise; liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise; refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise; + prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo): void; } interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase { diff --git a/lib/services/debug-service.ts b/lib/services/debug-service.ts index 2e488e32f5..3cf840ba29 100644 --- a/lib/services/debug-service.ts +++ b/lib/services/debug-service.ts @@ -51,7 +51,7 @@ export class DebugService extends EventEmitter implements IDebugService { this.$errors.failWithoutHelp(`Unsupported device OS: ${device.deviceInfo.platform}. You can debug your applications only on iOS or Android.`); } - if (this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform)) { + if (this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform)) { // TODO: Consider to move this code to ios-debug-service if (device.isEmulator && !debugData.pathToAppPackage && debugOptions.debugBrk) { this.$errors.failWithoutHelp("To debug on iOS simulator you need to provide path to the app package."); } @@ -61,12 +61,10 @@ export class DebugService extends EventEmitter implements IDebugService { } else if (!this.$hostInfo.isDarwin) { this.$errors.failWithoutHelp(`Debugging on iOS devices is not supported for ${platform()} yet.`); } - - result = await debugService.debug(debugData, debugOptions); - } else if (this.$mobileHelper.isAndroidPlatform(device.deviceInfo.platform)) { - result = await debugService.debug(debugData, debugOptions); } + result = await debugService.debug(debugData, debugOptions); + return this.getDebugInformation(result, device.deviceInfo.identifier); } diff --git a/lib/services/ios-debug-service.ts b/lib/services/ios-debug-service.ts index 7295caa9ac..eb701d3145 100644 --- a/lib/services/ios-debug-service.ts +++ b/lib/services/ios-debug-service.ts @@ -63,6 +63,8 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS await this.device.openDeviceLogStream(); } + this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(this.device, debugData); + if (debugOptions.emulator) { if (debugOptions.start) { return this.emulatorStart(debugData, debugOptions); @@ -142,12 +144,8 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS } private async emulatorStart(debugData: IDebugData, debugOptions: IDebugOptions): Promise { - const device = await this.$devicesService.getDevice(debugData.deviceIdentifier); - this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, debugData); const result = await this.wireDebuggerClient(debugData, debugOptions); - const attachRequestMessage = this.$iOSNotification.getAttachRequest(debugData.applicationIdentifier, debugData.deviceIdentifier); - const iOSEmulatorService = this.$iOSEmulatorServices; await iOSEmulatorService.postDarwinNotification(attachRequestMessage, debugData.deviceIdentifier); return result; @@ -192,7 +190,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS } private async deviceStartCore(device: Mobile.IiOSDevice, debugData: IDebugData, debugOptions: IDebugOptions): Promise { - this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, debugData); + await this.$iOSSocketRequestExecutor.executeAttachRequest(device, AWAIT_NOTIFICATION_TIMEOUT_SECONDS, debugData.applicationIdentifier); return this.wireDebuggerClient(debugData, debugOptions, device); } diff --git a/lib/services/livesync/android-livesync-service.ts b/lib/services/livesync/android-livesync-service.ts index 759683c444..b069088f91 100644 --- a/lib/services/livesync/android-livesync-service.ts +++ b/lib/services/livesync/android-livesync-service.ts @@ -8,14 +8,15 @@ export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implemen $devicePathProvider: IDevicePathProvider, $fs: IFileSystem, $logger: ILogger, - $projectFilesProvider: IProjectFilesProvider, - ) { - super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider); + $projectFilesProvider: IProjectFilesProvider) { + super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider); } protected _getDeviceLiveSyncService(device: Mobile.IDevice, data: IProjectDir): INativeScriptDeviceLiveSyncService { const service = this.$injector.resolve(AndroidDeviceLiveSyncService, { _device: device, data }); return service; } + + public prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir): void { /* */ } } $injector.register("androidLiveSyncService", AndroidLiveSyncService); diff --git a/lib/services/livesync/ios-device-livesync-service.ts b/lib/services/livesync/ios-device-livesync-service.ts index 562fbb935d..4967a1996d 100644 --- a/lib/services/livesync/ios-device-livesync-service.ts +++ b/lib/services/livesync/ios-device-livesync-service.ts @@ -20,7 +20,6 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen private $processService: IProcessService, protected $platformsData: IPlatformsData) { super($platformsData); - this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(_device, data); this.device = _device; } diff --git a/lib/services/livesync/ios-livesync-service.ts b/lib/services/livesync/ios-livesync-service.ts index 1970de3531..d253bb1d3e 100644 --- a/lib/services/livesync/ios-livesync-service.ts +++ b/lib/services/livesync/ios-livesync-service.ts @@ -13,10 +13,9 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I $devicePathProvider: IDevicePathProvider, $logger: ILogger, $projectFilesProvider: IProjectFilesProvider, - private $iOSDebuggerPortService: IIOSDebuggerPortService, - ) { - super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider); - } + private $iOSDebuggerPortService: IIOSDebuggerPortService) { + super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider); + } public async fullSync(syncInfo: IFullSyncInfo): Promise { const device = syncInfo.device; @@ -24,9 +23,6 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I if (device.isEmulator) { return super.fullSync(syncInfo); } - - this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, syncInfo.projectData); - const projectData = syncInfo.projectData; const platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData); const deviceAppData = await this.getAppData(syncInfo); @@ -70,6 +66,12 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I } } + public prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo): void { + if (!liveSyncInfo.skipWatcher) { + this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, data); + } + } + protected _getDeviceLiveSyncService(device: Mobile.IDevice, data: IProjectDir): INativeScriptDeviceLiveSyncService { const service = this.$injector.resolve(IOSDeviceLiveSyncService, { _device: device, data }); return service; diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index f81362c1c4..e6b74827ca 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -456,8 +456,11 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi const deviceAction = async (device: Mobile.IDevice): Promise => { try { const platform = device.deviceInfo.platform; + const liveSyncService = this.getLiveSyncService(platform); const deviceBuildInfoDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier); + liveSyncService.prepareForLiveSync(device, projectData, liveSyncData); + await this.ensureLatestAppPackageIsInstalledOnDevice({ device, preparedPlatforms, @@ -472,7 +475,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi env: liveSyncData.env }, { skipNativePrepare: deviceBuildInfoDescriptor.skipNativePrepare }); - const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({ + const liveSyncResultInfo = await liveSyncService.fullSync({ projectData, device, syncAllFiles: liveSyncData.watchAllFiles, useLiveEdit: liveSyncData.useLiveEdit, diff --git a/lib/services/livesync/platform-livesync-service-base.ts b/lib/services/livesync/platform-livesync-service-base.ts index df1a2f8bdd..8c25c182fd 100644 --- a/lib/services/livesync/platform-livesync-service-base.ts +++ b/lib/services/livesync/platform-livesync-service-base.ts @@ -138,5 +138,4 @@ export abstract class PlatformLiveSyncServiceBase { action.call(this.$logger, util.format(message, "all files")); } } - } From 2cb0dc3d38d335ce988c853214bf600418064977 Mon Sep 17 00:00:00 2001 From: fatme Date: Tue, 5 Jun 2018 08:51:53 +0300 Subject: [PATCH 2/2] Fix PR comments --- lib/services/debug-service.ts | 3 ++- lib/services/livesync/livesync-service.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/services/debug-service.ts b/lib/services/debug-service.ts index 3cf840ba29..6fcc3ba112 100644 --- a/lib/services/debug-service.ts +++ b/lib/services/debug-service.ts @@ -51,7 +51,8 @@ export class DebugService extends EventEmitter implements IDebugService { this.$errors.failWithoutHelp(`Unsupported device OS: ${device.deviceInfo.platform}. You can debug your applications only on iOS or Android.`); } - if (this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform)) { // TODO: Consider to move this code to ios-debug-service + // TODO: Consider to move this code to ios-debug-service + if (this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform)) { if (device.isEmulator && !debugData.pathToAppPackage && debugOptions.debugBrk) { this.$errors.failWithoutHelp("To debug on iOS simulator you need to provide path to the app package."); } diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index e6b74827ca..6cae05e247 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -456,10 +456,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi const deviceAction = async (device: Mobile.IDevice): Promise => { try { const platform = device.deviceInfo.platform; - const liveSyncService = this.getLiveSyncService(platform); + const platformLiveSyncService = this.getLiveSyncService(platform); const deviceBuildInfoDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier); - liveSyncService.prepareForLiveSync(device, projectData, liveSyncData); + platformLiveSyncService.prepareForLiveSync(device, projectData, liveSyncData); await this.ensureLatestAppPackageIsInstalledOnDevice({ device, @@ -475,7 +475,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi env: liveSyncData.env }, { skipNativePrepare: deviceBuildInfoDescriptor.skipNativePrepare }); - const liveSyncResultInfo = await liveSyncService.fullSync({ + const liveSyncResultInfo = await platformLiveSyncService.fullSync({ projectData, device, syncAllFiles: liveSyncData.watchAllFiles, useLiveEdit: liveSyncData.useLiveEdit,