Skip to content

Commit 19b7fca

Browse files
rosen-vladimirovDimitar Kerezov
authored andcommitted
Add useLiveEdit option
1 parent 33371a4 commit 19b7fca

File tree

6 files changed

+25
-28
lines changed

6 files changed

+25
-28
lines changed

lib/definitions/livesync.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,21 @@ interface ILiveSyncWatchInfo {
9292
filesToSync: string[];
9393
isRebuilt: boolean;
9494
syncAllFiles: boolean;
95+
useLiveEdit?: boolean;
9596
}
9697

9798
interface ILiveSyncResultInfo {
9899
modifiedFilesData: Mobile.ILocalToDevicePathData[];
99100
isFullSync: boolean;
100101
deviceAppData: Mobile.IDeviceAppData;
102+
useLiveEdit?: boolean;
101103
}
102104

103105
interface IFullSyncInfo {
104106
projectData: IProjectData;
105107
device: Mobile.IDevice;
106108
syncAllFiles: boolean;
109+
useLiveEdit?: boolean;
107110
}
108111

109112
interface IPlatformLiveSyncService {
@@ -121,10 +124,8 @@ interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase
121124
* @param {IProjectData} projectData Project data.
122125
* @return {Promise<void>}
123126
*/
124-
refreshApplication(deviceAppData: Mobile.IDeviceAppData,
125-
localToDevicePaths: Mobile.ILocalToDevicePathData[],
126-
forceExecuteFullSync: boolean,
127-
projectData: IProjectData): Promise<void>;
127+
refreshApplication(projectData: IProjectData,
128+
liveSyncInfo: ILiveSyncResultInfo): Promise<void>;
128129

129130
/**
130131
* Removes specified files from a connected device

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncServic
2525
return this.$androidDebugService;
2626
}
2727

28-
public async refreshApplication(deviceAppData: Mobile.IDeviceAppData,
29-
localToDevicePaths: Mobile.ILocalToDevicePathData[],
30-
forceExecuteFullSync: boolean,
31-
projectData: IProjectData): Promise<void> {
28+
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
29+
const deviceAppData = liveSyncInfo.deviceAppData;
30+
const localToDevicePaths = liveSyncInfo.modifiedFilesData;
3231

3332
await this.device.adb.executeShellCommand(
3433
["chmod",
@@ -38,7 +37,7 @@ export class AndroidLiveSyncService implements INativeScriptDeviceLiveSyncServic
3837
`/data/local/tmp/${deviceAppData.appIdentifier}/sync`]
3938
);
4039

41-
let canExecuteFastSync = !forceExecuteFullSync && !_.some(localToDevicePaths,
40+
let canExecuteFastSync = ! liveSyncInfo.isFullSync && !_.some(localToDevicePaths,
4241
(localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
4342

4443
if (canExecuteFastSync) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,9 @@ export class AndroidLiveSyncService implements IPlatformLiveSyncService {
8585
liveSyncInfo: ILiveSyncResultInfo
8686
): Promise<void> {
8787
if (liveSyncInfo.isFullSync || liveSyncInfo.modifiedFilesData.length) {
88-
// const deviceAppData = this.$injector.resolve(deviceAppDataIdentifiers.AndroidAppIdentifier,
89-
// { _appIdentifier: projectData.projectId, device, platform: device.deviceInfo.platform });
9088
let deviceLiveSyncService = this.$injector.resolve<INativeScriptDeviceLiveSyncService>(adls.AndroidLiveSyncService, { _device: liveSyncInfo.deviceAppData.device });
9189
this.$logger.info("Refreshing application...");
92-
await deviceLiveSyncService.refreshApplication(liveSyncInfo.deviceAppData, liveSyncInfo.modifiedFilesData, liveSyncInfo.isFullSync, projectData);
90+
await deviceLiveSyncService.refreshApplication(projectData, liveSyncInfo);
9391
}
9492
}
9593

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as net from "net";
55

66
let currentPageReloadId = 0;
77

8-
export class IOSLiveSyncService implements INativeScriptDeviceLiveSyncService {
8+
export class IOSDeviceLiveSyncService implements INativeScriptDeviceLiveSyncService {
99
private static BACKEND_PORT = 18181;
1010
private socket: net.Socket;
1111
private device: Mobile.IiOSDevice;
@@ -35,15 +35,15 @@ export class IOSLiveSyncService implements INativeScriptDeviceLiveSyncService {
3535
if (this.device.isEmulator) {
3636
await this.$iOSEmulatorServices.postDarwinNotification(this.$iOSNotification.getAttachRequest(projectId));
3737
try {
38-
this.socket = await helpers.connectEventuallyUntilTimeout(() => net.connect(IOSLiveSyncService.BACKEND_PORT), 5000);
38+
this.socket = await helpers.connectEventuallyUntilTimeout(() => net.connect(IOSDeviceLiveSyncService.BACKEND_PORT), 5000);
3939
} catch (e) {
4040
this.$logger.debug(e);
4141
return false;
4242
}
4343
} else {
4444
let timeout = 9000;
4545
await this.$iOSSocketRequestExecutor.executeAttachRequest(this.device, timeout, projectId);
46-
this.socket = await this.device.connectToPort(IOSLiveSyncService.BACKEND_PORT);
46+
this.socket = await this.device.connectToPort(IOSDeviceLiveSyncService.BACKEND_PORT);
4747
}
4848

4949
this.attachEventHandlers();
@@ -55,12 +55,10 @@ export class IOSLiveSyncService implements INativeScriptDeviceLiveSyncService {
5555
await Promise.all(_.map(localToDevicePaths, localToDevicePathData => this.device.fileSystem.deleteFile(localToDevicePathData.getDevicePath(), appIdentifier)));
5656
}
5757

58-
public async refreshApplication(
59-
deviceAppData: Mobile.IDeviceAppData,
60-
localToDevicePaths: Mobile.ILocalToDevicePathData[],
61-
forceExecuteFullSync: boolean,
62-
projectData: IProjectData): Promise<void> {
63-
if (forceExecuteFullSync) {
58+
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
59+
const deviceAppData = liveSyncInfo.deviceAppData;
60+
const localToDevicePaths = liveSyncInfo.modifiedFilesData;
61+
if (liveSyncInfo.isFullSync) {
6462
await this.restartApplication(deviceAppData, projectData.projectName);
6563
return;
6664
}
@@ -72,7 +70,7 @@ export class IOSLiveSyncService implements INativeScriptDeviceLiveSyncService {
7270
let otherFiles = _.difference(localToDevicePaths, _.concat(scriptFiles, scriptRelatedFiles));
7371
let shouldRestart = _.some(otherFiles, (localToDevicePath: Mobile.ILocalToDevicePathData) => !this.$liveSyncProvider.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, deviceAppData.platform));
7472

75-
if (shouldRestart || (!this.$options.liveEdit && scriptFiles.length)) {
73+
if (shouldRestart || (!liveSyncInfo.useLiveEdit && scriptFiles.length)) {
7674
await this.restartApplication(deviceAppData, projectData.projectName);
7775
return;
7876
}
@@ -174,4 +172,4 @@ export class IOSLiveSyncService implements INativeScriptDeviceLiveSyncService {
174172
}
175173
}
176174
}
177-
$injector.register("iosLiveSyncServiceLocator", { factory: IOSLiveSyncService });
175+
$injector.register("iosLiveSyncServiceLocator", { factory: IOSDeviceLiveSyncService });

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class IOSLiveSyncService implements IPlatformLiveSyncService {
109109
let localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, mappedFiles, []);
110110
modifiedLocalToDevicePaths.push(...localToDevicePaths);
111111

112-
const deviceLiveSyncService = this.$injector.resolve(iosdls.IOSLiveSyncService, { _device: device });
112+
const deviceLiveSyncService = this.$injector.resolve(iosdls.IOSDeviceLiveSyncService, { _device: device });
113113
deviceLiveSyncService.removeFiles(projectData.projectId, localToDevicePaths, projectData.projectId);
114114
}
115115
}
@@ -122,9 +122,9 @@ export class IOSLiveSyncService implements IPlatformLiveSyncService {
122122
}
123123

124124
public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
125-
let deviceLiveSyncService = this.$injector.resolve(iosdls.IOSLiveSyncService, { _device: liveSyncInfo.deviceAppData.device });
125+
let deviceLiveSyncService = this.$injector.resolve(iosdls.IOSDeviceLiveSyncService, { _device: liveSyncInfo.deviceAppData.device });
126126
this.$logger.info("Refreshing application...");
127-
await deviceLiveSyncService.refreshApplication(liveSyncInfo.deviceAppData, liveSyncInfo.modifiedFilesData, liveSyncInfo.isFullSync, projectData);
127+
await deviceLiveSyncService.refreshApplication(projectData, liveSyncInfo);
128128
}
129129

130130
protected async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<void> {

lib/services/livesync/livesync-service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
138138
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
139139
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor);
140140

141-
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({ projectData, device, syncAllFiles: liveSyncData.syncAllFiles });
141+
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({ projectData, device, syncAllFiles: liveSyncData.syncAllFiles, useLiveEdit: liveSyncData.useLiveEdit });
142142
await this.refreshApplication(projectData, liveSyncResultInfo);
143143
//await device.applicationManager.restartApplication(projectData.projectId, projectData.projectName);
144144
};
@@ -206,7 +206,8 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
206206
filesToRemove: currentFilesToRemove,
207207
filesToSync: currentFilesToSync,
208208
isRebuilt: !!_.find(rebuiltInformation, info => info.isEmulator === device.isEmulator && info.platform === device.deviceInfo.platform),
209-
syncAllFiles: liveSyncData.syncAllFiles
209+
syncAllFiles: liveSyncData.syncAllFiles,
210+
useLiveEdit: liveSyncData.useLiveEdit
210211
};
211212

212213
const liveSyncResultInfo = await service.liveSyncWatchAction(device, settings);

0 commit comments

Comments
 (0)