Skip to content

Commit c95e3e1

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Send page reload message to android runtime
1 parent 1a672c2 commit c95e3e1

File tree

5 files changed

+86
-82
lines changed

5 files changed

+86
-82
lines changed

lib/declarations.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ interface IUsbLiveSyncService {
6060

6161
interface IPlatformSpecificUsbLiveSyncService {
6262
restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture<void>;
63+
sendPageReloadMessageToDevice(deviceAppData: Mobile.IDeviceAppData): IFuture<void>;
6364
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): IFuture<void>;
64-
sendPageReloadMessageToDevice(): IFuture<void>;
65+
}
66+
67+
interface IiOSUsbLiveSyncService extends IPlatformSpecificUsbLiveSyncService {
6568
sendPageReloadMessageToSimulator(): IFuture<void>;
6669
}
6770

lib/services/ios-debug-service.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class IOSDebugService implements IDebugService {
6565

6666
public debugStart(): IFuture<void> {
6767
return (() => {
68-
this.$devicesServices.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
69-
this.$devicesServices.execute((device: Mobile.IiOSDevice) => this.debugBrkCore(device)).wait();
68+
this.$devicesService.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
69+
this.$devicesService.execute((device: Mobile.IiOSDevice) => this.debugBrkCore(device)).wait();
7070
}).future<void>()();
7171
}
7272

@@ -117,13 +117,6 @@ class IOSDebugService implements IDebugService {
117117
}).future<void>()();
118118
}
119119

