Skip to content

Commit 4f430ac

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Send page reload message to android runtime
1 parent a418afc commit 4f430ac

File tree

5 files changed

+86
-82
lines changed

5 files changed

+86
-82
lines changed

lib/common

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,
@@ -49,9 +47,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
4947
this.$projectDataService.initialize(this.$projectData.projectDir);
5048
let frameworkVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).wait().version;
5149
if (semver.lt(frameworkVersion, "1.2.1")) {
52-
let shouldUpdate = this.$prompter.confirm(
53-
"You need Android Runtime 1.2.1 or later for LiveSync to work properly. Do you want to update your runtime now?"
54-
).wait();
50+
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();
5551
if(shouldUpdate) {
5652
this.$platformService.updatePlatforms([this.$devicePlatformsConstants.Android.toLowerCase()]).wait();
5753
} else {
@@ -101,8 +97,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
10197
mappedFilePath = path.join(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait(), appResourcesRelativePath);
10298
}
10399

104-
this.sendPageReloadMessage(path.extname(mappedFilePath), platform).wait();
105-
106100
return mappedFilePath;
107101
}).future<string>()();
108102
};
@@ -111,12 +105,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
111105
return path.join(constants.APP_FOLDER_NAME, path.dirname(projectFile.split(`/${constants.APP_FOLDER_NAME}/`)[1]));
112106
};
113107

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

122110
let platformSpecificLiveSyncServices: IDictionary<any> = {
@@ -126,20 +114,51 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
126114

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

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

@@ -157,28 +176,10 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
157176

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

181-
export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
182+
export class IOSUsbLiveSyncService implements IiOSUsbLiveSyncService {
182183
private static BACKEND_PORT = 18181;
183184
private currentPageReloadId = 0;
184185

@@ -195,7 +196,7 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
195196
return this.device.applicationManager.restartApplication(deviceAppData.appIdentifier);
196197
}
197198

198-
public sendPageReloadMessageToDevice(): IFuture<void> {
199+
public sendPageReloadMessageToDevice(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
199200
return (() => {
200201
let timeout = 9000;
201202
this.$iOSSocketRequestExecutor.executeAttachRequest(this.device, timeout).wait();
@@ -224,12 +225,13 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
224225
$injector.register("iosUsbLiveSyncServiceLocator", {factory: IOSUsbLiveSyncService});
225226

226227
export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.AndroidLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
228+
private static BACKEND_PORT = 18181;
229+
227230
constructor(_device: Mobile.IDevice,
228231
$fs: IFileSystem,
229232
$mobileHelper: Mobile.IMobileHelper,
230233
private $options: IOptions) {
231234
super(<Mobile.IAndroidDevice>_device, $fs, $mobileHelper);
232-
233235
}
234236

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

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

0 commit comments

Comments
 (0)