Skip to content

Commit

Permalink
perf(sw): skip the first update check that requires manual interaction (
Browse files Browse the repository at this point in the history
  • Loading branch information
rfprod authored Feb 24, 2024
1 parent e626073 commit c9c2422
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libs/client-service-worker/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config: Config.InitialOptions = {
// TODO: bump unit test coverage and remove this override
global: {
branches: 0,
functions: 16,
functions: 15,
lines: 48,
statements: 48,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DOCUMENT } from '@angular/common';
import { ApplicationRef, Inject, Injectable, NgZone } from '@angular/core';
import { MatSnackBar, MatSnackBarConfig, MatSnackBarRef, TextOnlySnackBar } from '@angular/material/snack-bar';
import { SwUpdate } from '@angular/service-worker';
import { catchError, combineLatest, concat, filter, first, from, interval, map, of, switchMap, tap } from 'rxjs';
import { catchError, combineLatest, concat, defer, filter, first, from, interval, map, of, skip, switchMap, tap } from 'rxjs';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -43,7 +43,6 @@ export class AppServiceWorkerService {
this.displaySnackBar(`Failed to install app version '${event.version.hash}': ${event.error}`);
return null;
case 'VERSION_READY':
this.displaySnackBar(`Current app version: ${event.currentVersion.hash}`);
this.displaySnackBar(`New app version ready for use: ${event.latestVersion.hash}`);
return event;
default:
Expand All @@ -57,19 +56,18 @@ export class AppServiceWorkerService {
* Checks for available update and prompts the user to update the application.
*/
private readonly checkForUpdates$ = concat(this.appStable$, this.updateInterval$).pipe(
switchMap(() => from(this.service.checkForUpdate())),
switchMap(() => from(defer(() => this.service.checkForUpdate()))),
catchError((error: Error) => {
this.displaySnackBar(`Failed to check for updates. ${error.message}`, void 0);
return of(false);
}),
filter(update => update),
skip(1),
tap(() => {
this.displaySnackBar(
'There is an application update available. It is recommended to update to avoid unexpected behavior.',
'Update',
{
duration: Number(Infinity),
},
{ duration: Number(Infinity) },
true,
);
}),
Expand Down

0 comments on commit c9c2422

Please # to comment.