Skip to content

Commit 8daf0ab

Browse files
author
Akos Kitta
committed
faked the fine grained index update progress.
Signed-off-by: Akos Kitta <[email protected]>
1 parent bdc4a53 commit 8daf0ab

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

arduino-ide-extension/src/node/core-client-provider.ts

+31-23
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,31 @@ export class CoreClientProvider {
231231
): Promise<CoreClientProvider.Client> {
232232
const progressId = v4();
233233
// Note: at this point, the IDE2 backend might not have any connected clients, so this notification is not delivered to anywhere
234-
// Hence, clients must handle gracefully when no `willUpdate` is received only `didProgress`.
234+
// Hence, clients must handle gracefully when no `willUpdate` is received before any `didProgress`.
235235
this.notificationService.notifyIndexWillUpdate(progressId);
236-
236+
// The index update progress responses are not much helpful from the CLI. They cannot provide a fine-grain progress.
237+
// So IDE2 could report two total works only: index update and library index update.
238+
// See here an example: https://github.com/arduino/arduino-ide/issues/906#issuecomment-1171145630
239+
// Due to this, IDE2 fakes the progress to provide slightly better UX.
240+
const totalPlatformIndexCount =
241+
(this.configService.cliConfiguration?.board_manager?.additional_urls
242+
?.length ?? 0) + 1; // +1 for the `package_index.tar.bz2` when updating the platform index.
243+
// The `library_index.json.gz` and `library_index.json.sig` when running the library index update.
244+
const totalLibraryIndexCount = 2;
237245
let work = {
238246
done: 0,
239-
total: 2, // index update and library index update
247+
total: totalPlatformIndexCount + totalLibraryIndexCount + 1, // +1 for better UX, leave the last step complete when all subtasks are done.
240248
};
241-
let lastMessage = '';
242-
const reportProgress = () => {
249+
const reportProgress = ({
250+
progressId,
251+
message,
252+
}: Omit<ProgressMessage, 'work'>) => {
243253
work = {
244254
...work,
245255
done: work.done + 1,
246256
};
247257
this.notificationService.notifyIndexUpdateDidProgress({
248-
message: lastMessage,
258+
message,
249259
progressId,
250260
work,
251261
});
@@ -256,21 +266,13 @@ export class CoreClientProvider {
256266
const onDidProgress = onDidProgressEmitter.event;
257267
toDispose.pushAll([
258268
onDidProgressEmitter,
259-
onDidProgress(({ message, progressId }) => {
260-
this.notificationService.notifyIndexUpdateDidProgress({
261-
message,
262-
progressId,
263-
});
264-
lastMessage = message;
265-
}),
269+
onDidProgress(({ message, progressId }) =>
270+
reportProgress({ progressId, message })
271+
),
266272
]);
267273
await Promise.all([
268-
this.updateIndex(client, progressId, onDidProgressEmitter).then(
269-
reportProgress
270-
),
271-
this.updateLibraryIndex(client, progressId, onDidProgressEmitter).then(
272-
reportProgress
273-
),
274+
this.updateIndex(client, progressId, onDidProgressEmitter),
275+
this.updateLibraryIndex(client, progressId, onDidProgressEmitter),
274276
]);
275277
this.notificationService.notifyIndexDidUpdate(progressId);
276278
return client;
@@ -290,7 +292,8 @@ export class CoreClientProvider {
290292
new UpdateIndexRequest().setInstance(client.instance)
291293
),
292294
progressId,
293-
onDidProgressEmitter
295+
onDidProgressEmitter,
296+
'platform-index'
294297
);
295298
}
296299

@@ -305,7 +308,8 @@ export class CoreClientProvider {
305308
new UpdateLibrariesIndexRequest().setInstance(client.instance)
306309
),
307310
progressId,
308-
onDidProgressEmitter
311+
onDidProgressEmitter,
312+
'library-index'
309313
);
310314
}
311315

@@ -317,7 +321,8 @@ export class CoreClientProvider {
317321
>(
318322
responseProvider: () => grpc.ClientReadableStream<R>,
319323
progressId: string,
320-
onDidProgressEmitter: Emitter<ProgressMessage>
324+
onDidProgressEmitter: Emitter<ProgressMessage>,
325+
task?: string
321326
): Promise<void> {
322327
return retry(
323328
() =>
@@ -328,7 +333,10 @@ export class CoreClientProvider {
328333
InstallWithProgress.createDataCallback({
329334
responseService: {
330335
appendToOutput: (message) => {
331-
console.log('core-client-provider', message.chunk);
336+
console.log(
337+
`core-client-provider${task ? ` [${task}]` : ''}`,
338+
message.chunk
339+
);
332340
onDidProgressEmitter.fire({
333341
message: message.chunk,
334342
progressId,

0 commit comments

Comments
 (0)