Skip to content

Commit d6a2a05

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Destroy gdb sockets and propagate exceptions to user
1 parent 727a0df commit d6a2a05

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

lib/services/usb-livesync-service.ts

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
6666

6767
let projectFilesPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
6868

69-
let notInstalledAppOnDeviceAction = (device: Mobile.IDevice): IFuture<void> => this.$platformService.deployOnDevice(platform);
69+
let notInstalledAppOnDeviceAction = (device: Mobile.IDevice): IFuture<void> => this.$platformService.installOnDevice(platform);
7070

7171
let notRunningiOSSimulatorAction = (): IFuture<void> => this.$platformService.deployOnEmulator(this.$devicePlatformsConstants.iOS.toLowerCase());
7272

@@ -117,29 +117,29 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer
117117
let canExecuteFastLiveSync = (filePath: string) => _.contains(fastLivesyncFileExtensions, path.extname(filePath));
118118

119119
let fastLiveSync = (filePath: string) => {
120-
return (() => {
121-
this.$platformService.preparePlatform(platform).wait();
122-
let mappedFilePath = beforeBatchLiveSyncAction(filePath).wait();
123-
124-
if (this.shouldSynciOSSimulator(platform).wait()) {
125-
this.$iOSEmulatorServices.transferFiles(this.$projectData.projectId, [filePath], iOSSimulatorRelativeToProjectBasePathAction).wait();
126-
127-
let platformSpecificUsbLiveSyncService = <IiOSUsbLiveSyncService>this.resolvePlatformSpecificLiveSyncService(platform || this.$devicesService.platform, null, platformSpecificLiveSyncServices);
128-
platformSpecificUsbLiveSyncService.sendPageReloadMessageToSimulator().wait();
129-
} else {
130-
let deviceAppData = this.$deviceAppDataFactory.create(this.$projectData.projectId, this.$mobileHelper.normalizePlatformName(platform));
131-
let localToDevicePaths = this.createLocalToDevicePaths(platform, this.$projectData.projectId, localProjectRootPath || projectFilesPath, [mappedFilePath]);
132-
133-
let devices = this.$devicesService.getDeviceInstances();
134-
_.each(devices, (device: Mobile.IDevice) => {
135-
this.transferFiles(device, deviceAppData, localToDevicePaths, projectFilesPath, true).wait();
136-
let platformSpecificUsbLiveSyncService = this.resolvePlatformSpecificLiveSyncService(platform || this.$devicesService.platform, device, platformSpecificLiveSyncServices);
137-
return platformSpecificUsbLiveSyncService.sendPageReloadMessageToDevice(deviceAppData).wait();
138-
});
139-
140-
this.$dispatcher.dispatch(() => Future.fromResult());
141-
}
142-
}).future<void>()();
120+
this.$dispatcher.dispatch(() => {
121+
return (() => {
122+
this.$platformService.preparePlatform(platform).wait();
123+
let mappedFilePath = beforeBatchLiveSyncAction(filePath).wait();
124+
125+
if (this.shouldSynciOSSimulator(platform).wait()) {
126+
this.$iOSEmulatorServices.transferFiles(this.$projectData.projectId, [filePath], iOSSimulatorRelativeToProjectBasePathAction).wait();
127+
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, localProjectRootPath || projectFilesPath, [mappedFilePath]);
133+
134+
let devices = this.$devicesService.getDeviceInstances();
135+
_.each(devices, (device: Mobile.IDevice) => {
136+
this.transferFiles(device, deviceAppData, localToDevicePaths, projectFilesPath, true).wait();
137+
let platformSpecificUsbLiveSyncService = this.resolvePlatformSpecificLiveSyncService(platform || this.$devicesService.platform, device, platformSpecificLiveSyncServices);
138+
return platformSpecificUsbLiveSyncService.sendPageReloadMessageToDevice(deviceAppData).wait();
139+
});
140+
}
141+
}).future<void>()()
142+
});
143143
};
144144

145145
let liveSyncData = {
@@ -207,24 +207,32 @@ export class IOSUsbLiveSyncService implements IiOSUsbLiveSyncService {
207207
let timeout = 9000;
208208
this.$iOSSocketRequestExecutor.executeAttachRequest(this.device, timeout).wait();
209209
let socket = this.device.connectToPort(IOSUsbLiveSyncService.BACKEND_PORT);
210-
this.sendReloadMessageCore(socket);
210+
this.sendReloadMessage(socket);
211211
}).future<void>()();
212212
}
213213

214214
public sendPageReloadMessageToSimulator(): IFuture<void> {
215-
helpers.connectEventually(() => net.connect(IOSUsbLiveSyncService.BACKEND_PORT), (socket: net.Socket) => this.sendReloadMessageCore(socket));
215+
helpers.connectEventually(() => net.connect(IOSUsbLiveSyncService.BACKEND_PORT), (socket: net.Socket) => this.sendReloadMessage(socket));
216216
return this.$iOSEmulatorServices.postDarwinNotification(this.$iOSNotification.attachRequest);
217217
}
218218

219+
private sendReloadMessage(socket: net.Socket): void {
220+
try {
221+
this.sendReloadMessageCore(socket);
222+
} finally {
223+
socket.destroy();
224+
}
225+
}
226+
219227
private sendReloadMessageCore(socket: net.Socket): void {
220228
let message = `{ "method":"Page.reload","params":{"ignoreCache":false},"id":${++currentPageReloadId} }`;
221229
let length = Buffer.byteLength(message, "utf16le");
222230
let payload = new Buffer(length + 4);
223231
payload.writeInt32BE(length, 0);
224232
payload.write(message, 4, length, "utf16le");
225233
socket.write(payload);
226-
socket.destroy();
227234
}
235+
228236
}
229237
$injector.register("iosUsbLiveSyncServiceLocator", {factory: IOSUsbLiveSyncService});
230238

0 commit comments

Comments
 (0)