Skip to content

Commit 703e386

Browse files
committed
Integrate the new live sync + debug logic in the current refactoring
1 parent 9e45c5d commit 703e386

10 files changed

+76
-355
lines changed

lib/commands/debug.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,26 @@
66
private $childProcess: IChildProcess,
77
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
88
private $config: IConfiguration,
9+
private $usbLiveSyncService: ILiveSyncService,
910
protected $options: IOptions) { }
1011

1112
execute(args: string[]): IFuture<void> {
1213
if (!this.$options.rebuild && !this.$options.start) {
1314
this.$config.debugLivesync = true;
14-
let usbLiveSyncService: ILiveSyncService = this.$injector.resolve("usbLiveSyncService");
15-
let liveSyncServiceBase: any = this.$injector.resolve("liveSyncServiceBase");
16-
let liveSyncProvider: ILiveSyncProvider = this.$injector.resolve("liveSyncProvider");
15+
let applicationReloadAction = (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> => {
16+
return (() => {
17+
let projectData: IProjectData = this.$injector.resolve("projectData");
1718

18-
liveSyncServiceBase.on("sync", (device: Mobile.IDevice, data: ILiveSyncData) => {
19-
let platformLiveSyncService: IPlatformLiveSyncService = this.$injector.resolve(liveSyncProvider.platformSpecificLiveSyncServices[data.platform.toLowerCase()], { _device: device });
20-
let projectData: IProjectData = this.$injector.resolve("projectData");
21-
let appId = device.isEmulator ? projectData.projectName : data.appIdentifier;
22-
if (data.platform === this.$devicePlatformsConstants.iOS) {
23-
platformLiveSyncService.debugService.debugStop().wait();
24-
}
25-
device.applicationManager.stopApplication(appId).wait();
26-
platformLiveSyncService.debugService.debug().wait();
27-
});
19+
this.debugService.debugStop().wait();
2820

29-
liveSyncServiceBase.on("syncAfterInstall", (device: Mobile.IDevice, data: ILiveSyncData) => {
30-
let platformLiveSyncService: IPlatformLiveSyncService = this.$injector.resolve(liveSyncProvider.platformSpecificLiveSyncServices[data.platform.toLowerCase()], { _device: device });
31-
platformLiveSyncService.debugService.debug().wait();
32-
});
21+
let applicationId = deviceAppData.device.isEmulator ? projectData.projectName : deviceAppData.appIdentifier;
22+
deviceAppData.device.applicationManager.stopApplication(applicationId).wait();
3323

34-
return usbLiveSyncService.liveSync(this.$devicesService.platform);
24+
this.debugService.debug().wait();
25+
}).future<void>()();
26+
};
27+
28+
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, applicationReloadAction);
3529
}
3630
return this.debugService.debug();
3731
}
@@ -66,8 +60,9 @@ export class DebugIOSCommand extends DebugPlatformCommand {
6660
$childProcess: IChildProcess,
6761
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
6862
$config: IConfiguration,
63+
$usbLiveSyncService: ILiveSyncService,
6964
$options: IOptions) {
70-
super($iOSDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $options);
65+
super($iOSDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $options);
7166
}
7267
}
7368
$injector.registerCommand("debug|ios", DebugIOSCommand);
@@ -78,10 +73,11 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
7873
$injector: IInjector,
7974
$logger: ILogger,
8075
$childProcess: IChildProcess,
81-
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
76+
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
8277
$config: IConfiguration,
78+
$usbLiveSyncService: ILiveSyncService,
8379
$options: IOptions) {
84-
super($androidDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $options);
80+
super($androidDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $options);
8581
}
8682
}
8783
$injector.registerCommand("debug|android", DebugAndroidCommand);

lib/declarations.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ interface IOpener {
5757
}
5858

