Skip to content

Commit 9834826

Browse files
Merge pull request #4271 from NativeScript/vladimirov/fix-error-preview-stop
fix: do not show error from preview initialization when stop is called
2 parents 0842ab6 + 7c07d2e commit 9834826

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

lib/commands/preview.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,11 @@ export class PreviewCommand implements ICommand {
1919
this.$logger.info(message);
2020
});
2121

22-
await this.$liveSyncService.liveSync([], {
23-
syncToPreviewApp: true,
24-
projectDir: this.$projectData.projectDir,
25-
skipWatcher: !this.$options.watch,
26-
watchAllFiles: this.$options.syncAllFiles,
27-
clean: this.$options.clean,
22+
await this.$liveSyncService.liveSyncToPreviewApp({
2823
bundle: !!this.$options.bundle,
29-
release: this.$options.release,
30-
env: this.$options.env,
31-
timeout: this.$options.timeout,
32-
useHotModuleReload: this.$options.hmr
24+
useHotModuleReload: this.$options.hmr,
25+
projectDir: this.$projectData.projectDir,
26+
env: this.$options.env
3327
});
3428

3529
await this.$previewQrCodeService.printLiveSyncQrCode({ useHotModuleReload: this.$options.hmr, link: this.$options.link });

lib/definitions/livesync.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ interface ILiveSyncService {
242242
*/
243243
liveSync(deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncData: ILiveSyncInfo): Promise<void>;
244244

245+
/**
246+
* Starts LiveSync operation to Preview app.
247+
* @param {IPreviewAppLiveSyncData} data Describes information about the current operation.
248+
* @returns {Promise<IQrCodeImageData>} Data of the QR code that should be used to start the LiveSync operation.
249+
*/
250+
liveSyncToPreviewApp(data: IPreviewAppLiveSyncData): Promise<IQrCodeImageData>;
251+
245252
/**
246253
* Stops LiveSync operation for specified directory.
247254
* @param {string} projectDir The directory for which to stop the operation.

lib/services/livesync/livesync-service.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
137137
return currentDescriptors || [];
138138
}
139139

140-
@cache()
141140
private attachToPreviewAppLiveSyncError(): void {
142-
this.$previewAppLiveSyncService.on(LiveSyncEvents.previewAppLiveSyncError, liveSyncData => {
143-
this.emit(LiveSyncEvents.previewAppLiveSyncError, liveSyncData);
144-
});
141+
if (!this.$usbLiveSyncService.isInitialized) {
142+
this.$previewAppLiveSyncService.on(LiveSyncEvents.previewAppLiveSyncError, liveSyncData => {
143+
this.$logger.error(liveSyncData.error);
144+
this.emit(LiveSyncEvents.previewAppLiveSyncError, liveSyncData);
145+
});
146+
}
145147
}
146148

147149
private handleWarnings(liveSyncData: ILiveSyncInfo, projectData: IProjectData) {

lib/services/livesync/playground/preview-app-livesync-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class PreviewAppLiveSyncService extends EventEmitter implements IPreviewA
4343
this.deviceInitializationPromise[device.id] = null;
4444
}
4545
} catch (error) {
46-
this.$logger.error(error);
46+
this.$logger.trace(`Error while sending files on device ${device && device.id}. Error is`, error);
4747
this.emit(PreviewAppLiveSyncEvents.PREVIEW_APP_LIVE_SYNC_ERROR, {
4848
error,
4949
data,

test/stubs.ts

+4
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,10 @@ export class DebugServiceStub extends EventEmitter implements IDeviceDebugServic
661661
}
662662

663663
export class LiveSyncServiceStub implements ILiveSyncService {
664+
public async liveSyncToPreviewApp(data: IPreviewAppLiveSyncData): Promise<IQrCodeImageData> {
665+
return;
666+
}
667+
664668
public async liveSync(deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncData: ILiveSyncInfo): Promise<void> {
665669
return;
666670
}

0 commit comments

Comments
 (0)