Skip to content

Commit e045aa1

Browse files
author
Tsvetan Raikov
committed
Fixed: livesync should continue to work after app crash
1 parent bb1979d commit e045aa1

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

lib/services/livesync/android-device-livesync-service.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ class AndroidLiveSyncService implements IDeviceLiveSyncService {
6969
private reloadPage(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> {
7070
return (() => {
7171
this.device.adb.executeCommand(["forward", `tcp:${AndroidLiveSyncService.BACKEND_PORT.toString()}`, `localabstract:${deviceAppData.appIdentifier}-livesync`]).wait();
72-
this.sendPageReloadMessage().wait();
72+
if (!this.sendPageReloadMessage().wait()) {
73+
this.restartApplication(deviceAppData).wait();
74+
}
7375
}).future<void>()();
7476
}
7577

@@ -97,15 +99,25 @@ class AndroidLiveSyncService implements IDeviceLiveSyncService {
9799
return `/data/local/tmp/${appIdentifier}`;
98100
}
99101

100-
private sendPageReloadMessage(): IFuture<void> {
101-
let future = new Future<void>();
102+
private sendPageReloadMessage(): IFuture<boolean> {
103+
let future = new Future<boolean>();
102104
let socket = new net.Socket();
103105
socket.connect(AndroidLiveSyncService.BACKEND_PORT, '127.0.0.1', () => {
104106
socket.write(new Buffer([0, 0, 0, 1, 1]));
105107
});
106108
socket.on("data", (data: any) => {
107109
socket.destroy();
108-
future.return();
110+
future.return(true);
111+
});
112+
socket.on("error", () => {
113+
if (!future.isResolved()) {
114+
future.return(false);
115+
}
116+
});
117+
socket.on("close", () => {
118+
if (!future.isResolved()) {
119+
future.return(false);
120+
}
109121
});
110122
return future;
111123
}

lib/services/livesync/ios-device-livesync-service.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class IOSLiveSyncService implements IDeviceLiveSyncService {
4747
try {
4848
this.socket = helpers.connectEventuallyUntilTimeout(() => net.connect(IOSLiveSyncService.BACKEND_PORT), 5000).wait();
4949
} catch (e) {
50-
this.$logger.warn(e);
51-
50+
this.$logger.debug(e);
5251
return false;
5352
}
5453
} else {
@@ -82,21 +81,16 @@ class IOSLiveSyncService implements IDeviceLiveSyncService {
8281
let otherFiles = _.difference(localToDevicePaths, _.concat(scriptFiles, scriptRelatedFiles));
8382
let shouldRestart = _.some(otherFiles, (localToDevicePath: Mobile.ILocalToDevicePathData) => !this.$liveSyncProvider.canExecuteFastSync(localToDevicePath.getLocalPath(), deviceAppData.platform));
8483

85-
if (shouldRestart) {
84+
if (shouldRestart || (!this.$options.liveEdit && scriptFiles.length)) {
8685
this.restartApplication(deviceAppData).wait();
87-
88-
return;
89-
}
90-
91-
if (!this.$options.liveEdit && scriptFiles.length) {
92-
this.restartApplication(deviceAppData).wait();
93-
9486
return;
9587
}
9688

9789
if (this.setupSocketIfNeeded().wait()) {
9890
this.liveEdit(scriptFiles);
9991
this.reloadPage(deviceAppData, otherFiles).wait();
92+
} else {
93+
this.restartApplication(deviceAppData).wait();
10094
}
10195
}).future<void>()();
10296
}

0 commit comments

Comments
 (0)