5959
interface ILiveSyncService {
60-
liveSync(platform: string): IFuture<void>;
60+
liveSync(platform: string, applicationReloadAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void>;
6161
forceExecuteFullSync: boolean;
6262
}
6363

6464
interface IPlatformLiveSyncService {
65-
fullSync(): IFuture<void>;
66-
partialSync(event: string, filePath: string, dispatcher: IFutureDispatcher): void;
65+
fullSync(postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void>;
66+
partialSync(event: string, filePath: string, dispatcher: IFutureDispatcher, afterFileSyncAction: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): void;
67+
refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void>;
6768
}
6869

6970
interface IOptions extends ICommonOptions {

lib/definitions/debug.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
interface IDebugService {
22
debug(shouldBreak?: boolean): IFuture<void>;
33
debugStart(): IFuture<void>;
4-
debugStop?(): IFuture<void>
4+
debugStop(): IFuture<void>
55
platform: string;
66
}

lib/services/android-debug-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ class AndroidDebugService implements IDebugService {
190190
}).future<void>()();
191191
}
192192

193+
public debugStop(): IFuture<void> {
194+
return Future.fromResult();
195+
}
196+
193197
private debugStartCore(): IFuture<void> {
194198
return (() => {
195199
let packageName = this.$projectData.projectId;

lib/services/livesync/android-platform-livesync-service.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AndroidPlatformLiveSyncService extends PlatformLiveSyncServiceBase {
1515
super(_liveSyncData, $devicesService, $mobileHelper, $logger, $options, $deviceAppDataFactory, $fs, $injector, $projectFilesManager, $projectFilesProvider, $liveSyncProvider);
1616
}
1717

18-
public fullSync(): IFuture<void> {
18+
public fullSync(postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void> {
1919
return (() => {
2020
let appIdentifier = this.liveSyncData.appIdentifier;
2121
let platform = this.liveSyncData.platform;
@@ -30,15 +30,21 @@ class AndroidPlatformLiveSyncService extends PlatformLiveSyncServiceBase {
3030

3131
let installed = this.tryInstallApplication(device, deviceAppData).wait();
3232
let localToDevicePaths = this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, null, this.liveSyncData.excludedProjectDirsAndFiles);
33+
let afterSyncAction: () => IFuture<void>;
3334

3435
if (installed) {
3536
deviceLiveSyncService.afterInstallApplicationAction(deviceAppData, localToDevicePaths).wait();
36-
37-
device.applicationManager.tryStartApplication(deviceAppData.appIdentifier).wait();
37+
afterSyncAction = () => device.applicationManager.tryStartApplication(deviceAppData.appIdentifier);
3838
} else {
3939
this.transferFiles(deviceAppData, localToDevicePaths, this.liveSyncData.projectFilesPath, true).wait();
40-
this.refreshApplication(deviceAppData, localToDevicePaths, this.liveSyncData.forceExecuteFullSync).wait();
40+
afterSyncAction = () => this.refreshApplication(deviceAppData, localToDevicePaths);
41+
}
42+
43+
if (postAction) {
44+
return postAction(deviceAppData, localToDevicePaths);
4145
}
46+
47+
return afterSyncAction();
4248
}).future<void>()();
4349
};
4450
this.$devicesService.execute(action, canExecute).wait();

lib/services/livesync/ios-platform-livesync-service.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class IOSPlatformLiveSyncService extends PlatformLiveSyncServiceBase {
1515
super(_liveSyncData, $devicesService, $mobileHelper, $logger, $options, $deviceAppDataFactory, $fs, $injector, $projectFilesManager, $projectFilesProvider, $liveSyncProvider);
1616
}
1717

18-
public fullSync(): IFuture<void> {
18+
public fullSync(postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void> {
1919
return (() => {
2020
let appIdentifier = this.liveSyncData.appIdentifier;
2121
let platform = this.liveSyncData.platform;
@@ -26,14 +26,21 @@ class IOSPlatformLiveSyncService extends PlatformLiveSyncServiceBase {
2626
return (() => {
2727
let deviceAppData = this.$deviceAppDataFactory.create(appIdentifier, this.$mobileHelper.normalizePlatformName(platform), device);
2828
let installed = this.tryInstallApplication(device, deviceAppData).wait();
29+
let localToDevicePaths = this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, null, this.liveSyncData.excludedProjectDirsAndFiles);
30+
let afterSyncAction: () => IFuture<void>;
2931

3032
if(installed) {
31-
device.applicationManager.tryStartApplication(deviceAppData.appIdentifier).wait();
33+
afterSyncAction = () => device.applicationManager.tryStartApplication(deviceAppData.appIdentifier);
3234
} else {
33-
let localToDevicePaths = this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, null, this.liveSyncData.excludedProjectDirsAndFiles);
3435
this.transferFiles(deviceAppData, localToDevicePaths, this.liveSyncData.projectFilesPath, true).wait();
35-
this.refreshApplication(deviceAppData, localToDevicePaths, this.liveSyncData.forceExecuteFullSync).wait();
36+
afterSyncAction = () => this.refreshApplication(deviceAppData, localToDevicePaths);
3637
}
38+
39+
if (postAction) {
40+
return postAction(deviceAppData, localToDevicePaths);
41+
}
42+
43+
return afterSyncAction();
3744
}).future<void>()();
3845
};
3946
this.$devicesService.execute(action, canExecute).wait();

0 commit comments

Comments
 (0)