@@ -50,6 +50,7 @@ import {
50
50
fetchHassioBoots ,
51
51
fetchHassioLogs ,
52
52
fetchHassioLogsFollow ,
53
+ fetchHassioLogsFollowSkip ,
53
54
fetchHassioLogsLegacy ,
54
55
getHassioLogDownloadLinesUrl ,
55
56
getHassioLogDownloadUrl ,
@@ -428,46 +429,66 @@ class ErrorLogCard extends LitElement {
428
429
}
429
430
}
430
431
431
- private async _loadLogs ( ) : Promise < void > {
432
+ private async _loadLogs ( retry = false ) : Promise < void > {
432
433
this . _error = undefined ;
433
434
this . _loadingState = "loading" ;
434
- this . _loadingPrevState = undefined ;
435
- this . _firstCursor = undefined ;
436
- this . _numberOfLines = 0 ;
437
- this . _ansiToHtmlElement ?. clear ( ) ;
435
+ this . _numberOfLines = retry ? ( this . _numberOfLines ?? 0 ) : 0 ;
436
+
437
+ if ( ! retry ) {
438
+ this . _loadingPrevState = undefined ;
439
+ this . _firstCursor = undefined ;
440
+ this . _ansiToHtmlElement ?. clear ( ) ;
441
+ }
442
+
443
+ const streamLogs =
444
+ this . _streamSupported &&
445
+ isComponentLoaded ( this . hass , "hassio" ) &&
446
+ this . provider ;
438
447
439
448
try {
440
449
if ( this . _logStreamAborter ) {
441
450
this . _logStreamAborter . abort ( ) ;
442
451
this . _logStreamAborter = undefined ;
443
452
}
444
453
445
- if (
446
- this . _streamSupported &&
447
- isComponentLoaded ( this . hass , "hassio" ) &&
448
- this . provider
449
- ) {
454
+ if ( streamLogs ) {
450
455
this . _logStreamAborter = new AbortController ( ) ;
451
456
452
- // check if there are any logs at all
453
- const testResponse = await fetchHassioLogs (
454
- this . hass ,
455
- this . provider ,
456
- `entries=:-1:` ,
457
- this . _boot
458
- ) ;
459
- const testLogs = await testResponse . text ( ) ;
460
- if ( ! testLogs . trim ( ) ) {
461
- this . _loadingState = "empty" ;
457
+ if ( ! retry ) {
458
+ // check if there are any logs at all
459
+ const testResponse = await fetchHassioLogs (
460
+ this . hass ,
461
+ this . provider ! ,
462
+ `entries=:-1:` ,
463
+ this . _boot
464
+ ) ;
465
+ const testLogs = await testResponse . text ( ) ;
466
+ if ( ! testLogs . trim ( ) ) {
467
+ this . _loadingState = "empty" ;
468
+ }
462
469
}
463
470
464
- const response = await fetchHassioLogsFollow (
465
- this . hass ,
466
- this . provider ,
467
- this . _logStreamAborter . signal ,
468
- NUMBER_OF_LINES ,
469
- this . _boot
470
- ) ;
471
+ let response : Response ;
472
+
473
+ if ( retry && this . _firstCursor ) {
474
+ response = await fetchHassioLogsFollowSkip (
475
+ this . hass ,
476
+ this . provider ! ,
477
+ this . _logStreamAborter . signal ,
478
+ this . _firstCursor ,
479
+ this . _numberOfLines ,
480
+ NUMBER_OF_LINES ,
481
+ this . _boot
482
+ ) ;
483
+ } else {
484
+ response = await fetchHassioLogsFollow (
485
+ this . hass ,
486
+ this . provider ! ,
487
+ this . _logStreamAborter . signal ,
488
+ NUMBER_OF_LINES ,
489
+ this . _boot
490
+ ) ;
491
+ }
471
492
472
493
if ( response . headers . has ( "X-First-Cursor" ) ) {
473
494
this . _firstCursor = response . headers . get ( "X-First-Cursor" ) ! ;
@@ -524,14 +545,17 @@ class ErrorLogCard extends LitElement {
524
545
525
546
if ( ! this . _downloadSupported ) {
526
547
const downloadUrl = getHassioLogDownloadLinesUrl (
527
- this . provider ,
548
+ this . provider ! ,
528
549
this . _numberOfLines ,
529
550
this . _boot
530
551
) ;
531
552
getSignedPath ( this . hass , downloadUrl ) . then ( ( signedUrl ) => {
532
553
this . _logsFileLink = signedUrl . path ;
533
554
} ) ;
534
555
}
556
+
557
+ // first chunk loads successfully, reset retry param
558
+ retry = false ;
535
559
}
536
560
}
537
561
} else {
@@ -554,6 +578,13 @@ class ErrorLogCard extends LitElement {
554
578
if ( err . name === "AbortError" ) {
555
579
return ;
556
580
}
581
+
582
+ // The stream can fail if the connection is lost or firefox service worker intercept the connection
583
+ if ( ! retry && streamLogs ) {
584
+ this . _loadLogs ( true ) ;
585
+ return ;
586
+ }
587
+
557
588
this . _error = ( this . localizeFunc || this . hass . localize ) (
558
589
"ui.panel.config.logs.failed_get_logs" ,
559
590
{
@@ -590,9 +621,10 @@ class ErrorLogCard extends LitElement {
590
621
private _handleConnectionStatus = ( ev : HASSDomEvent < ConnectionStatus > ) => {
591
622
if ( ev . detail === "disconnected" && this . _logStreamAborter ) {
592
623
this . _logStreamAborter . abort ( ) ;
624
+ this . _loadingState = "loading" ;
593
625
}
594
626
if ( ev . detail === "connected" ) {
595
- this . _loadLogs ( ) ;
627
+ this . _loadLogs ( true ) ;
596
628
}
597
629
} ;
598
630
0 commit comments