Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 57c6e69

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #418 from telerik/fatme/fix-broken-emulator-option
Fix broken livesync android --emulator --watch command
2 parents d335e73 + 2849351 commit 57c6e69

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

services/usb-livesync-service-base.ts

+20-17
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
2626
private $fs: IFileSystem,
2727
private $dispatcher: IFutureDispatcher,
2828
protected $childProcess: IChildProcess,
29-
protected $iOSEmulatorServices: Mobile.IiOSSimulatorService) { }
29+
protected $iOSEmulatorServices: Mobile.IiOSSimulatorService,
30+
private $hostInfo: IHostInfo) { }
3031

3132
public initialize(platform: string): IFuture<string> {
3233
return (() => {
33-
if(!this.$options.emulator) {
34+
if(!(this.$options.emulator && platform && platform.toLowerCase() === "ios")) {
3435
this.$devicesServices.initialize({ platform: platform, deviceId: this.$options.device }).wait();
3536
this._initialized = true;
3637
return this.$devicesServices.platform;
37-
}
38+
}
3839
}).future<string>()();
3940
}
4041

@@ -46,18 +47,19 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
4647
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
4748
beforeBatchLiveSyncAction?: (filePath: string) => IFuture<string>): IFuture<void> {
4849
return (() => {
49-
if(!this._initialized && !this.$options.emulator) {
50-
this.initialize(platform).wait();
51-
}
50+
let synciOSSimulator = this.$hostInfo.isDarwin ? this.$iOSEmulatorServices.isSimulatorRunning().wait() || (this.$options.emulator && platform.toLowerCase() === "ios") : false;
5251

53-
let isiOSSimulatorRunning = this.$iOSEmulatorServices.isSimulatorRunning().wait();
54-
if(isiOSSimulatorRunning || this.$options.emulator) {
52+
if(synciOSSimulator) {
5553
this.$iOSEmulatorServices.sync(appIdentifier, projectFilesPath, notRunningiOSSimulatorAction).wait();
5654
}
5755

58-
if(!this.$options.emulator) {
56+
if(!this._initialized && (!this.$options.emulator || platform.toLowerCase() === "android")) {
57+
this.initialize(platform).wait();
58+
}
59+
60+
if(!this.$options.emulator || platform.toLowerCase() === "android") {
5961
let projectFiles = this.$fs.enumerateFilesInDirectorySync(projectFilesPath, (filePath, stat) => !this.isFileExcluded(path.relative(projectFilesPath, filePath), excludedProjectDirsAndFiles, projectFilesPath), { enumerateDirectories: true});
60-
this.syncCore(projectFiles, appIdentifier, localProjectRootPath || projectFilesPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction).wait();
62+
this.syncCore(platform, projectFiles, appIdentifier, localProjectRootPath || projectFilesPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction).wait();
6163
}
6264

6365
if(this.$options.watch) {
@@ -67,12 +69,12 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
6769
this.on('all', (event: string, filePath: string) => {
6870
if(event === "added" || event === "changed") {
6971
if(!_.contains(excludedProjectDirsAndFiles, filePath)) {
70-
if(isiOSSimulatorRunning || __this.$options.emulator) {
72+
if(synciOSSimulator) {
7173
__this.$dispatcher.dispatch(() => __this.$iOSEmulatorServices.syncFiles(appIdentifier, projectFilesPath, [filePath], notRunningiOSSimulatorAction));
7274
}
7375

74-
if(!__this.$options.emulator) {
75-
__this.batchLiveSync(filePath, appIdentifier, projectFilesPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeLiveSyncAction, beforeBatchLiveSyncAction);
76+
if(!__this.$options.emulator || platform.toLowerCase() === "android") {
77+
__this.batchLiveSync(platform, filePath, appIdentifier, projectFilesPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeLiveSyncAction, beforeBatchLiveSyncAction);
7678
}
7779
}
7880
}
@@ -84,12 +86,13 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
8486
}).future<void>()();
8587
}
8688

87-
private syncCore(projectFiles: string[], appIdentifier: string, projectFilesPath: string,
89+
private syncCore(platform: string, projectFiles: string[], appIdentifier: string, projectFilesPath: string,
8890
restartAppOnDeviceAction: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]) => IFuture<void>,
8991
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<void>,
9092
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>): IFuture<void> {
9193
return (() => {
92-
let deviceAppData = this.$deviceAppDataFactory.create(appIdentifier, this.$devicesServices.platform);
94+
platform = platform ? this.$mobileHelper.normalizePlatformName(platform) : this.$devicesServices.platform;
95+
let deviceAppData = this.$deviceAppDataFactory.create(appIdentifier, platform);
9396
let localToDevicePaths = _(projectFiles)
9497
.map(projectFile => this.getProjectFileInfo(projectFile))
9598
.filter(projectFileInfo => projectFileInfo.shouldIncludeFile)
@@ -128,7 +131,7 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
128131

129132
private timer: any= null;
130133
private syncQueue: string[] = [];
131-
private batchLiveSync(filePath: string, appIdentifier: string, projectFilesPath: string,
134+
private batchLiveSync(platform: string, filePath: string, appIdentifier: string, projectFilesPath: string,
132135
restartAppOnDeviceAction: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]) => IFuture<void>,
133136
notInstalledAppOnDeviceAction: (device: Mobile.IDevice) => IFuture<void>,
134137
beforeLiveSyncAction?: (device: Mobile.IDevice, deviceAppData: Mobile.IDeviceAppData) => IFuture<void>,
@@ -141,7 +144,7 @@ export class UsbLiveSyncServiceBase implements IUsbLiveSyncServiceBase {
141144
this.$logger.trace("Syncing %s", filesToSync.join(", "));
142145
this.$dispatcher.dispatch( () => {
143146
return (() => {
144-
this.syncCore(filesToSync, appIdentifier, projectFilesPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeLiveSyncAction).wait();
147+
this.syncCore(platform, filesToSync, appIdentifier, projectFilesPath, restartAppOnDeviceAction, notInstalledAppOnDeviceAction, beforeLiveSyncAction).wait();
145148
}).future<void>()();
146149
});
147150
}

0 commit comments

Comments
 (0)