@@ -231,21 +231,31 @@ export class CoreClientProvider {
231
231
) : Promise < CoreClientProvider . Client > {
232
232
const progressId = v4 ( ) ;
233
233
// 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`.
235
235
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 ;
237
245
let work = {
238
246
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.
240
248
} ;
241
- let lastMessage = '' ;
242
- const reportProgress = ( ) => {
249
+ const reportProgress = ( {
250
+ progressId,
251
+ message,
252
+ } : Omit < ProgressMessage , 'work' > ) => {
243
253
work = {
244
254
...work ,
245
255
done : work . done + 1 ,
246
256
} ;
247
257
this . notificationService . notifyIndexUpdateDidProgress ( {
248
- message : lastMessage ,
258
+ message,
249
259
progressId,
250
260
work,
251
261
} ) ;
@@ -256,21 +266,13 @@ export class CoreClientProvider {
256
266
const onDidProgress = onDidProgressEmitter . event ;
257
267
toDispose . pushAll ( [
258
268
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
+ ) ,
266
272
] ) ;
267
273
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 ) ,
274
276
] ) ;
275
277
this . notificationService . notifyIndexDidUpdate ( progressId ) ;
276
278
return client ;
@@ -290,7 +292,8 @@ export class CoreClientProvider {
290
292
new UpdateIndexRequest ( ) . setInstance ( client . instance )
291
293
) ,
292
294
progressId ,
293
- onDidProgressEmitter
295
+ onDidProgressEmitter ,
296
+ 'platform-index'
294
297
) ;
295
298
}
296
299
@@ -305,7 +308,8 @@ export class CoreClientProvider {
305
308
new UpdateLibrariesIndexRequest ( ) . setInstance ( client . instance )
306
309
) ,
307
310
progressId ,
308
- onDidProgressEmitter
311
+ onDidProgressEmitter ,
312
+ 'library-index'
309
313
) ;
310
314
}
311
315
@@ -317,7 +321,8 @@ export class CoreClientProvider {
317
321
> (
318
322
responseProvider : ( ) => grpc . ClientReadableStream < R > ,
319
323
progressId : string ,
320
- onDidProgressEmitter : Emitter < ProgressMessage >
324
+ onDidProgressEmitter : Emitter < ProgressMessage > ,
325
+ task ?: string
321
326
) : Promise < void > {
322
327
return retry (
323
328
( ) =>
@@ -328,7 +333,10 @@ export class CoreClientProvider {
328
333
InstallWithProgress . createDataCallback ( {
329
334
responseService : {
330
335
appendToOutput : ( message ) => {
331
- console . log ( 'core-client-provider' , message . chunk ) ;
336
+ console . log (
337
+ `core-client-provider${ task ? ` [${ task } ]` : '' } ` ,
338
+ message . chunk
339
+ ) ;
332
340
onDidProgressEmitter . fire ( {
333
341
message : message . chunk ,
334
342
progressId,
0 commit comments