From e045aa1cf010625cbb6d1de81937e5a74700876c Mon Sep 17 00:00:00 2001 From: Tsvetan Raikov Date: Tue, 29 Nov 2016 17:32:25 +0200 Subject: [PATCH] Fixed: livesync should continue to work after app crash --- .../android-device-livesync-service.ts | 20 +++++++++++++++---- .../livesync/ios-device-livesync-service.ts | 14 ++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/services/livesync/android-device-livesync-service.ts b/lib/services/livesync/android-device-livesync-service.ts index 9689f9b3c2..c58f101462 100644 --- a/lib/services/livesync/android-device-livesync-service.ts +++ b/lib/services/livesync/android-device-livesync-service.ts @@ -69,7 +69,9 @@ class AndroidLiveSyncService implements IDeviceLiveSyncService { private reloadPage(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture { return (() => { this.device.adb.executeCommand(["forward", `tcp:${AndroidLiveSyncService.BACKEND_PORT.toString()}`, `localabstract:${deviceAppData.appIdentifier}-livesync`]).wait(); - this.sendPageReloadMessage().wait(); + if (!this.sendPageReloadMessage().wait()) { + this.restartApplication(deviceAppData).wait(); + } }).future()(); } @@ -97,15 +99,25 @@ class AndroidLiveSyncService implements IDeviceLiveSyncService { return `/data/local/tmp/${appIdentifier}`; } - private sendPageReloadMessage(): IFuture { - let future = new Future(); + private sendPageReloadMessage(): IFuture { + let future = new Future(); let socket = new net.Socket(); socket.connect(AndroidLiveSyncService.BACKEND_PORT, '127.0.0.1', () => { socket.write(new Buffer([0, 0, 0, 1, 1])); }); socket.on("data", (data: any) => { socket.destroy(); - future.return(); + future.return(true); + }); + socket.on("error", () => { + if (!future.isResolved()) { + future.return(false); + } + }); + socket.on("close", () => { + if (!future.isResolved()) { + future.return(false); + } }); return future; } diff --git a/lib/services/livesync/ios-device-livesync-service.ts b/lib/services/livesync/ios-device-livesync-service.ts index e85adddfc6..17fe58c403 100644 --- a/lib/services/livesync/ios-device-livesync-service.ts +++ b/lib/services/livesync/ios-device-livesync-service.ts @@ -47,8 +47,7 @@ class IOSLiveSyncService implements IDeviceLiveSyncService { try { this.socket = helpers.connectEventuallyUntilTimeout(() => net.connect(IOSLiveSyncService.BACKEND_PORT), 5000).wait(); } catch (e) { - this.$logger.warn(e); - + this.$logger.debug(e); return false; } } else { @@ -82,21 +81,16 @@ class IOSLiveSyncService implements IDeviceLiveSyncService { let otherFiles = _.difference(localToDevicePaths, _.concat(scriptFiles, scriptRelatedFiles)); let shouldRestart = _.some(otherFiles, (localToDevicePath: Mobile.ILocalToDevicePathData) => !this.$liveSyncProvider.canExecuteFastSync(localToDevicePath.getLocalPath(), deviceAppData.platform)); - if (shouldRestart) { + if (shouldRestart || (!this.$options.liveEdit && scriptFiles.length)) { this.restartApplication(deviceAppData).wait(); - - return; - } - - if (!this.$options.liveEdit && scriptFiles.length) { - this.restartApplication(deviceAppData).wait(); - return; } if (this.setupSocketIfNeeded().wait()) { this.liveEdit(scriptFiles); this.reloadPage(deviceAppData, otherFiles).wait(); + } else { + this.restartApplication(deviceAppData).wait(); } }).future()(); }