@@ -2,7 +2,8 @@ import * as path from "path";
22import * as choki from "chokidar" ;
33import { EventEmitter } from "events" ;
44import { hook } from "../../common/helpers" ;
5- import { FileExtensions } from "../../common/constants" ;
5+ import { APP_FOLDER_NAME , PACKAGE_JSON_FILE_NAME , LiveSyncTrackActionNames } from "../../constants" ;
6+ import { FileExtensions , DeviceTypes } from "../../common/constants" ;
67
78const LiveSyncEvents = {
89 liveSyncStopped : "liveSyncStopped" ,
@@ -22,6 +23,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
2223 private $projectDataService : IProjectDataService ,
2324 protected $devicesService : Mobile . IDevicesService ,
2425 private $mobileHelper : Mobile . IMobileHelper ,
26+ protected $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
2527 private $nodeModulesDependenciesBuilder : INodeModulesDependenciesBuilder ,
2628 protected $logger : ILogger ,
2729 private $processService : IProcessService ,
@@ -152,8 +154,8 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
152154 rebuiltInformation : ILiveSyncBuildInfo [ ] ,
153155 projectData : IProjectData ,
154156 deviceBuildInfoDescriptor : ILiveSyncDeviceInfo ,
157+ settings : ILatestAppPackageInstalledSettings ,
155158 modifiedFiles ?: string [ ] ) : Promise < void > {
156-
157159 const platform = device . deviceInfo . platform ;
158160 if ( preparedPlatforms . indexOf ( platform ) === - 1 ) {
159161 preparedPlatforms . push ( platform ) ;
@@ -176,12 +178,29 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
176178 // TODO: fix args cast to any
177179 const shouldBuild = await this . $platformService . shouldBuild ( platform , projectData , < any > { buildForDevice : ! device . isEmulator } , deviceBuildInfoDescriptor . outputPath ) ;
178180 let pathToBuildItem = null ;
181+ let action = LiveSyncTrackActionNames . LIVESYNC_OPERATION ;
179182 if ( shouldBuild ) {
180183 pathToBuildItem = await deviceBuildInfoDescriptor . buildAction ( ) ;
181184 // Is it possible to return shouldBuild for two devices? What about android device and android emulator?
182185 rebuiltInformation . push ( { isEmulator : device . isEmulator , platform, pathToBuildItem } ) ;
186+ action = LiveSyncTrackActionNames . LIVESYNC_OPERATION_BUILD ;
187+ }
188+
189+ if ( ! settings [ platform ] [ device . deviceInfo . type ] ) {
190+ let isForDevice = ! device . isEmulator ;
191+ settings [ platform ] [ device . deviceInfo . type ] = true ;
192+ if ( this . $mobileHelper . isAndroidPlatform ( platform ) ) {
193+ settings [ platform ] [ DeviceTypes . Emulator ] = true ;
194+ settings [ platform ] [ DeviceTypes . Device ] = true ;
195+ isForDevice = null ;
196+ }
197+
198+ await this . $platformService . trackActionForPlatform ( { action, platform, isForDevice } ) ;
183199 }
184200
201+ await this . $platformService . trackActionForPlatform ( { action : LiveSyncTrackActionNames . DEVICE_INFO , platform, isForDevice : ! device . isEmulator , deviceOsVersion : device . deviceInfo . version } ) ;
202+
203+
185204 const shouldInstall = await this . $platformService . shouldInstall ( device , projectData , deviceBuildInfoDescriptor . outputPath ) ;
186205 if ( shouldInstall ) {
187206 await this . $platformService . installApplication ( device , { release : false } , projectData , pathToBuildItem , deviceBuildInfoDescriptor . outputPath ) ;
@@ -192,6 +211,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
192211 const preparedPlatforms : string [ ] = [ ] ;
193212 const rebuiltInformation : ILiveSyncBuildInfo [ ] = [ ] ;
194213
214+ const settings = this . getDefaultLatestAppPackageInstalledSettings ( ) ;
195215 // Now fullSync
196216 const deviceAction = async ( device : Mobile . IDevice ) : Promise < void > => {
197217 try {
@@ -204,14 +224,15 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
204224 const platform = device . deviceInfo . platform ;
205225 const deviceDescriptor = _ . find ( deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
206226
207- await this . ensureLatestAppPackageIsInstalledOnDevice ( device , preparedPlatforms , rebuiltInformation , projectData , deviceDescriptor ) ;
227+ await this . ensureLatestAppPackageIsInstalledOnDevice ( device , preparedPlatforms , rebuiltInformation , projectData , deviceDescriptor , settings ) ;
208228
209229 const liveSyncResultInfo = await this . getLiveSyncService ( platform ) . fullSync ( {
210230 projectData, device,
211231 syncAllFiles : liveSyncData . watchAllFiles ,
212232 useLiveEdit : liveSyncData . useLiveEdit ,
213233 watch : ! liveSyncData . skipWatcher
214234 } ) ;
235+ await this . $platformService . trackActionForPlatform ( { action : "LiveSync" , platform : device . deviceInfo . platform , isForDevice : ! device . isEmulator , deviceOsVersion : device . deviceInfo . version } ) ;
215236 await this . refreshApplication ( projectData , liveSyncResultInfo ) ;
216237 } catch ( err ) {
217238 this . $logger . warn ( `Unable to apply changes on device: ${ device . deviceInfo . identifier } . Error is: ${ err . message } .` ) ;
@@ -232,14 +253,27 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
232253 await this . addActionToChain ( projectData . projectDir , ( ) => this . $devicesService . execute ( deviceAction , ( device : Mobile . IDevice ) => _ . some ( deviceDescriptors , deviceDescriptor => deviceDescriptor . identifier === device . deviceInfo . identifier ) ) ) ;
233254 }
234255
256+ private getDefaultLatestAppPackageInstalledSettings ( ) : ILatestAppPackageInstalledSettings {
257+ return {
258+ [ this . $devicePlatformsConstants . Android ] : {
259+ [ DeviceTypes . Device ] : false ,
260+ [ DeviceTypes . Emulator ] : false
261+ } ,
262+ [ this . $devicePlatformsConstants . iOS ] : {
263+ [ DeviceTypes . Device ] : false ,
264+ [ DeviceTypes . Emulator ] : false
265+ }
266+ }
267+ }
268+
235269 private async startWatcher ( projectData : IProjectData ,
236270 liveSyncData : ILiveSyncInfo ) : Promise < void > {
237271
238- let pattern = [ "app" ] ;
272+ let pattern = [ APP_FOLDER_NAME ] ;
239273
240274 if ( liveSyncData . watchAllFiles ) {
241275 const productionDependencies = this . $nodeModulesDependenciesBuilder . getProductionDependencies ( projectData . projectDir ) ;
242- pattern . push ( "package.json" ) ;
276+ pattern . push ( PACKAGE_JSON_FILE_NAME ) ;
243277
244278 // watch only production node_module/packages same one prepare uses
245279 for ( let index in productionDependencies ) {
@@ -274,11 +308,13 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
274308 const preparedPlatforms : string [ ] = [ ] ;
275309 const rebuiltInformation : ILiveSyncBuildInfo [ ] = [ ] ;
276310
311+ const latestAppPackageInstalledSettings = this . getDefaultLatestAppPackageInstalledSettings ( ) ;
312+
277313 await this . $devicesService . execute ( async ( device : Mobile . IDevice ) => {
278314 const liveSyncProcessInfo = this . liveSyncProcessesInfo [ projectData . projectDir ] ;
279315 const deviceDescriptor = _ . find ( liveSyncProcessInfo . deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
280316
281- await this . ensureLatestAppPackageIsInstalledOnDevice ( device , preparedPlatforms , rebuiltInformation , projectData , deviceDescriptor , allModifiedFiles ) ;
317+ await this . ensureLatestAppPackageIsInstalledOnDevice ( device , preparedPlatforms , rebuiltInformation , projectData , deviceDescriptor , latestAppPackageInstalledSettings , allModifiedFiles ) ;
282318
283319 const service = this . getLiveSyncService ( device . deviceInfo . platform ) ;
284320 const settings : ILiveSyncWatchInfo = {
0 commit comments