All files / app/service pwa.service.ts

47.61% Statements 10/21
62.5% Branches 5/8
25% Functions 1/4
37.5% Lines 6/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 351x               1x     1x 1x   1x                           1x            
import { Injectable } from '@angular/core';
import { SwUpdate } from '@angular/service-worker';
import { runInAction } from 'mobx';
import { Store } from '../store/store';
 
@Injectable({
  providedIn: 'root'
})
export class PwaService {
 
  constructor(
    private store: Store,
    private updates: SwUpdate,
  ) {
    updates.versionUpdates.subscribe(evt => {
      switch (evt.type) {
        case 'VERSION_DETECTED':
          console.log(`Downloading new app version: ${evt.version.hash}`);
          break;
        case 'VERSION_READY':
          console.log(`Current app version: ${evt.currentVersion.hash}`);
          console.log(`New app version ready for use: ${evt.latestVersion.hash}`);
          break;
        case 'VERSION_INSTALLATION_FAILED':
          console.error(`Failed to install app version '${evt.version.hash}': ${evt.error}`);
          break;
      }
    });
    updates.unrecoverable.subscribe(event => {
      console.error(`Unrecoverable PWA error: ${event.reason}`);
      runInAction(() => store.account.unrecoverable = true);
    });
  }
}