@propmix/app-update-handler
v1.0.0
Published
An Angular library that automatically detects and notifies users when a new version of your application is available using Angular Service Worker.
Keywords
Readme
Propmix Update Handler
An Angular library that automatically detects and notifies users when a new version of your application is available using Angular Service Worker.
How It Works
- Initialization - Starts periodic update checks via
APP_INITIALIZER - Detection - Uses
SwUpdate.checkForUpdate()at configured intervals (default: 5 minutes) - Notification - Shows Material overlay dialog when new version is available
- Update - User can choose "Update & Refresh" or "Ignore"
- Error Handling - Detects chunk-load errors and prompts for update
Installation
npm install @propmix/app-update-handlerNote: The following steps must be completed in your parent application that uses this library.
Setup Parent Application
Enable Service Worker:
ng add @angular/pwaUpdate
ngsw-config.json: Add"navigationRequestStrategy": "freshness"to enable update detection:{ "index": "/index.html", "navigationRequestStrategy": "freshness", ... }Clean up unwanted files and configs
Remove Unwanted PWA Files: Since we're using Service Worker for app updates only (not PWA functionality), remove these files:
# Remove PWA-specific files src/assets/icons/ src/manifest.webmanifestAlso remove references in
angular.json:- Remove the
manifest.webmanifestentry fromassetsarray - Remove any PWA-related configuration
- Remove the
And remove from
index.html:- Remove
<link rel="manifest" href="manifest.webmanifest"> - Remove
<meta name="theme-color" content="..."> - Remove
<link rel="icon" type="image/x-icon" href="...">
- Remove
Update App Module
Add this to your app's
app.module.tsimport { provideAppUpdateHandler } from '@propmix/app-update-handler'; @NgModule({ providers: [ provideAppUpdateHandler(), // Optionally pass `checkInterval` in minutes ], }) export class AppModule {}
API Reference
provideAppUpdateHandler(config?: AppUpdateHandlerProviderConfig)
Configuration Options:
| Option | Type | Default | Description | | ------------- | ------ | ------- | ----------------------------- | | checkInterval | number | 5 | Check interval in minutes |
Dependencies
@angular/service-worker(viang add @angular/pwa)@angular/material- For notification UI@angular/cdk- For overlay portal
