diff --git a/lib/commands/preview.ts b/lib/commands/preview.ts index f3bf388a30..7d8a4af6ec 100644 --- a/lib/commands/preview.ts +++ b/lib/commands/preview.ts @@ -19,17 +19,11 @@ export class PreviewCommand implements ICommand { this.$logger.info(message); }); - await this.$liveSyncService.liveSync([], { - syncToPreviewApp: true, - projectDir: this.$projectData.projectDir, - skipWatcher: !this.$options.watch, - watchAllFiles: this.$options.syncAllFiles, - clean: this.$options.clean, + await this.$liveSyncService.liveSyncToPreviewApp({ bundle: !!this.$options.bundle, - release: this.$options.release, - env: this.$options.env, - timeout: this.$options.timeout, - useHotModuleReload: this.$options.hmr + useHotModuleReload: this.$options.hmr, + projectDir: this.$projectData.projectDir, + env: this.$options.env }); await this.$previewQrCodeService.printLiveSyncQrCode({ useHotModuleReload: this.$options.hmr, link: this.$options.link }); diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index a4274c147a..212474a508 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -242,6 +242,13 @@ interface ILiveSyncService { */ liveSync(deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncData: ILiveSyncInfo): Promise; + /** + * Starts LiveSync operation to Preview app. + * @param {IPreviewAppLiveSyncData} data Describes information about the current operation. + * @returns {Promise} Data of the QR code that should be used to start the LiveSync operation. + */ + liveSyncToPreviewApp(data: IPreviewAppLiveSyncData): Promise; + /** * Stops LiveSync operation for specified directory. * @param {string} projectDir The directory for which to stop the operation. diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index fd8dc63993..38e3b8603d 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -137,11 +137,13 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi return currentDescriptors || []; } - @cache() private attachToPreviewAppLiveSyncError(): void { - this.$previewAppLiveSyncService.on(LiveSyncEvents.previewAppLiveSyncError, liveSyncData => { - this.emit(LiveSyncEvents.previewAppLiveSyncError, liveSyncData); - }); + if (!this.$usbLiveSyncService.isInitialized) { + this.$previewAppLiveSyncService.on(LiveSyncEvents.previewAppLiveSyncError, liveSyncData => { + this.$logger.error(liveSyncData.error); + this.emit(LiveSyncEvents.previewAppLiveSyncError, liveSyncData); + }); + } } private handleWarnings(liveSyncData: ILiveSyncInfo, projectData: IProjectData) { diff --git a/lib/services/livesync/playground/preview-app-livesync-service.ts b/lib/services/livesync/playground/preview-app-livesync-service.ts index 4dae4f41e8..2883dd1ccf 100644 --- a/lib/services/livesync/playground/preview-app-livesync-service.ts +++ b/lib/services/livesync/playground/preview-app-livesync-service.ts @@ -43,7 +43,7 @@ export class PreviewAppLiveSyncService extends EventEmitter implements IPreviewA this.deviceInitializationPromise[device.id] = null; } } catch (error) { - this.$logger.error(error); + this.$logger.trace(`Error while sending files on device ${device && device.id}. Error is`, error); this.emit(PreviewAppLiveSyncEvents.PREVIEW_APP_LIVE_SYNC_ERROR, { error, data, diff --git a/test/stubs.ts b/test/stubs.ts index 28a0ce35f8..b06e61e7b8 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -661,6 +661,10 @@ export class DebugServiceStub extends EventEmitter implements IDeviceDebugServic } export class LiveSyncServiceStub implements ILiveSyncService { + public async liveSyncToPreviewApp(data: IPreviewAppLiveSyncData): Promise { + return; + } + public async liveSync(deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncData: ILiveSyncInfo): Promise { return; }