Skip to content

Commit 91d3a31

Browse files
committed
Cleanul livesync with sockets code.
1 parent 4e7e815 commit 91d3a31

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
5252
getDirname: true
5353
});
5454

55-
await this.device.adb.executeShellCommand(["rm", "-rf", await this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.FULLSYNC_DIR_NAME),
55+
await this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.FULLSYNC_DIR_NAME),
5656
this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.SYNC_DIR_NAME),
57-
await this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.REMOVEDSYNC_DIR_NAME)]);
57+
this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.REMOVEDSYNC_DIR_NAME)]);
5858
}
5959

6060
private async restartApplication(deviceAppData: Mobile.IDeviceAppData, projectName: string): Promise<void> {

lib/services/livesync/android-livesync-library.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
2323
constructor(private $androidProcessService: Mobile.IAndroidProcessService,
2424
private $errors: IErrors,
2525
private $fs: IFileSystem,
26-
private $logger: ILogger) {
26+
private $logger: ILogger,
27+
private $mobileHelper: Mobile.IMobileHelper) {
2728
this.operationPromises = Object.create(null);
2829
this.socketError = null;
2930
this.socketConnection = null;
@@ -38,6 +39,10 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
3839
this.$errors.fail(`You need to provide "baseDir" as a configuration property!`);
3940
}
4041

42+
if (this.socketConnection) {
43+
this.$errors.fail("Socket connection already exists.");
44+
}
45+
4146
if (!configuration.localHostAddress) {
4247
configuration.localHostAddress = DEFAULT_LOCAL_HOST_ADDRESS;
4348
}
@@ -267,6 +272,8 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
267272
const error = new Error(`Socket Error:\n${err}`);
268273
if (this.configuration.errorHandler) {
269274
this.configuration.errorHandler(error);
275+
} else {
276+
this.handleSocketError(socket.uid, error.message);
270277
}
271278
});
272279
}
@@ -381,18 +388,9 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
381388
}
382389

383390
private resolveRelativePath(filePath: string): string {
384-
let relativeFilePath;
385-
386-
if (this.configuration.appPlatformsPath) {
387-
relativeFilePath = path.relative(this.configuration.appPlatformsPath, filePath);
388-
} else if (this.appPlatformsPath) {
389-
relativeFilePath = path.relative(this.appPlatformsPath, filePath);
390-
} else {
391-
this.$errors.failWithoutHelp("You need to pass either \"baseDir\" " +
392-
"when you initialize the tool or \"basePath\" as a second argument to this method!");
393-
}
391+
const relativeFilePath = path.relative(this.appPlatformsPath, filePath);
394392

395-
return relativeFilePath.split(path.sep).join(path.posix.sep);
393+
return this.$mobileHelper.buildDevicePath(relativeFilePath);
396394
}
397395
}
398396
$injector.register("androidLivesyncLibrary", AndroidLivesyncTool);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PlatformLiveSyncServiceBase } from "./platform-livesync-service-base";
44
import * as semver from "semver";
55

66
export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implements IPlatformLiveSyncService {
7+
private static MIN_SOCKETS_LIVESYNC_RUNTIME_VERSION = "4.2.0";
78
constructor(protected $platformsData: IPlatformsData,
89
protected $projectFilesManager: IProjectFilesManager,
910
private $injector: IInjector,
@@ -15,7 +16,7 @@ export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implemen
1516
}
1617

1718
protected _getDeviceLiveSyncService(device: Mobile.IDevice, data: IProjectDir, frameworkVersion: string): INativeScriptDeviceLiveSyncService {
18-
if (semver.gte(frameworkVersion, "4.2.0")) {
19+
if (semver.gte(frameworkVersion, AndroidLiveSyncService.MIN_SOCKETS_LIVESYNC_RUNTIME_VERSION)) {
1920
return this.$injector.resolve<INativeScriptDeviceLiveSyncService>(AndroidDeviceSocketsLiveSyncService, { device, data });
2021
}
2122

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export abstract class PlatformLiveSyncServiceBase {
5858

5959
public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
6060
const projectData = liveSyncInfo.projectData;
61-
let deviceLiveSyncService = this.getDeviceLiveSyncService(device, projectData);
61+
const deviceLiveSyncService = this.getDeviceLiveSyncService(device, projectData);
6262
const syncInfo = _.merge<IFullSyncInfo>({ device, watch: true }, liveSyncInfo);
6363
const deviceAppData = await this.getAppData(syncInfo);
6464

@@ -101,7 +101,6 @@ export abstract class PlatformLiveSyncServiceBase {
101101
const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, mappedFiles, []);
102102
modifiedLocalToDevicePaths.push(...localToDevicePaths);
103103

104-
deviceLiveSyncService = this.getDeviceLiveSyncService(device, projectData);
105104
await deviceLiveSyncService.removeFiles(deviceAppData, localToDevicePaths, projectFilesPath);
106105
}
107106

0 commit comments

Comments
 (0)