diff --git a/angular.json b/angular.json index cb5b49b6a3f35dddcc00bd1a7da7d560179484f7..37a9618c1f9f6483a26512382e4df302782b1f86 100644 --- a/angular.json +++ b/angular.json @@ -22,6 +22,9 @@ "src/locale", "src/favicon.ico", "src/.htaccess", + "src/cassiopee.webmanifest", + "src/pwabuilder-sw.js", + "src/pwa-offline.html", { "glob": "**/*.json", "input": "src/", @@ -112,6 +115,9 @@ "assets": [ "src/assets", "src/favicon.ico", + "src/cassiopee.webmanifest", + "src/pwabuilder-sw.js", + "src/pwa-offline.html", "src/**/*.json", "src/**/*.md", "src/**/*.png" diff --git a/jalhyd_branch b/jalhyd_branch index f95555f7a46d0099a962879fa5b1ec791ca252ee..d64531f1305e091791eac674c3a36d86b9e17ddd 100644 --- a/jalhyd_branch +++ b/jalhyd_branch @@ -1 +1 @@ -204-ajout-de-la-fonctionnalite-respect-des-criteres-2 +devel diff --git a/src/cassiopee.webmanifest b/src/cassiopee.webmanifest new file mode 100644 index 0000000000000000000000000000000000000000..b7666d28d67c84209635cdc15364b453f59ad682 --- /dev/null +++ b/src/cassiopee.webmanifest @@ -0,0 +1,31 @@ +{ + "name": "Cassiopée", + "short_name": "cassiopee", + "description": "Hydraulic calculators", + "icons": [ + { + "src": "assets/icons/favicon-16x16.png", + "sizes": "16x16", + "type": "image/png" + }, + { + "src": "assets/icons/favicon-32x32.png", + "sizes": "32x32", + "type": "image/png" + }, + { + "src": "assets/icons/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "assets/icons/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "start_url": "index.html", + "display": "fullscreen", + "theme_color": "#003A80", + "background_color": "#003A80" +} diff --git a/src/index.html b/src/index.html index 24fc414e26f12665c3ac6a32851b93ac0a8cf0a7..96d25eb9231673bb9b7c168f4d44bd5e6c1602d5 100644 --- a/src/index.html +++ b/src/index.html @@ -13,6 +13,9 @@ <link rel="icon" type="image/png" sizes="16x16" href="assets/icons/favicon-16x16.png"> <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#ffffff"> + <link rel="manifest" href="cassiopee.webmanifest"> + <meta name="theme-color" content="#003A80"> + <meta name="viewport" content="width=device-width, initial-scale=1"> </head> @@ -282,6 +285,18 @@ } </script> + <script type="module"> + /* + This code uses the pwa-update web component https://github.com/pwa-builder/pwa-update to register your service worker, + tell the user when there is an update available and let the user know when your PWA is ready to use offline. + */ + import 'https://cdn.jsdelivr.net/npm/@pwabuilder/pwaupdate'; + + // généré par https://www.pwabuilder.com/serviceworker le 2020-09-02 + const el = document.createElement('pwa-update'); + document.body.appendChild(el); + </script> + </body> </html> \ No newline at end of file diff --git a/src/pwa-offline.html b/src/pwa-offline.html new file mode 100644 index 0000000000000000000000000000000000000000..987f857cd539223b5f3f7a640209df4477e96919 --- /dev/null +++ b/src/pwa-offline.html @@ -0,0 +1,8 @@ +<html> + <head> + <meta charset="utf-8"> + </head> + <body> + <h1>Network is required to use Cassiopée</h1> + </body> +</html> \ No newline at end of file diff --git a/src/pwabuilder-sw.js b/src/pwabuilder-sw.js new file mode 100644 index 0000000000000000000000000000000000000000..797a10ec0b49a53363f37992239bf9bf02b6e2fa --- /dev/null +++ b/src/pwabuilder-sw.js @@ -0,0 +1,48 @@ +// This is the "Offline page" service worker +// généré par https://www.pwabuilder.com/serviceworker le 2020-09-02 + +importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.0.0/workbox-sw.js'); + +const CACHE = "cassiopee-pwa"; + +// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html"; +const offlineFallbackPage = "pwa-offline.html"; + +self.addEventListener("message", (event) => { + if (event.data && event.data.type === "SKIP_WAITING") { + self.skipWaiting(); + } +}); + +self.addEventListener('install', async (event) => { + event.waitUntil( + caches.open(CACHE) + .then((cache) => cache.add(offlineFallbackPage)) + ); +}); + +if (workbox.navigationPreload.isSupported()) { + workbox.navigationPreload.enable(); +} + +self.addEventListener('fetch', (event) => { + if (event.request.mode === 'navigate') { + event.respondWith((async () => { + try { + const preloadResp = await event.preloadResponse; + + if (preloadResp) { + return preloadResp; + } + + const networkResp = await fetch(event.request); + return networkResp; + } catch (error) { + + const cache = await caches.open(CACHE); + const cachedResp = await cache.match(offlineFallbackPage); + return cachedResp; + } + })()); + } +});