Skip to content

Commit 4231500

Browse files
committed
fix: unnecessary refresh before restart
1 parent f81fc16 commit 4231500

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

lib/definitions/livesync.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,12 @@ interface IAndroidLivesyncTool {
420420
removeFiles(filePaths: string[]): Promise<boolean[]>;
421421
/**
422422
* Sends doSyncOperation that will be handled by the runtime.
423+
* @param doRefresh - Indicates if the application should be restarted. Defaults to true.
423424
* @param operationId - The identifier of the operation
424425
* @param timeout - The timeout in milliseconds
425426
* @returns {Promise<void>}
426427
*/
427-
sendDoSyncOperation(operationId: string, timeout?: number): Promise<IAndroidLivesyncSyncOperationResult>;
428+
sendDoSyncOperation(doRefresh: boolean, timeout?: number, operationId?: string): Promise<IAndroidLivesyncSyncOperationResult>;
428429
/**
429430
* Generates new operation identifier.
430431
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
3535

3636
if (liveSyncInfo.modifiedFilesData.length) {
3737
const operationIdentifier = this.livesyncTool.generateOperationIdentifier();
38-
const doSyncPromise = this.livesyncTool.sendDoSyncOperation(operationIdentifier);
38+
39+
const doSyncPromise = this.livesyncTool.sendDoSyncOperation(canExecuteFastSync, null, operationIdentifier);
3940

4041
const syncInterval : NodeJS.Timer = setInterval(() => {
4142
if (this.livesyncTool.isOperationInProgress(operationIdentifier)) {

lib/services/livesync/android-livesync-tool.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,19 @@ When called, sendDoSyncOperation will tell the runtime to execute a script that
155155
* Definition
156156
```TypeScript
157157
/**
158-
* Sends doSyncOperation that will be handeled by the runtime.
158+
* Sends doSyncOperation that will be handled by the runtime.
159+
* @param doRefresh - Indicates if the application should be restarted. Defaults to true.
159160
* @param operationId - The identifier of the operation
160-
* @param timeout - The timeout in miliseconds
161+
* @param timeout - The timeout in milliseconds
161162
* @returns {Promise<void>}
162163
*/
163-
sendDoSyncOperation(operationId: string, timeout?: number): Promise<void>;
164+
sendDoSyncOperation(doRefresh: boolean, timeout?: number, operationId?: string): Promise<IAndroidLivesyncSyncOperationResult>;
164165
```
165166

166167
* Example:
167168
```JavaScript
168169
const operationId = liveSyncTool.generateOperationIdentifier();
169-
await liveSyncTool.sendDoSyncOperation(operationId);
170+
await liveSyncTool.sendDoSyncOperation(true, 10000, operationId);
170171
```
171172

172173
### Calling end

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const ERROR_REPORT = 1;
1212
const OPERATION_END_REPORT = 2;
1313
const OPERATION_END_NO_REFRESH_REPORT_CODE = 3;
1414
const REPORT_LENGTH = 1;
15+
const DO_REFRESH_LENGTH = 1;
16+
const DO_REFRESH = 1;
17+
const SKIP_REFRESH = 0;
1518
const SYNC_OPERATION_TIMEOUT = 60000;
1619
const TRY_CONNECT_TIMEOUT = 30000;
1720
const DEFAULT_LOCAL_HOST_ADDRESS = "127.0.0.1";
@@ -119,29 +122,34 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
119122
return !!this.operationPromises[operationId];
120123
}
121124

122-
public sendDoSyncOperation(operationId: string, timeout: number): Promise<IAndroidLivesyncSyncOperationResult> {
125+
public sendDoSyncOperation(doRefresh = true , timeout?: number, operationId?: string): Promise<IAndroidLivesyncSyncOperationResult> {
123126
const id = operationId || this.generateOperationIdentifier();
124127
const operationPromise: Promise<IAndroidLivesyncSyncOperationResult> = new Promise((resolve: Function, reject: Function) => {
125128
this.verifyActiveConnection(reject);
126-
127129
const message = `${DO_SYNC_OPERATION}${id}`;
130+
const headerBuffer = Buffer.alloc(Buffer.byteLength(message) + DO_REFRESH_LENGTH);
128131
const socketId = this.socketConnection.uid;
129-
const hash = crypto.createHash("md5").update(message).digest();
132+
const doRefreshCode = doRefresh ? DO_REFRESH : SKIP_REFRESH;
133+
const offset = headerBuffer.write(message);
134+
135+
headerBuffer.writeUInt8(doRefreshCode, offset);
136+
const hash = crypto.createHash("md5").update(headerBuffer).digest();
130137

131138
this.operationPromises[id] = {
132139
resolve,
133140
reject,
134141
socketId
135142
};
136143

137-
this.socketConnection.write(message);
144+
this.socketConnection.write(headerBuffer);
138145
this.socketConnection.write(hash);
139146

147+
timeout = timeout || SYNC_OPERATION_TIMEOUT;
140148
setTimeout(() => {
141149
if (this.isOperationInProgress(id)) {
142150
this.handleSocketError(socketId, "Sync operation is taking too long");
143151
}
144-
}, SYNC_OPERATION_TIMEOUT);
152+
}, timeout);
145153
});
146154

147155
return operationPromise;

0 commit comments

Comments
 (0)