Browse Source

Add pwa functionality to application

Helmut Pozimski 11 months ago
parent
commit
336975811c

+ 7 - 3
angular.json

@@ -22,13 +22,16 @@
             "tsConfig": "tsconfig.app.json",
             "assets": [
               "src/favicon.ico",
-              "src/assets"
+              "src/assets",
+              "src/manifest.webmanifest"
             ],
             "styles": [
               "src/styles.css",
               "@angular/material/prebuilt-themes/indigo-pink.css"
             ],
-            "scripts": []
+            "scripts": [],
+            "serviceWorker": true,
+            "ngswConfigPath": "ngsw-config.json"
           },
           "configurations": {
             "production": {
@@ -91,7 +94,8 @@
             "tsConfig": "tsconfig.spec.json",
             "assets": [
               "src/favicon.ico",
-              "src/assets"
+              "src/assets",
+              "src/manifest.webmanifest"
             ],
             "styles": [
               "@angular/material/prebuilt-themes/indigo-pink.css",

+ 30 - 0
ngsw-config.json

@@ -0,0 +1,30 @@
+{
+  "$schema": "./node_modules/@angular/service-worker/config/schema.json",
+  "index": "/index.html",
+  "assetGroups": [
+    {
+      "name": "app",
+      "installMode": "prefetch",
+      "resources": {
+        "files": [
+          "/favicon.ico",
+          "/index.html",
+          "/manifest.webmanifest",
+          "/*.css",
+          "/*.js"
+        ]
+      }
+    },
+    {
+      "name": "assets",
+      "installMode": "lazy",
+      "updateMode": "prefetch",
+      "resources": {
+        "files": [
+          "/assets/**",
+          "/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
+        ]
+      }
+    }
+  ]
+}

+ 19 - 0
package-lock.json

@@ -18,6 +18,7 @@
         "@angular/platform-browser": "^16.0.4",
         "@angular/platform-browser-dynamic": "^16.0.4",
         "@angular/router": "^16.0.4",
+        "@angular/service-worker": "^16.0.4",
         "@types/lodash": "^4.14.191",
         "ngx-mat-timepicker": "^16.0.0",
         "rxjs": "~7.8.0",
@@ -1211,6 +1212,24 @@
         "rxjs": "^6.5.3 || ^7.4.0"
       }
     },
+    "node_modules/@angular/service-worker": {
+      "version": "16.0.4",
+      "resolved": "https://registry.npmjs.org/@angular/service-worker/-/service-worker-16.0.4.tgz",
+      "integrity": "sha512-acTdQ9hFUh0eCf8sg1zc5IdzNaBgQdzvSg1QKTqeKoUEjCqY/Wyycn/tx2HydlnWMY4fLaaNO+zuqJbJ2BqxBA==",
+      "dependencies": {
+        "tslib": "^2.3.0"
+      },
+      "bin": {
+        "ngsw-config": "ngsw-config.js"
+      },
+      "engines": {
+        "node": "^16.14.0 || >=18.10.0"
+      },
+      "peerDependencies": {
+        "@angular/common": "16.0.4",
+        "@angular/core": "16.0.4"
+      }
+    },
     "node_modules/@assemblyscript/loader": {
       "version": "0.10.1",
       "resolved": "https://registry.npmjs.org/@assemblyscript/loader/-/loader-0.10.1.tgz",

+ 1 - 0
package.json

@@ -21,6 +21,7 @@
     "@angular/platform-browser": "^16.0.4",
     "@angular/platform-browser-dynamic": "^16.0.4",
     "@angular/router": "^16.0.4",
+    "@angular/service-worker": "^16.0.4",
     "@types/lodash": "^4.14.191",
     "ngx-mat-timepicker": "^16.0.0",
     "rxjs": "~7.8.0",

+ 9 - 2
src/app/app.module.ts

@@ -1,4 +1,4 @@
-import {NgModule} from '@angular/core';
+import {NgModule, isDevMode} from '@angular/core';
 import {BrowserModule} from '@angular/platform-browser';
 
 import {AppComponent} from './app.component';
@@ -19,6 +19,7 @@ import {WeekdaysViewComponent} from './weekdays-view/weekdays-view.component';
 import {WeekdayEntryComponent} from './weekday-entry/weekday-entry.component';
 import {RouterModule} from "@angular/router";
 import {ErrorAlertDialogComponent} from './error-alert-dialog/error-alert-dialog.component';
+import { ServiceWorkerModule } from '@angular/service-worker';
 
 @NgModule({
   declarations: [
@@ -42,7 +43,13 @@ import {ErrorAlertDialogComponent} from './error-alert-dialog/error-alert-dialog
     MatToolbarModule,
     MatIconModule,
     MatButtonModule,
-    RouterModule
+    RouterModule,
+    ServiceWorkerModule.register('ngsw-worker.js', {
+      enabled: !isDevMode(),
+      // Register the ServiceWorker as soon as the application is stable
+      // or after 30 seconds (whichever comes first).
+      registrationStrategy: 'registerWhenStable:30000'
+    })
   ],
   providers: [],
   bootstrap: [AppComponent]

BIN
src/assets/icons/icon-128x128.png


BIN
src/assets/icons/icon-144x144.png


BIN
src/assets/icons/icon-152x152.png


BIN
src/assets/icons/icon-192x192.png


BIN
src/assets/icons/icon-384x384.png


BIN
src/assets/icons/icon-512x512.png


BIN
src/assets/icons/icon-72x72.png


BIN
src/assets/icons/icon-96x96.png


+ 3 - 0
src/index.html

@@ -8,8 +8,11 @@
   <link rel="icon" type="image/x-icon" href="favicon.ico">
   <link href="assets/roboto_300_400_500.css" rel="stylesheet">
   <link href="assets/material_icons.css" rel="stylesheet">
+  <link rel="manifest" href="manifest.webmanifest">
+  <meta name="theme-color" content="#1976d2">
 </head>
 <body class="mat-typography">
   <app-root></app-root>
+  <noscript>Please enable JavaScript to continue using this application.</noscript>
 </body>
 </html>

+ 59 - 0
src/manifest.webmanifest

@@ -0,0 +1,59 @@
+{
+  "name": "angular-alarm-clock-configurator",
+  "short_name": "angular-alarm-clock-configurator",
+  "theme_color": "#1976d2",
+  "background_color": "#fafafa",
+  "display": "standalone",
+  "scope": "./",
+  "start_url": "./",
+  "icons": [
+    {
+      "src": "assets/icons/icon-72x72.png",
+      "sizes": "72x72",
+      "type": "image/png",
+      "purpose": "maskable any"
+    },
+    {
+      "src": "assets/icons/icon-96x96.png",
+      "sizes": "96x96",
+      "type": "image/png",
+      "purpose": "maskable any"
+    },
+    {
+      "src": "assets/icons/icon-128x128.png",
+      "sizes": "128x128",
+      "type": "image/png",
+      "purpose": "maskable any"
+    },
+    {
+      "src": "assets/icons/icon-144x144.png",
+      "sizes": "144x144",
+      "type": "image/png",
+      "purpose": "maskable any"
+    },
+    {
+      "src": "assets/icons/icon-152x152.png",
+      "sizes": "152x152",
+      "type": "image/png",
+      "purpose": "maskable any"
+    },
+    {
+      "src": "assets/icons/icon-192x192.png",
+      "sizes": "192x192",
+      "type": "image/png",
+      "purpose": "maskable any"
+    },
+    {
+      "src": "assets/icons/icon-384x384.png",
+      "sizes": "384x384",
+      "type": "image/png",
+      "purpose": "maskable any"
+    },
+    {
+      "src": "assets/icons/icon-512x512.png",
+      "sizes": "512x512",
+      "type": "image/png",
+      "purpose": "maskable any"
+    }
+  ]
+}