Skip to content

Commit 74f7fd6

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Some improvements
1 parent d6a2a05 commit 74f7fd6

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

lib/services/usb-livesync-service.ts

+28-16
Original file line numberDiff line numberDiff line change
@@ -207,32 +207,31 @@ 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.sendReloadMessage(socket);
210+
this.sendPageReloadMessage(socket);
211211
}).future<void>()();
212212
}
213213

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

219-
private sendReloadMessage(socket: net.Socket): void {
219+
private sendPageReloadMessage(socket: net.Socket): void {
220220
try {
221-
this.sendReloadMessageCore(socket);
221+
this.sendPageReloadMessageCore(socket);
222222
} finally {
223223
socket.destroy();
224224
}
225225
}
226226

227-
private sendReloadMessageCore(socket: net.Socket): void {
227+
private sendPageReloadMessageCore(socket: net.Socket): void {
228228
let message = `{ "method":"Page.reload","params":{"ignoreCache":false},"id":${++currentPageReloadId} }`;
229229
let length = Buffer.byteLength(message, "utf16le");
230230
let payload = new Buffer(length + 4);
231231
payload.writeInt32BE(length, 0);
232232
payload.write(message, 4, length, "utf16le");
233233
socket.write(payload);
234234
}
235-
236235
}
237236
$injector.register("iosUsbLiveSyncServiceLocator", {factory: IOSUsbLiveSyncService});
238237

@@ -248,8 +247,7 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
248247

249248
public restartApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> {
250249
return (() => {
251-
this.device.adb.executeShellCommand(["chmod", "777", deviceAppData.deviceProjectRootPath]).wait();
252-
this.device.adb.executeShellCommand(["chmod", "777", `/data/local/tmp/${deviceAppData.appIdentifier}`]).wait();
250+
this.device.adb.executeShellCommand(["chmod", "777", deviceAppData.deviceProjectRootPath, `/data/local/tmp/${deviceAppData.appIdentifier}`]).wait();
253251

254252
if(this.$options.companion) {
255253
let commands = [ this.liveSyncCommands.SyncFilesCommand() ];
@@ -267,21 +265,35 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
267265
public beforeLiveSyncAction(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
268266
return (() => {
269267
let deviceRootPath = `/data/local/tmp/${deviceAppData.appIdentifier}`;
270-
this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync")]).wait();
271-
this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "sync")]).wait();
272-
this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync")]).wait();
268+
this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync"),
269+
this.$mobileHelper.buildDevicePath(deviceRootPath, "sync"),
270+
this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync")]).wait();
273271
}).future<void>()();
274272
}
275273

276274
public sendPageReloadMessageToDevice(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
277275
return (() => {
278-
let socket = new net.Socket();
279-
socket.connect(AndroidUsbLiveSyncService.BACKEND_PORT, '127.0.0.1', () => {
280-
socket.write(new Buffer([0, 0, 0, 1, 1]));
281-
socket.destroy();
282-
});
283276
this.device.adb.executeCommand(["forward", `tcp:${AndroidUsbLiveSyncService.BACKEND_PORT.toString()}`, `localabstract:${deviceAppData.appIdentifier}-livesync`]).wait();
277+
this.sendPageReloadMessage().wait();
284278
}).future<void>()();
285279
}
280+
281+
private sendPageReloadMessage(): IFuture<void> {
282+
let future = new Future<void>();
283+
284+
let socket = new net.Socket();
285+
socket.connect(AndroidUsbLiveSyncService.BACKEND_PORT, '127.0.0.1', () => {
286+
try {
287+
socket.write(new Buffer([0, 0, 0, 1, 1]));
288+
future.return();
289+
} catch(e) {
290+
future.throw(e);
291+
} finally {
292+
socket.destroy();
293+
}
294+
});
295+
296+
return future;
297+
}
286298
}
287299
$injector.register("androidUsbLiveSyncServiceLocator", {factory: AndroidUsbLiveSyncService});

0 commit comments

Comments
 (0)