120-
public debugStart(): IFuture<void> {
121-
return (() => {
122-
this.$devicesService.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
123-
this.$devicesService.execute((device: iOSDevice.IOSDevice) => this.debugBrkCore(device)).wait();
124-
}).future<void>()();
125-
}
126-
127120
private debugBrkCore(device: Mobile.IiOSDevice): IFuture<void> {
128121
return (() => {
129122
let timeout = this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS);
@@ -136,8 +129,8 @@ class IOSDebugService implements IDebugService {
136129

137130
private deviceStart(): IFuture<void> {
138131
return (() => {
139-
this.$devicesServices.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
140-
this.$devicesServices.execute((device: Mobile.IiOSDevice) => this.deviceStartCore(device)).wait();
132+
this.$devicesService.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
133+
this.$devicesService.execute((device: Mobile.IiOSDevice) => this.deviceStartCore(device)).wait();
141134
}).future<void>()();
142135
}
143136

lib/services/test-execution-service.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,23 @@ class TestExecutionService implements ITestExecutionService {
8787
};
8888

8989
let localProjectRootPath = platform.toLowerCase() === "ios" ? platformData.appDestinationDirectoryPath : null;
90-
this.$usbLiveSyncServiceBase.sync(platform,
91-
this.$projectData.projectId,
92-
projectFilesPath,
93-
constants.LIVESYNC_EXCLUDED_DIRECTORIES,
94-
watchGlob,
95-
platformSpecificLiveSyncServices,
96-
notInstalledAppOnDeviceAction,
97-
notRunningiOSSimulatorAction,
98-
localProjectRootPath,
99-
(device: Mobile.IDevice, deviceAppData:Mobile.IDeviceAppData) => Future.fromResult(),
100-
beforeBatchLiveSyncAction,
101-
(projectFile: string) => "",
102-
(localToDevicePaths: Mobile.ILocalToDevicePathData[]) => Future.fromResult(!this.$options.debugBrk)
103-
).wait();
90+
91+
let liveSyncData = {
92+
platform: platform,
93+
appIdentifier: this.$projectData.projectId,
94+
projectFilesPath: projectFilesPath,
95+
excludedProjectDirsAndFiles: constants.LIVESYNC_EXCLUDED_DIRECTORIES,
96+
watchGlob: watchGlob,
97+
platformSpecificLiveSyncServices: platformSpecificLiveSyncServices,
98+
notInstalledAppOnDeviceAction: notInstalledAppOnDeviceAction,
99+
notRunningiOSSimulatorAction: notRunningiOSSimulatorAction,
100+
localProjectRootPath: localProjectRootPath,
101+
beforeBatchLiveSyncAction: beforeBatchLiveSyncAction,
102+
shouldRestartApplication: (localToDevicePaths: Mobile.ILocalToDevicePathData[]) => Future.fromResult(!this.$options.debugBrk),
103+
canExecuteFastLiveSync: (filePath: string) => false,
104+
};
105+
106+
this.$usbLiveSyncServiceBase.sync(liveSyncData).wait();
104107

105108
if (this.$options.debugBrk) {
106109
this.$logger.info('Starting debugger...');

lib/services/usb-livesync-service.ts

+60-55
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
1515
"**/*.ts",
1616
];
1717

18-
private fastLivesyncFileExtensions = [".css", ".xml"];
19-
20-
constructor($devicesServices: Mobile.IDevicesServices,
18+
constructor($devicesService: Mobile.IDevicesService,
2119
$fs: IFileSystem,
2220
$mobileHelper: Mobile.IMobileHelper,
2321
$localToDevicePathDataFactory: Mobile.ILocalToDevicePathDataFactory,
@@ -51,9 +49,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
5149
this.$projectDataService.initialize(this.$projectData.projectDir);
5250
let frameworkVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).wait().version;
5351
if (semver.lt(frameworkVersion, "1.2.1")) {
54-
let shouldUpdate = this.$prompter.confirm(
55-
"You need Android Runtime 1.2.1 or later for LiveSync to work properly. Do you want to update your runtime now?"
56-
).wait();
52+
let shouldUpdate = this.$prompter.confirm("You need Android Runtime 1.2.1 or later for LiveSync to work properly. Do you want to update your runtime now?").wait();
5753
if(shouldUpdate) {
5854
this.$platformService.updatePlatforms([this.$devicePlatformsConstants.Android.toLowerCase()]).wait();
5955
} else {
@@ -103,8 +99,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
10399
mappedFilePath = path.join(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait(), appResourcesRelativePath);
104100
}
105101

106-
this.sendPageReloadMessage(path.extname(mappedFilePath), platform).wait();
107-
108102
return mappedFilePath;
109103
}).future<string>()();
110104
};
@@ -113,12 +107,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
113107
return path.join(constants.APP_FOLDER_NAME, path.dirname(projectFile.split(`/${constants.APP_FOLDER_NAME}/`)[1]));
114108
};
115109

116-
let shouldRestartApplication = (localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<boolean> => {
117-
return (() => {
118-
return false;
119-
}).future<boolean>()();
120-
};
121-
122110
let watchGlob = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
123111

124112
let platformSpecificLiveSyncServices: IDictionary<any> = {
@@ -128,20 +116,51 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
128116

129117
let localProjectRootPath = platform.toLowerCase() === "ios" ? platformData.appDestinationDirectoryPath : null;
130118

131-
this.sync(platform,
132-
this.$projectData.projectId,
133-
projectFilesPath,
134-
this.excludedProjectDirsAndFiles,
135-
watchGlob,
136-
platformSpecificLiveSyncServices,
137-
notInstalledAppOnDeviceAction,
138-
notRunningiOSSimulatorAction,
139-
localProjectRootPath,
140-
beforeLiveSyncAction,
141-
beforeBatchLiveSyncAction,
142-
iOSSimulatorRelativeToProjectBasePathAction,
143-
shouldRestartApplication
144-
).wait();
119+
let fastLivesyncFileExtensions = [".css", ".xml"];
120+
let canExecuteFastLiveSync = (filePath: string) => _.contains(fastLivesyncFileExtensions, path.extname(filePath));
121+
122+
let fastLiveSync = (filePath: string) => {
123+
return (() => {
124+
this.$platformService.preparePlatform(platform).wait();
125+
let mappedFilePath = beforeBatchLiveSyncAction(filePath).wait();
126+
127+
if (this.shouldSynciOSSimulator(platform).wait()) {
128+
let platformSpecificUsbLiveSyncService = <IiOSUsbLiveSyncService>this.resolvePlatformSpecificLiveSyncService(platform || this.$devicesService.platform, null, platformSpecificLiveSyncServices);
129+
platformSpecificUsbLiveSyncService.sendPageReloadMessageToSimulator().wait();
130+
} else {
131+
let deviceAppData = this.$deviceAppDataFactory.create(this.$projectData.projectId, this.$mobileHelper.normalizePlatformName(platform));
132+
let localToDevicePaths = this.createLocalToDevicePaths(platform, this.$projectData.projectId, projectFilesPath, [mappedFilePath]);
133+
134+
let devices = this.$devicesService.getDeviceInstances();
135+
_.each(devices, (device: Mobile.IDevice) => {
136+
this.transferFiles(device, deviceAppData, localToDevicePaths);
137+
let platformSpecificUsbLiveSyncService = this.resolvePlatformSpecificLiveSyncService(platform || this.$devicesService.platform, device, platformSpecificLiveSyncServices);
138+
return platformSpecificUsbLiveSyncService.sendPageReloadMessageToDevice(deviceAppData);
139+
});
140+
141+
this.$dispatcher.dispatch(() => Future.fromResult());
142+
}
143+
}).future<void>()();
144+
};
145+
146+
let liveSyncData = {
147+
platform: platform,
148+
appIdentifier: this.$projectData.projectId,
149+
projectFilesPath: projectFilesPath,
150+
excludedProjectDirsAndFiles: this.excludedProjectDirsAndFiles,
151+
watchGlob: watchGlob,
152+
platformSpecificLiveSyncServices: platformSpecificLiveSyncServices,
153+
notInstalledAppOnDeviceAction: notInstalledAppOnDeviceAction,
154+
notRunningiOSSimulatorAction: notRunningiOSSimulatorAction,
155+
localProjectRootPath: localProjectRootPath,
156+
beforeLiveSyncAction: beforeLiveSyncAction,
157+
beforeBatchLiveSyncAction: beforeBatchLiveSyncAction,
158+
iOSSimulatorRelativeToProjectBasePathAction: iOSSimulatorRelativeToProjectBasePathAction,
159+
canExecuteFastLiveSync: canExecuteFastLiveSync,
160+
fastLiveSync: fastLiveSync
161+
};
162+
163+
this.sync(liveSyncData).wait();
145164
}).future<void>()();
146165
}
147166

