Update Service

class UpdateService

This service is a wrapper for communicating with SwUpdate, which manages service worker updates.

It:

  1. Subscribes to service worker updates and alerts if an update is found or ready.

  2. Checks for service worker updates when requested.

  3. Emits the last update check timestamp.

Recipe: Integrate this service with a back-end service that returns the latest version available and the minimum supported version, to encourage users to update or to force users to update respectively.

update.service.ts
@Injectable({
  providedIn: 'root',
})
export class UpdateService {
  private readonly _swUpdate = inject(SwUpdate);
  private readonly _translocoService = inject(TranslocoService);
  private readonly _alertService = inject(AlertService);
  private readonly _loggerService = inject(LoggerService);
  private readonly _storageService = inject(StorageService);

  private _isReloadPending: boolean;
  private readonly _lastUpdateCheckTimestamp: WritableSignal<string>;

  public readonly swUpdateSubscription: Subscription;

  public constructor() {
    // Buy to unlock
  }

  public get lastUpdateCheckTimestamp(): Signal<string> {
    // Buy to unlock
  }

  public checkForUpdate(): void {
    // Buy to unlock
  }

  private _resetLastUpdateCheckTimestamp(): void {
    // Buy to unlock
  }

  private _subscribeToUpdates(): Subscription {
    // Buy to unlock
  }
}

Last updated