Skip to content

Commit a1b4d83

Browse files
committed
fix: app not restarted if in error activity
1 parent 34fe8d4 commit a1b4d83

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

lib/definitions/livesync.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ interface IAndroidLivesyncTool {
414414
* @param timeout - The timeout in milliseconds
415415
* @returns {Promise<void>}
416416
*/
417-
sendDoSyncOperation(operationId: string, timeout?: number): Promise<void>;
417+
sendDoSyncOperation(operationId: string, timeout?: number): Promise<IAndroidLivesyncSyncOperationResult>;
418418
/**
419419
* Generates new operation identifier.
420420
*/
@@ -454,6 +454,11 @@ interface IAndroidLivesyncToolConfiguration {
454454
errorHandler?: any;
455455
}
456456

457+
interface IAndroidLivesyncSyncOperationResult {
458+
operationId: string,
459+
didRefresh: boolean
460+
}
461+
457462
interface IDeviceProjectRootOptions {
458463
appIdentifier: string;
459464
getDirname?: boolean;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
5050
this.$processService.attachToProcessExitSignals(this, clearSyncInterval);
5151
doSyncPromise.then(clearSyncInterval, clearSyncInterval);
5252

53-
await doSyncPromise;
53+
const refreshResult = await doSyncPromise;
5454

55-
if (!canExecuteFastSync) {
55+
if (!canExecuteFastSync || !refreshResult.didRefresh) {
5656
await this.device.applicationManager.restartApplication({ appId: liveSyncInfo.deviceAppData.appIdentifier, projectName: projectData.projectName });
5757
}
5858
}
@@ -61,7 +61,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
6161
}
6262

6363
public async removeFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void> {
64-
await this.livesyncTool.removeFiles(_.map(localToDevicePaths, (element: any) => { return element.filePath; }));
64+
await this.livesyncTool.removeFiles(_.map(localToDevicePaths, (element: any) => element.filePath));
6565
}
6666

6767
public async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<Mobile.ILocalToDevicePathData[]> {

lib/services/livesync/android-livesync-library.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const CREATE_FILE_OPERATION = 8;
1010
const DO_SYNC_OPERATION = 9;
1111
const ERROR_REPORT = 1;
1212
const OPERATION_END_REPORT = 2;
13+
const OPERATION_END_NO_REFRESH_REPORT_CODE = 3;
1314
const REPORT_LENGTH = 1;
1415
const DEFAULT_LOCAL_HOST_ADDRESS = "127.0.0.1";
1516

@@ -118,9 +119,9 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
118119
return !!this.operationPromises[operationId];
119120
}
120121

121-
public sendDoSyncOperation(operationId: string, timeout: number): Promise<any> {
122+
public sendDoSyncOperation(operationId: string, timeout: number): Promise<IAndroidLivesyncSyncOperationResult> {
122123
const id = operationId || this.generateOperationIdentifier();
123-
const operationPromise = new Promise((resolve: Function, reject: Function) => {
124+
const operationPromise: Promise<IAndroidLivesyncSyncOperationResult> = new Promise((resolve: Function, reject: Function) => {
124125
this.verifyActiveConnection(reject);
125126

126127
const message = `${DO_SYNC_OPERATION}${id}`;
@@ -328,16 +329,18 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
328329
const errorMessage = infoBuffer.toString();
329330
this.handleSocketError(socketId, errorMessage);
330331
} else if (reportType === OPERATION_END_REPORT) {
331-
this.handleSyncEnd(infoBuffer);
332+
this.handleSyncEnd({data:infoBuffer, didRefresh: true});
333+
} else if (reportType === OPERATION_END_NO_REFRESH_REPORT_CODE) {
334+
this.handleSyncEnd({data:infoBuffer, didRefresh: false});
332335
}
333336
}
334337

335-
private handleSyncEnd(data: any) {
338+
private handleSyncEnd({data, didRefresh}: {data: any, didRefresh: boolean}) {
336339
const operationId = data.toString();
337340
const promiseHandler = this.operationPromises[operationId];
338341

339342
if (promiseHandler) {
340-
promiseHandler.resolve(operationId);
343+
promiseHandler.resolve({operationId, didRefresh});
341344
delete this.operationPromises[operationId];
342345
}
343346
}

0 commit comments

Comments
 (0)