@@ -2,7 +2,8 @@ import * as path from "path";
2
2
import * as choki from "chokidar" ;
3
3
import { EventEmitter } from "events" ;
4
4
import { 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" ;
6
7
7
8
const LiveSyncEvents = {
8
9
liveSyncStopped : "liveSyncStopped" ,
@@ -22,6 +23,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
22
23
private $projectDataService : IProjectDataService ,
23
24
protected $devicesService : Mobile . IDevicesService ,
24
25
private $mobileHelper : Mobile . IMobileHelper ,
26
+ protected $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
25
27
private $nodeModulesDependenciesBuilder : INodeModulesDependenciesBuilder ,
26
28
protected $logger : ILogger ,
27
29
private $processService : IProcessService ,
@@ -152,8 +154,8 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
152
154
rebuiltInformation : ILiveSyncBuildInfo [ ] ,
153
155
projectData : IProjectData ,
154
156
deviceBuildInfoDescriptor : ILiveSyncDeviceInfo ,
157
+ settings : ILatestAppPackageInstalledSettings ,
155
158
modifiedFiles ?: string [ ] ) : Promise < void > {
156
-
157
159
const platform = device . deviceInfo . platform ;
158
160
if ( preparedPlatforms . indexOf ( platform ) === - 1 ) {
159
161
preparedPlatforms . push ( platform ) ;
@@ -176,12 +178,29 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
176
178
// TODO: fix args cast to any
177
179
const shouldBuild = await this . $platformService . shouldBuild ( platform , projectData , < any > { buildForDevice : ! device . isEmulator } , deviceBuildInfoDescriptor . outputPath ) ;
178
180
let pathToBuildItem = null ;
181
+ let action = LiveSyncTrackActionNames . LIVESYNC_OPERATION ;
179
182
if ( shouldBuild ) {
180
183
pathToBuildItem = await deviceBuildInfoDescriptor . buildAction ( ) ;
181
184
// Is it possible to return shouldBuild for two devices? What about android device and android emulator?
182
185
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 } ) ;
183
199
}
184
200
201
+ await this . $platformService . trackActionForPlatform ( { action : LiveSyncTrackActionNames . DEVICE_INFO , platform, isForDevice : ! device . isEmulator , deviceOsVersion : device . deviceInfo . version } ) ;
202
+
203
+
185
204
const shouldInstall = await this . $platformService . shouldInstall ( device , projectData , deviceBuildInfoDescriptor . outputPath ) ;
186
205
if ( shouldInstall ) {
187
206
await this . $platformService . installApplication ( device , { release : false } , projectData , pathToBuildItem , deviceBuildInfoDescriptor . outputPath ) ;
@@ -192,6 +211,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
192
211
const preparedPlatforms : string [ ] = [ ] ;
193
212
const rebuiltInformation : ILiveSyncBuildInfo [ ] = [ ] ;
194
213
214
+ const settings = this . getDefaultLatestAppPackageInstalledSettings ( ) ;
195
215
// Now fullSync
196
216
const deviceAction = async ( device : Mobile . IDevice ) : Promise < void > => {
197
217
try {
@@ -204,14 +224,15 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
204
224
const platform = device . deviceInfo . platform ;
205
225
const deviceDescriptor = _ . find ( deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
206
226
207
- await this . ensureLatestAppPackageIsInstalledOnDevice ( device , preparedPlatforms , rebuiltInformation , projectData , deviceDescriptor ) ;
227
+ await this . ensureLatestAppPackageIsInstalledOnDevice ( device , preparedPlatforms , rebuiltInformation , projectData , deviceDescriptor , settings ) ;
208
228
209
229
const liveSyncResultInfo = await this . getLiveSyncService ( platform ) . fullSync ( {
210
230
projectData, device,
211
231
syncAllFiles : liveSyncData . watchAllFiles ,
212
232
useLiveEdit : liveSyncData . useLiveEdit ,
213
233
watch : ! liveSyncData . skipWatcher
214
234
} ) ;
235
+ await this . $platformService . trackActionForPlatform ( { action : "LiveSync" , platform : device . deviceInfo . platform , isForDevice : ! device . isEmulator , deviceOsVersion : device . deviceInfo . version } ) ;
215
236
await this . refreshApplication ( projectData , liveSyncResultInfo ) ;
216
237
} catch ( err ) {
217
238
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 {
232
253
await this . addActionToChain ( projectData . projectDir , ( ) => this . $devicesService . execute ( deviceAction , ( device : Mobile . IDevice ) => _ . some ( deviceDescriptors , deviceDescriptor => deviceDescriptor . identifier === device . deviceInfo . identifier ) ) ) ;
233
254
}
234
255
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
+
235
269
private async startWatcher ( projectData : IProjectData ,
236
270
liveSyncData : ILiveSyncInfo ) : Promise < void > {
237
271
238
- let pattern = [ "app" ] ;
272
+ let pattern = [ APP_FOLDER_NAME ] ;
239
273
240
274
if ( liveSyncData . watchAllFiles ) {
241
275
const productionDependencies = this . $nodeModulesDependenciesBuilder . getProductionDependencies ( projectData . projectDir ) ;
242
- pattern . push ( "package.json" ) ;
276
+ pattern . push ( PACKAGE_JSON_FILE_NAME ) ;
243
277
244
278
// watch only production node_module/packages same one prepare uses
245
279
for ( let index in productionDependencies ) {
@@ -274,11 +308,13 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
274
308
const preparedPlatforms : string [ ] = [ ] ;
275
309
const rebuiltInformation : ILiveSyncBuildInfo [ ] = [ ] ;
276
310
311
+ const latestAppPackageInstalledSettings = this . getDefaultLatestAppPackageInstalledSettings ( ) ;
312
+
277
313
await this . $devicesService . execute ( async ( device : Mobile . IDevice ) => {
278
314
const liveSyncProcessInfo = this . liveSyncProcessesInfo [ projectData . projectDir ] ;
279
315
const deviceDescriptor = _ . find ( liveSyncProcessInfo . deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
280
316
281
- await this . ensureLatestAppPackageIsInstalledOnDevice ( device , preparedPlatforms , rebuiltInformation , projectData , deviceDescriptor , allModifiedFiles ) ;
317
+ await this . ensureLatestAppPackageIsInstalledOnDevice ( device , preparedPlatforms , rebuiltInformation , projectData , deviceDescriptor , latestAppPackageInstalledSettings , allModifiedFiles ) ;
282
318
283
319
const service = this . getLiveSyncService ( device . deviceInfo . platform ) ;
284
320
const settings : ILiveSyncWatchInfo = {
0 commit comments