Skip to content

Commit ac77f74

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

File tree

4 files changed

+83
-85
lines changed

4 files changed

+83
-85
lines changed

lib/declarations.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ interface IUsbLiveSyncService {
5858
liveSync(platform: string): IFuture<void>;
5959
}
6060

61-
interface IPlatformSpecificUsbLiveSyncService {
62-
restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths?: Mobile.ILocalToDevicePathData[]): IFuture<void>;
63-
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): IFuture<void>;
64-
sendPageReloadMessageToDevice(): IFuture<void>;
61+
interface IiOSUsbLiveSyncService extends IPlatformSpecificUsbLiveSyncService {
6562
sendPageReloadMessageToSimulator(): IFuture<void>;
6663
}
6764

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
@@ -91,20 +91,23 @@ class TestExecutionService implements ITestExecutionService {
9191
};
9292

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

109112
if (this.$options.debugBrk) {
110113
this.$logger.info('Starting debugger...');

lib/services/usb-livesync-service.ts

+61-56
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 {
@@ -76,7 +72,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
7672
let notRunningiOSSimulatorAction = (): IFuture<boolean> => {
7773
return (() => {
7874
this.$platformService.deployOnEmulator(this.$devicePlatformsConstants.iOS.toLowerCase()).wait();
79-
return false;
75+
return false;
8076
}).future<boolean>()();
8177
};
8278

@@ -106,8 +102,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
106102
mappedFilePath = path.join(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait(), appResourcesRelativePath);
107103
}
108104

109-
this.sendPageReloadMessage(path.extname(mappedFilePath), platform).wait();
110-
111105
return mappedFilePath;
112106
}).future<string>()();
113107
};
@@ -116,12 +110,6 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
116110
return path.join(constants.APP_FOLDER_NAME, path.dirname(projectFile.split(`/${constants.APP_FOLDER_NAME}/`)[1]));
117111
};
118112

119-
let shouldRestartApplication = (localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<boolean> => {
120-
return (() => {
121-
return false;
122-
}).future<boolean>()();
123-
};
124-
125113
let watchGlob = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
126114

127115
let platformSpecificLiveSyncServices: IDictionary<any> = {
@@ -131,20 +119,51 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
131119

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

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

@@ -162,28 +181,10 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
162181

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

186-
export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
187+
export class IOSUsbLiveSyncService implements IiOSUsbLiveSyncService {
187188
private static BACKEND_PORT = 18181;
188189
private currentPageReloadId = 0;
189190

@@ -200,7 +201,7 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
200201
return this.device.applicationManager.restartApplication(deviceAppData.appIdentifier);
201202
}
202203

203-
public sendPageReloadMessageToDevice(): IFuture<void> {
204+
public sendPageReloadMessageToDevice(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
204205
return (() => {
205206
let timeout = 9000;
206207
this.$iOSSocketRequestExecutor.executeAttachRequest(this.device, timeout).wait();
@@ -229,12 +230,13 @@ export class IOSUsbLiveSyncService implements IPlatformSpecificUsbLiveSyncServic
229230
$injector.register("iosUsbLiveSyncServiceLocator", {factory: IOSUsbLiveSyncService});
230231

231232
export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.AndroidLiveSyncService implements IPlatformSpecificUsbLiveSyncService {
233+
private static BACKEND_PORT = 18181;
234+
232235
constructor(_device: Mobile.IDevice,
233236
$fs: IFileSystem,
234237
$mobileHelper: Mobile.IMobileHelper,
235238
private $options: IOptions) {
236239
super(<Mobile.IAndroidDevice>_device, $fs, $mobileHelper);
237-
238240
}
239241

240242
public restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> {
@@ -264,12 +266,15 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
264266
}).future<void>()();
265267
}
266268

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

0 commit comments

Comments
 (0)