@@ -159,28 +178,10 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
159178

160179
return platformSpecificUsbLiveSyncService;
161180
}
162-
163-
private sendPageReloadMessage(fileExtension: string, platform: string): IFuture<void> {
164-
return (() => {
165-
if(_.contains(this.fastLivesyncFileExtensions, fileExtension)) {
166-
let platformLowerCase = platform ? platform.toLowerCase() : null;
167-
if(this.$options.emulator && platformLowerCase === "ios") {
168-
let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, null);
169-
platformSpecificUsbLiveSyncService.sendPageReloadMessageToSimulator().wait();
170-
} else {
171-
let devices = this.$devicesServices.getDevices();
172-
_.each(devices, (device: Mobile.IDevice) => {
173-
let platformSpecificUsbLiveSyncService = this.resolveUsbLiveSyncService(platform || this.$devicesServices.platform, device);
174-
return platformSpecificUsbLiveSyncService.sendPageReloadMessageToDevice();
175-
});
176-
}
177-
}
178-
}).future<void>()();
179-
}
180181
}
181182
$injector.register("usbLiveSyncService", UsbLiveSyncService);
182183

183-
export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
184+
export class IOSUsbLiveSyncService implements IiOSUsbLiveSyncService {
184185
private static BACKEND_PORT = 18181;
185186
private currentPageReloadId = 0;
186187

@@ -197,7 +198,7 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
197198
return this.device.applicationManager.restartApplication(deviceAppData.appIdentifier);
198199
}
199200

200-
public sendPageReloadMessageToDevice(): IFuture<void> {
201+
public sendPageReloadMessageToDevice(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
201202
return (() => {
202203
let timeout = 9000;
203204
this.$iOSSocketRequestExecutor.executeAttachRequest(this.device, timeout).wait();
@@ -226,12 +227,13 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
226227
$injector.register("iosUsbLiveSyncServiceLocator", {factory: IOSUsbLiveSyncService});
227228

228229
export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.AndroidLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
230+
private static BACKEND_PORT = 18181;
231+
229232
constructor(_device: Mobile.IDevice,
230233
$fs: IFileSystem,
231234
$mobileHelper: Mobile.IMobileHelper,
232235
private $options: IOptions) {
233236
super(<Mobile.IAndroidDevice>_device, $fs, $mobileHelper);
234-
235237
}
236238

237239
public restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> {
@@ -261,12 +263,15 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
261263
}).future<void>()();
262264
}
263265

264-
public sendPageReloadMessageToSimulator(): IFuture<void> {
265-
return Future.fromResult();
266-
}
267-
268-
public sendPageReloadMessageToDevice(): IFuture<void> {
269-
return Future.fromResult();
266+
public sendPageReloadMessageToDevice(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
267+
return (() => {
268+
let socket = new net.Socket();
269+
socket.connect(AndroidUsbLiveSyncService.BACKEND_PORT, '127.0.0.1', () => {
270+
socket.write(new Buffer([0, 0, 0, 1, 1]));
271+
socket.destroy();
272+
});
273+
this.device.adb.executeCommand(["forward", `tcp:${AndroidUsbLiveSyncService.BACKEND_PORT.toString()}`, `localabstract:${deviceAppData.appIdentifier}-livesync`]).wait();
274+
}).future<void>()();
270275
}
271276
}
272277
$injector.register("androidUsbLiveSyncServiceLocator", {factory: AndroidUsbLiveSyncService});

0 commit comments

Comments
 (0)