- fixed problema sull'aggiornamento del service-worker, con iPhone (e non solo) compariva schermata bianca.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="13"
|
||||
DIRECTORY_LOCAL="newfreeplanet"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="13"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="18"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="17"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="18"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="17"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
APP_VERSION="1.0.37"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker_1.0.39.js"
|
||||
APP_ID="13"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
DIRECTORY_SERVER=/var/www/testriso.freeplanet_serverside
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="13"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="13"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="15"
|
||||
DIRECTORY_LOCAL="newfreeplanet"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="15"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "fioredellavita",
|
||||
"version": "0.6.1",
|
||||
"version": "1.0.43",
|
||||
"description": "Fiore Della Vita",
|
||||
"productName": "Fiore Della Vita",
|
||||
"author": "Paolo Arena",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="18"
|
||||
DIRECTORY_LOCAL="newfreeplanet"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="16"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gruppomacro",
|
||||
"version": "0.6.1",
|
||||
"version": "1.0.43",
|
||||
"description": "Gruppo Macro Editori",
|
||||
"productName": "Gruppo Macro",
|
||||
"author": "Paolo Arena",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="17"
|
||||
DIRECTORY_LOCAL="newfreeplanet"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="13"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="13"
|
||||
DIRECTORY_LOCAL="newfreeplanet"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="13"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="16"
|
||||
DIRECTORY_LOCAL=newfreeplanet
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "riso",
|
||||
"version": "0.6.1",
|
||||
"version": "1.0.43",
|
||||
"description": "Siamo la Rete Italiana di Scambio Orizzontale, abbiamo creato questa piattaforma per metterla al servizio di chi vuole riscoprire il valore della condivisione e della cooperazione. Valori semplici e profondi che ci aiutano a ritrovare il Senso della Vita, perduto in questa società consumista, e riporti quei Sani Pricìpi Naturali ed Umani di Fratellanza che intere popolazioni antiche conoscevano bene.",
|
||||
"productName": "Riso",
|
||||
"author": "Paolo Arena",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
APP_VERSION="1.0.37"
|
||||
APP_VERSION="1.0.43"
|
||||
SERVICE_WORKER_FILE="service-worker.js"
|
||||
APP_ID="14"
|
||||
DIRECTORY_LOCAL="newfreeplanet"
|
||||
|
||||
@@ -19,7 +19,7 @@ npm run buildpwa
|
||||
|
||||
echo "Sincronizzazione $SERVERDIR_WEBSITE in remoto..."
|
||||
sshpass -p $SERVERPW_WEBSITE rsync -e 'ssh -p 8855' -a --exclude 'upload' dist/pwa/ suryapaolo@servereng:/var/www/$SERVERDIR_WEBSITE/
|
||||
sshpass -p $SERVERPW_WEBSITE rsync -e 'ssh -p 8855' dist/pwa/index.html suryapaolo@servereng:/var/www/$SERVERDIR_WEBSITE/
|
||||
rsync -e 'ssh -p 8855' -av --delete dist/pwa/js/ suryapaolo@servereng:/var/www/$SERVERDIR_WEBSITE/js
|
||||
|
||||
cp .env.prod.bak .env.production
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ npm run buildpwa
|
||||
|
||||
echo "Sincronizzazione $SERVERDIR_WEBSITE in remoto..."
|
||||
rsync -e 'ssh -p 8822' -a dist/pwa/ pcbuser@pcb:$SERVERDIR_WEBSITE
|
||||
rsync -e 'ssh -p 8822' -av --delete dist/pwa/js/ pcbuser@pcb:$SERVERDIR_WEBSITE/js
|
||||
|
||||
cp .env.prod.bak .env.production
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ npm run buildpwa
|
||||
|
||||
echo "Sincronizzazione $SERVERDIR_WEBSITE in remoto..."
|
||||
rsync -e 'ssh -p 8822' -a dist/pwa/ pcbuser@pcb:$SERVERDIR_WEBSITE
|
||||
rsync -e 'ssh -p 8822' -av --delete dist/pwa/js/ pcbuser@pcb:$SERVERDIR_WEBSITE/js
|
||||
|
||||
cp .env.prod.bak .env.production
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ npm run buildpwa
|
||||
|
||||
echo "Sincronizzazione $SERVERDIR_WEBSITE in remoto..."
|
||||
sshpass -p $SERVERPW_WEBSITE rsync -e 'ssh -p 8855' -a --exclude 'upload' dist/pwa/ ftpadmin@servereng:/var/www/$SERVERDIR_WEBSITE/
|
||||
rsync -e 'ssh -p 8855' -av --delete dist/pwa/js/ ftpadmin@servereng:/var/www/$SERVERDIR_WEBSITE/js
|
||||
|
||||
cp .env.prod.bak .env.production
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ npm run buildpwa
|
||||
|
||||
echo "Sincronizzazione $SERVERDIR_WEBSITE in remoto..."
|
||||
rsync -e 'ssh -p 8822' -a dist/pwa/ pcbuser@pcb:$SERVERDIR_WEBSITE
|
||||
rsync -e 'ssh -p 8822' -av --delete dist/pwa/js/ pcbuser@pcb:$SERVERDIR_WEBSITE/js
|
||||
|
||||
cp .env.prod.bak .env.production
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ npm run buildpwa
|
||||
|
||||
echo "Sincronizzazione $SERVERDIR_WEBSITE in remoto..."
|
||||
rsync -e 'ssh -p 8822' -a dist/pwa/ pcbuser@pcb:$SERVERDIR_WEBSITE
|
||||
rsync -e 'ssh -p 8822' -av --delete dist/pwa/js/ pcbuser@pcb:$SERVERDIR_WEBSITE/js
|
||||
|
||||
|
||||
cp .env.prod.bak .env.production
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ npm run buildspa
|
||||
|
||||
echo "Sincronizzazione $SERVERDIR_WEBSITE in remoto..."
|
||||
sshpass -p $SERVERPW_WEBSITE rsync -e 'ssh -p 8855' -a --exclude 'upload' dist/spa/ ftpadmin@servereng:/var/www/$SERVERDIR_WEBSITE/
|
||||
rsync -e 'ssh -p 8855' -av --delete dist/spa/js/ ftpadmin@servereng:/var/www/$SERVERDIR_WEBSITE/js
|
||||
|
||||
cp .env.prod.bak .env.production
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "riso",
|
||||
"version": "0.6.1",
|
||||
"version": "1.0.43",
|
||||
"description": "Siamo la Rete Italiana di Scambio Orizzontale, abbiamo creato questa piattaforma per metterla al servizio di chi vuole riscoprire il valore della condivisione e della cooperazione. Valori semplici e profondi che ci aiutano a ritrovare il Senso della Vita, perduto in questa società consumista, e riporti quei Sani Pricìpi Naturali ed Umani di Fratellanza che intere popolazioni antiche conoscevano bene.",
|
||||
"productName": "Riso",
|
||||
"author": "Paolo Arena",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "riso",
|
||||
"version": "0.6.1",
|
||||
"version": "1.0.43",
|
||||
"description": "Siamo la Rete Italiana di Scambio Orizzontale, abbiamo creato questa piattaforma per metterla al servizio di chi vuole riscoprire il valore della condivisione e della cooperazione. Valori semplici e profondi che ci aiutano a ritrovare il Senso della Vita, perduto in questa società consumista, e riporti quei Sani Pricìpi Naturali ed Umani di Fratellanza che intere popolazioni antiche conoscevano bene.",
|
||||
"productName": "Riso",
|
||||
"author": "Paolo Arena",
|
||||
|
||||
76
package.json
76
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "riso",
|
||||
"version": "0.6.1",
|
||||
"version": "1.0.43",
|
||||
"description": "Siamo la Rete Italiana di Scambio Orizzontale, abbiamo creato questa piattaforma per metterla al servizio di chi vuole riscoprire il valore della condivisione e della cooperazione. Valori semplici e profondi che ci aiutano a ritrovare il Senso della Vita, perduto in questa società consumista, e riporti quei Sani Pricìpi Naturali ed Umani di Fratellanza che intere popolazioni antiche conoscevano bene.",
|
||||
"productName": "Riso",
|
||||
"author": "Paolo Arena",
|
||||
@@ -27,27 +27,27 @@
|
||||
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
|
||||
"@babel/plugin-proposal-json-strings": "^7.18.6",
|
||||
"@babel/plugin-proposal-numeric-separator": "^7.18.6",
|
||||
"@cubejs-client/core": "^0.35.0",
|
||||
"@quasar/extras": "^1.16.9",
|
||||
"@cubejs-client/core": "^0.35.23",
|
||||
"@quasar/extras": "^1.16.11",
|
||||
"@quasar/quasar-ui-qcalendar": "^4.0.0-beta.19",
|
||||
"@types/leaflet": "^1.9.8",
|
||||
"@vue/compat": "^3.4.21",
|
||||
"@vue/compiler-sfc": "^3.4.21",
|
||||
"@vue/eslint-config-standard": "^7.0.0",
|
||||
"@types/leaflet": "^1.9.12",
|
||||
"@vue/compat": "^3.4.27",
|
||||
"@vue/compiler-sfc": "^3.4.27",
|
||||
"@vue/eslint-config-standard": "8.0.1",
|
||||
"@vuelidate/core": "^2.0.3",
|
||||
"@vuelidate/validators": "^2.0.4",
|
||||
"acorn": "^8.11.3",
|
||||
"animate.css": "^4.1.1",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"axios": "^1.6.8",
|
||||
"axios": "^1.7.2",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"chart.js": "^4.4.2",
|
||||
"core-js": "^3.36.1",
|
||||
"chart.js": "^4.4.3",
|
||||
"core-js": "^3.37.1",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"date-fns": "^3.6.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"echarts": "5.5.0",
|
||||
"eslint-plugin-n": "^15.0.0",
|
||||
"eslint-plugin-n": "^17.7.0",
|
||||
"eslint-plugin-quasar": "^1.1.0",
|
||||
"graphql": "^16.8.1",
|
||||
"graphql-tag": "^2.12.6",
|
||||
@@ -59,25 +59,25 @@
|
||||
"localforage": "^1.10.0",
|
||||
"lodash": "^4.17.21",
|
||||
"normalize.css": "^8.0.1",
|
||||
"npm": "^10.5.0",
|
||||
"npm": "^10.8.0",
|
||||
"nprogress": "^0.2.0",
|
||||
"pinia": "^2.1.7",
|
||||
"prerender-spa-plugin": "^3.4.0",
|
||||
"quasar": "^2.15.1",
|
||||
"quasar": "^2.16.4",
|
||||
"quasar-extras": "^2.0.9",
|
||||
"register-service-worker": "^1.7.2",
|
||||
"typescript-eslint": "^7.3.1",
|
||||
"vee-validate": "^4.12.6",
|
||||
"vue": "^3.4.21",
|
||||
"typescript-eslint": "^7.10.0",
|
||||
"vee-validate": "^4.12.8",
|
||||
"vue": "^3.4.27",
|
||||
"vue-class-component": "^8.0.0-rc.1",
|
||||
"vue-country-code": "^1.1.3",
|
||||
"vue-echarts": "^6.6.9",
|
||||
"vue-i18n": "^9.10.2",
|
||||
"vue-echarts": "^6.7.2",
|
||||
"vue-i18n": "^9.13.1",
|
||||
"vue-idb": "^0.2.0",
|
||||
"vue-image-zoomer": "^2.2.3",
|
||||
"vue-image-zoomer": "^2.3.0",
|
||||
"vue-loader": "^17.4.2",
|
||||
"vue-property-decorator": "^10.0.0-rc.3",
|
||||
"vue-router": "^4.3.0",
|
||||
"vue-router": "^4.3.2",
|
||||
"vue-scroll-reveal": "^2.1.0",
|
||||
"vue-social-sharing": "^4.0.0-alpha4",
|
||||
"vue-svgicon": "^4.0.0-alpha.3",
|
||||
@@ -88,45 +88,53 @@
|
||||
"vuex-router-sync": "^6.0.0-rc.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.24.3",
|
||||
"@quasar/app-webpack": "^3.12.4",
|
||||
"@babel/core": "^7.24.6",
|
||||
"@babel/plugin-proposal-decorators": "^7.24.6",
|
||||
"@babel/plugin-proposal-function-sent": "^7.24.6",
|
||||
"@babel/plugin-proposal-throw-expressions": "^7.24.6",
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
||||
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
||||
"@babel/plugin-transform-runtime": "^7.24.6",
|
||||
"@babel/preset-env": "^7.24.6",
|
||||
"@quasar/app-webpack": "^3.13.2",
|
||||
"@types/bcryptjs": "^2.4.6",
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"@types/googlemaps": "^3.43.3",
|
||||
"@types/jest": "^29.5.12",
|
||||
"@types/js-cookie": "^3.0.6",
|
||||
"@types/node": "20.11.30",
|
||||
"@types/node": "20.12.12",
|
||||
"@types/nprogress": "^0.2.3",
|
||||
"@types/vue-tel-input": "^2.1.6",
|
||||
"@types/vuelidate": "^0.7.21",
|
||||
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
||||
"@typescript-eslint/parser": "^7.3.1",
|
||||
"eslint": "^8.37.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.10.0",
|
||||
"@typescript-eslint/parser": "^7.10.0",
|
||||
"babel-loader": "^9.1.3",
|
||||
"eslint": "^9.3.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"eslint-plugin-vue": "^8.7.1",
|
||||
"eslint-plugin-vue": "^9.26.0",
|
||||
"file-loader": "^6.2.0",
|
||||
"html-webpack-plugin": "^5.6.0",
|
||||
"http-proxy-middleware": "^2.0.6",
|
||||
"http-proxy-middleware": "^3.0.0",
|
||||
"jest": "^29.7.0",
|
||||
"json-loader": "^0.5.7",
|
||||
"node-sass": "^9.0.0",
|
||||
"npm-check-updates": "^16.14.17",
|
||||
"npm-check-updates": "^16.14.20",
|
||||
"optimize-css-assets-webpack-plugin": "^6.0.1",
|
||||
"parcel": "^2.12.0",
|
||||
"postcss": "^8.4.38",
|
||||
"postcss-loader": "^8.1.1",
|
||||
"sass-loader": "^14.1.1",
|
||||
"sass-loader": "^14.2.1",
|
||||
"strip-ansi": "=7.1.0",
|
||||
"ts-jest": "^29.1.2",
|
||||
"ts-jest": "^29.1.3",
|
||||
"ts-loader": "^9.5.1",
|
||||
"typescript": "5.3.2",
|
||||
"typescript": "5.4.5",
|
||||
"vue-cli-plugin-element-ui": "^1.1.4",
|
||||
"vueify": "^9.4.1",
|
||||
"webpack": "^5.91.0",
|
||||
"workbox-webpack-plugin": "^6.5.4"
|
||||
"workbox-webpack-plugin": "6.5.4"
|
||||
},
|
||||
"browser": {
|
||||
"crypto": false
|
||||
@@ -145,7 +153,7 @@
|
||||
"not dead"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 18.18.0",
|
||||
"node": "^20 || ^18 || ^16",
|
||||
"npm": ">= 6.14.8",
|
||||
"yarn": ">= 1.21.1"
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ const webpack = require('webpack')
|
||||
const helpers = require('./helpers')
|
||||
const envparser = require('./config/envparser')
|
||||
|
||||
const package = require('./package.json');
|
||||
|
||||
// const ESLintPlugin = require('eslint-webpack-plugin')
|
||||
|
||||
module.exports = configure((ctx) => ({
|
||||
@@ -87,6 +89,7 @@ module.exports = configure((ctx) => ({
|
||||
// Full list of options: https://v2.quasar.dev/quasar-cli/quasar-conf-js#Property%3A-build
|
||||
build: {
|
||||
env: envparser(),
|
||||
versionCode: package.version,
|
||||
vueRouterMode: 'history',
|
||||
vueCompiler: true,
|
||||
gzip: false, // gzip true
|
||||
|
||||
@@ -5,4 +5,5 @@ source .env.test.risosrv
|
||||
echo "Sincronizzazione in remoto $SERVERDIR_WEBSITE ..."
|
||||
echo "SERVERDIR_WEBSITE = $SERVERDIR_WEBSITE"
|
||||
rsync -e 'ssh -p 8822' -a --exclude 'upload' dist/pwa/ pcbuser@pcb:$SERVERDIR_WEBSITE
|
||||
rsync -e 'ssh -p 8822' -av --delete dist/pwa/js/ pcbuser@pcb:$SERVERDIR_WEBSITE/js
|
||||
echo "Finito $SERVERDIR_WEBSITE"
|
||||
|
||||
@@ -1,667 +1,296 @@
|
||||
import { cleanupOutdatedCaches, precacheAndRoute } from 'workbox-precaching'
|
||||
import { registerRoute } from 'workbox-routing'
|
||||
|
||||
import { clientsClaim, setCacheNameDetails, skipWaiting } from 'workbox-core'
|
||||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.5.4/workbox-sw.js');
|
||||
|
||||
import { cleanupOutdatedCaches, precacheAndRoute } from 'workbox-precaching';
|
||||
import { registerRoute } from 'workbox-routing';
|
||||
import { clientsClaim, setCacheNameDetails, skipWaiting } from 'workbox-core';
|
||||
import {
|
||||
NetworkFirst,
|
||||
NetworkOnly,
|
||||
StaleWhileRevalidate,
|
||||
CacheFirst,
|
||||
} from 'workbox-strategies'
|
||||
} from 'workbox-strategies';
|
||||
|
||||
const ENABLE_DYNAMIC_CACHING = false;
|
||||
|
||||
// Used for filtering matches based on status code, header, or both
|
||||
import { CacheableResponsePlugin } from 'workbox-cacheable-response'
|
||||
// Used to limit entries in cache, remove entries after a certain period of time
|
||||
import { ExpirationPlugin } from 'workbox-expiration'
|
||||
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
|
||||
import { ExpirationPlugin } from 'workbox-expiration';
|
||||
|
||||
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
||||
|
||||
self.addEventListener('install', () => {
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('install', () => self.skipWaiting());
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(self.clients.claim());
|
||||
// console.log('CLAIM');
|
||||
//event.waitUntil(self.clients.claim())
|
||||
|
||||
event.waitUntil(async () => {
|
||||
// Check for a new service worker version
|
||||
const registration = await navigator.serviceWorker.getRegistration();
|
||||
if (registration && registration.waiting) {
|
||||
// A new service worker is waiting, trigger a page reload
|
||||
await registration.waiting.postMessage({ type: 'SKIP_WAITING' });
|
||||
self.skipWaiting();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
console.log(
|
||||
' [ VER-0.5.4 ] _---------________------ PAO: this is my custom service worker')
|
||||
|
||||
importScripts('js/idb.js')
|
||||
importScripts('js/storage.js')
|
||||
importScripts('js/workbox-sw.js')
|
||||
|
||||
// importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.4/workbox-sw.js');
|
||||
const VersioneApp = '1.0.42';
|
||||
|
||||
|
||||
console.log(' [ VER-' + VersioneApp + ' ] _---------________------ PAO: this is my custom service worker');
|
||||
|
||||
// importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js');
|
||||
importScripts('js/idb.js', 'js/storage.js');
|
||||
|
||||
// importScripts('./ChabokSDKWorker.js', 'https://storage.googleapis.com/workbox-cdn/releases/5.0.0/workbox-sw.js');
|
||||
|
||||
let port = 3000
|
||||
if (self.location.hostname.startsWith('test')) {
|
||||
port = 3001
|
||||
}
|
||||
console.log('SW- app ver 1.0.21')
|
||||
|
||||
const cfgenv = {
|
||||
serverweb: `${self.location.protocol}//${self.location.hostname}:${port}`,
|
||||
dbname: 'mydb3',
|
||||
dbversion: 11,
|
||||
}
|
||||
|
||||
// console.log('serverweb', cfgenv.serverweb)
|
||||
let port = self.location.hostname.startsWith('test') ? 3001 : 3000;
|
||||
console.log('SW- app ver ' + VersioneApp + ' on port ' + port);
|
||||
|
||||
// Function helpers
|
||||
async function writeData(table, data) {
|
||||
console.log('writeData', table, data);
|
||||
await idbKeyval.setdata(table, data)
|
||||
await idbKeyval.setdata(table, data);
|
||||
}
|
||||
|
||||
async function readAllData(table) {
|
||||
// console.log('readAllData', table);
|
||||
return idbKeyval.getalldata(table)
|
||||
return idbKeyval.getalldata(table);
|
||||
}
|
||||
|
||||
async function clearAllData(table) {
|
||||
// console.log('clearAllData', table);
|
||||
await idbKeyval.clearalldata(table)
|
||||
await idbKeyval.clearalldata(table);
|
||||
}
|
||||
|
||||
async function deleteItemFromData(table, id) {
|
||||
// console.log('deleteItemFromData', table, 'ID:', id);
|
||||
|
||||
await idbKeyval.deletedata(table, id)
|
||||
}
|
||||
|
||||
// self.addEventListener('activate', function(event) {
|
||||
// event.waitUntil(
|
||||
// // createDB()
|
||||
// );
|
||||
// });
|
||||
|
||||
if (!workbox) {
|
||||
const workbox = new self.WorkboxSW()
|
||||
await idbKeyval.deletedata(table, id);
|
||||
}
|
||||
|
||||
if (workbox) {
|
||||
const debug = false
|
||||
workbox.setConfig({ debug })
|
||||
const debug = false;
|
||||
workbox.setConfig({ debug });
|
||||
|
||||
const precacheList = self.__WB_MANIFEST || [];
|
||||
|
||||
setCacheNameDetails({
|
||||
prefix: self.location.hostname,
|
||||
suffix: 'v1',
|
||||
precache: 'precache',
|
||||
runtime: 'runtime'
|
||||
})
|
||||
runtime: 'runtime',
|
||||
});
|
||||
|
||||
// clientsClaim()
|
||||
// skipWaiting()
|
||||
|
||||
precacheAndRoute(precacheList)
|
||||
// cleanupOutdatedCaches()
|
||||
precacheAndRoute(precacheList);
|
||||
|
||||
// Cache strategy registrations
|
||||
registerRoute(
|
||||
new RegExp(/\.(?:png|gif|jpg|jpeg)$/),
|
||||
new CacheFirst({
|
||||
cacheName: 'images-upload',
|
||||
plugins: [
|
||||
// Ensure that only requests that result in a 200 status are cached
|
||||
new CacheableResponsePlugin({
|
||||
statuses: [200],
|
||||
}),
|
||||
new ExpirationPlugin({
|
||||
maxEntries: 60,
|
||||
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
|
||||
}),
|
||||
new CacheableResponsePlugin({ statuses: [200] }),
|
||||
new ExpirationPlugin({ maxEntries: 60, maxAgeSeconds: 30 * 24 * 60 * 60 }), // 30 Days
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
new RegExp(/\.(?:svg)$/),
|
||||
new CacheFirst({
|
||||
cacheName: 'svg',
|
||||
plugins: [
|
||||
// Ensure that only requests that result in a 200 status are cached
|
||||
new CacheableResponsePlugin({
|
||||
statuses: [200],
|
||||
}),
|
||||
new ExpirationPlugin({
|
||||
maxEntries: 60,
|
||||
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
|
||||
}),
|
||||
new CacheableResponsePlugin({ statuses: [200] }),
|
||||
new ExpirationPlugin({ maxEntries: 60, maxAgeSeconds: 30 * 24 * 60 * 60 }), // 30 Days
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
/*
|
||||
// Per Articoli....
|
||||
const articleHandler = new NetworkFirst({
|
||||
cacheName: 'articles-cache',
|
||||
plugins: [
|
||||
// Ensure that only requests that result in a 200 status are cached
|
||||
new CacheableResponsePlugin({
|
||||
statuses: [200],
|
||||
}),
|
||||
new ExpirationPlugin({
|
||||
maxEntries: 50,
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
registerRoute(
|
||||
new RegExp(/(.*)article(.*)\.html/), args => articleHandler.handle(args),
|
||||
) */
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
new RegExp(/.*(?:googleapis|gstatic)\.com.*$/),
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: 'google-fonts',
|
||||
plugins: [
|
||||
// Ensure that only requests that result in a 200 status are cached
|
||||
new CacheableResponsePlugin({
|
||||
statuses: [200],
|
||||
}),
|
||||
new ExpirationPlugin({
|
||||
maxEntries: 30,
|
||||
}),
|
||||
new CacheableResponsePlugin({ statuses: [200] }),
|
||||
new ExpirationPlugin({ maxEntries: 30 }),
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
// console.log(' routing.registerRoute function declaration:')
|
||||
|
||||
function Execute_Fetch(table, args) {
|
||||
console.log('Execute_Fetch registerRoute! ',
|
||||
`${cfgenv.serverweb}/${table}/`)
|
||||
// console.log('DATABODY:', args.event.request.body)
|
||||
let myres = null
|
||||
// return fetch(args.event.request, args.event.headers)
|
||||
return fetch(args.event.request, args.event.headers)
|
||||
.then((res) => {
|
||||
myres = res
|
||||
if (res.status === 200) {
|
||||
const clonedRes = res.clone()
|
||||
|
||||
let secondatab = ''
|
||||
if (table === 'todos') {
|
||||
secondatab = 'categories'
|
||||
}
|
||||
console.log('1) clearAllData: ', table)
|
||||
return clearAllData(table)
|
||||
.then(() => {
|
||||
if (secondatab !== '') {
|
||||
// console.log('2) clearAllData(todos)')
|
||||
return clearAllData(secondatab)
|
||||
.then(() =>
|
||||
// console.log('3) ....return clonedRes')
|
||||
clonedRes)
|
||||
}
|
||||
return clonedRes
|
||||
})
|
||||
}
|
||||
})
|
||||
.then((clonedRes) => {
|
||||
// console.log(' 3) ')
|
||||
if (clonedRes) return clonedRes.json()
|
||||
return null
|
||||
})
|
||||
.then(data => {
|
||||
// console.log(' 4) data = ', data)
|
||||
if (data) {
|
||||
const myarr = idbKeyval.getArrayByTable(table, data)
|
||||
if (myarr) {
|
||||
let promiseChain = Promise.resolve()
|
||||
|
||||
console.log('*********+++++++++++++++++********** Records ',
|
||||
`${table} Received from Server [`, myarr.length, 'record]', myarr)
|
||||
|
||||
if (table === 'todos') {
|
||||
for (const cat in data.categories) {
|
||||
promiseChain = promiseChain.then(() => writeData('categories', {
|
||||
_id: cat,
|
||||
valore: data.categories[cat],
|
||||
}))
|
||||
}
|
||||
|
||||
for (const arrsing of myarr) {
|
||||
for (const rec of arrsing) {
|
||||
promiseChain = promiseChain.then(() => writeData(table, rec))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Others tables
|
||||
for (const rec of myarr) {
|
||||
promiseChain = promiseChain.then(() => writeData(table, rec))
|
||||
}
|
||||
}
|
||||
|
||||
// console.log('promiseChain', promiseChain)
|
||||
|
||||
return promiseChain
|
||||
}
|
||||
}
|
||||
})
|
||||
.then(() => myres)
|
||||
.catch(err => {
|
||||
console.log('ERROR registerRoute FETCH:', err)
|
||||
return myres
|
||||
})
|
||||
}
|
||||
|
||||
for (const table of MainTables) {
|
||||
registerRoute(
|
||||
new RegExp(`${cfgenv.serverweb}/${table}/`),
|
||||
(args) => {
|
||||
Execute_Fetch(table, args)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
registerRoute(
|
||||
(routeData) => (routeData.event.request.headers.get('accept')
|
||||
.includes('text/html')), (args) => caches.match(args.event.request)
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
return response
|
||||
}
|
||||
return fetch(args.event.request)
|
||||
.then((res) => caches.open('dynamic')
|
||||
.then((cache) => {
|
||||
console.log('fetch cache')
|
||||
console.log('cache', args.event.request.url)
|
||||
cache.put(args.event.request.url, res.clone())
|
||||
return res
|
||||
}))
|
||||
.catch((err) => caches.match('/offline')
|
||||
.then((res) => res))
|
||||
}),
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
new RegExp(/.*\/(?:icons).*$/),
|
||||
new CacheFirst({
|
||||
cacheName: 'icon-cache',
|
||||
plugins: [
|
||||
// Ensure that only requests that result in a 200 status are cached
|
||||
new CacheableResponsePlugin({
|
||||
statuses: [200],
|
||||
}),
|
||||
new ExpirationPlugin({
|
||||
maxAgeSeconds: 30 * 24 * 60 * 60,
|
||||
}),
|
||||
new CacheableResponsePlugin({ statuses: [200] }),
|
||||
new ExpirationPlugin({ maxAgeSeconds: 30 * 24 * 60 * 60 }), // 30 Days
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
registerRoute(
|
||||
new RegExp(/\.(?:js|css|font)$/),
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: 'js-css-fonts',
|
||||
// Ensure that only requests that result in a 200 status are cached
|
||||
plugins: [
|
||||
new CacheableResponsePlugin({
|
||||
statuses: [200],
|
||||
}),
|
||||
new CacheableResponsePlugin({ statuses: [200] }),
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
// Storage
|
||||
registerRoute(
|
||||
new RegExp(/.*(?:storage)/),
|
||||
new StaleWhileRevalidate({
|
||||
cacheName: 'storage',
|
||||
plugins: [
|
||||
// Ensure that only requests that result in a 200 status are cached
|
||||
new CacheableResponsePlugin({
|
||||
statuses: [200],
|
||||
}),
|
||||
new ExpirationPlugin({
|
||||
maxAgeSeconds: 30 * 24 * 60 * 60,
|
||||
// Only cache 10 requests.
|
||||
maxEntries: 200,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
registerRoute(
|
||||
new RegExp(/.*\/(?:public).*$/),
|
||||
new CacheFirst({
|
||||
cacheName: 'public',
|
||||
plugins: [
|
||||
// Ensure that only requests that result in a 200 status are cached
|
||||
new CacheableResponsePlugin({
|
||||
statuses: [200],
|
||||
}),
|
||||
new ExpirationPlugin({
|
||||
maxAgeSeconds: 10 * 24 * 60 * 60,
|
||||
// Only cache 10 requests.
|
||||
}),
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
registerRoute(
|
||||
new RegExp('/admin/'),
|
||||
new NetworkOnly(),
|
||||
)
|
||||
|
||||
/*registerRoute(
|
||||
new RegExp('/owa/'),
|
||||
new NetworkOnly(),
|
||||
)
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
|
||||
// console.log('***************** Entering in custom-service-worker.js:')
|
||||
|
||||
}
|
||||
|
||||
/* self.addEventListener('fetch', (event) => {
|
||||
if (event.request.url === '/') {
|
||||
const StaleWhileRevalidate = new StaleWhileRevalidate();
|
||||
event.respondWith(StaleWhileRevalidate.handle({ event }));
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
console.log('[Service Worker] Fetching something ....', event);
|
||||
console.log('event.request.cache=', event.request.cache)
|
||||
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
|
||||
console.log('SAME ORIGIN!', event);
|
||||
return;
|
||||
}
|
||||
event.respondWith((async () => {
|
||||
const cachedResponse = await caches.match(event.request);
|
||||
if (cachedResponse) {
|
||||
return cachedResponse;
|
||||
}
|
||||
|
||||
console.log('*** REQUEST', event.request);
|
||||
try {
|
||||
const response = await fetch(event.request);
|
||||
|
||||
if (!response || response.status !== 200 || response.type !== 'basic') {
|
||||
return response;
|
||||
}
|
||||
|
||||
if (ENABLE_DYNAMIC_CACHING) {
|
||||
const responseToCache = response.clone();
|
||||
const cache = await caches.open(DYNAMIC_CACHE)
|
||||
await cache.put(event.request, response.clone());
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
})());
|
||||
});
|
||||
|
||||
|
||||
const syncStore = {}
|
||||
self.addEventListener('message', event => {
|
||||
if (event.data && event.data.type === 'SKIP_WAITING') {
|
||||
self.skipWaiting()
|
||||
}
|
||||
if (event.data.type === 'sync') {
|
||||
console.log('addEventListener - message')
|
||||
// get a unique id to save the data
|
||||
const id = uuid()
|
||||
syncStore[id] = event.data
|
||||
// register a sync and pass the id as tag for it to get the data
|
||||
self.registration.sync.register(id)
|
||||
console.log('self.registration.sync.register(id)')
|
||||
}
|
||||
console.log(event.data)
|
||||
})
|
||||
|
||||
|
||||
addEventListener('fetch', event => {
|
||||
// Prevent the default, and handle the request ourselves.
|
||||
event.respondWith(async function () {
|
||||
// Try to get the response from a cache.
|
||||
const cachedResponse = await caches.match(event.request);
|
||||
// Return it if we found one.
|
||||
if (cachedResponse && (event.request.cache !== 'no-cache'))
|
||||
return cachedResponse;
|
||||
|
||||
// If we didn't find a match in the cache, use the network.
|
||||
return fetch(event.request);
|
||||
}());
|
||||
});
|
||||
|
||||
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
event.respondWith(
|
||||
fetch(event.request, event.headers)
|
||||
.catch(err => {
|
||||
console.log('_______________________ ERRORE FETCH SW: ', event.request, err)
|
||||
writeData('config', { _id: 2, stateconn: 'offline' })
|
||||
return caches.match(event.request);
|
||||
})
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
registerRoute(
|
||||
(routeData) => routeData.event.request.headers.get('accept').includes('text/html'),
|
||||
async (args) => {
|
||||
let response = await caches.match(args.event.request);
|
||||
if (response) return response;
|
||||
|
||||
self.addEventListener('sync', function (event) {
|
||||
console.log('[Service Worker V5] Background syncing', event);
|
||||
console.log('event:', event);
|
||||
try {
|
||||
response = await fetch(args.event.request);
|
||||
const cache = await caches.open('dynamic');
|
||||
cache.put(args.event.request.url, response.clone());
|
||||
return response;
|
||||
} catch (err) {
|
||||
return caches.match('/offline');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let mystrparam = event.tag
|
||||
let multiparams = mystrparam.split('|')
|
||||
if (multiparams) {
|
||||
if (multiparams.length > 3) {
|
||||
let cmd = multiparams[0]
|
||||
let table = multiparams[1]
|
||||
let method = multiparams[2]
|
||||
let token = multiparams[3]
|
||||
let refreshToken = multiparams[4]
|
||||
// let lang = multiparams[3]
|
||||
registerRoute(new RegExp('/admin/'), new NetworkOnly());
|
||||
|
||||
const syncStore = {};
|
||||
self.addEventListener('message', event => {
|
||||
if (event.data && (event.data.type === 'SKIP_WAITING' || event.data.action === 'skipWaiting')) {
|
||||
window.location.reload();
|
||||
}
|
||||
if (event.data.type === 'sync') {
|
||||
console.log('addEventListener - message');
|
||||
const id = uuid();
|
||||
syncStore[id] = event.data;
|
||||
self.registration.sync.register(id);
|
||||
}
|
||||
console.log(event.data);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') return;
|
||||
|
||||
event.respondWith(async () => {
|
||||
let cachedResponse = await caches.match(event.request);
|
||||
if (cachedResponse) return cachedResponse;
|
||||
|
||||
try {
|
||||
const response = await fetch(event.request);
|
||||
if (!response || response.status !== 200 || response.type !== 'basic') return response;
|
||||
|
||||
if (ENABLE_DYNAMIC_CACHING) {
|
||||
const cache = await caches.open(DYNAMIC_CACHE);
|
||||
cache.put(event.request, response.clone());
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
self.addEventListener('sync', event => {
|
||||
console.log('[Service Worker V5] Background syncing', event);
|
||||
|
||||
let mystrparam = event.tag;
|
||||
let multiparams = mystrparam.split('|');
|
||||
if (multiparams && multiparams.length > 3) {
|
||||
let [cmd, table, method, token, refreshToken] = multiparams;
|
||||
|
||||
if (cmd === 'sync-todos') {
|
||||
console.log('[Service Worker] Syncing', cmd, table, method);
|
||||
|
||||
const headers = new Headers()
|
||||
headers.append('content-Type', 'application/json')
|
||||
headers.append('Accept', 'application/json')
|
||||
headers.append('x-auth', token)
|
||||
headers.append('x-refrtok', refreshToken)
|
||||
|
||||
|
||||
// console.log('A1) INIZIO.............................................................');
|
||||
const headers = new Headers();
|
||||
headers.append('content-Type', 'application/json');
|
||||
headers.append('Accept', 'application/json');
|
||||
headers.append('x-auth', token);
|
||||
headers.append('x-refrtok', refreshToken);
|
||||
|
||||
event.waitUntil(
|
||||
readAllData(table)
|
||||
.then(function (alldata) {
|
||||
const myrecs = [...alldata]
|
||||
console.log('----------------------- LEGGO QUALCOSA DAL WAITUNTIL ')
|
||||
let errorfromserver = false
|
||||
if (myrecs) {
|
||||
for (let rec of myrecs) {
|
||||
//console.log('syncing', table, '', rec.descr)
|
||||
let link = cfgenv.serverweb + '/todos'
|
||||
readAllData(table).then(alldata => {
|
||||
const myrecs = [...alldata];
|
||||
let errorfromserver = false;
|
||||
|
||||
if (method !== 'POST')
|
||||
link += '/' + rec._id
|
||||
if (myrecs) {
|
||||
let promiseChain = Promise.resolve();
|
||||
|
||||
console.log('++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:')
|
||||
for (let rec of myrecs) {
|
||||
let link = cfgenv.serverweb + '/todos';
|
||||
if (method !== 'POST') link += '/' + rec._id;
|
||||
|
||||
// console.log('DATATOSAVE:', JSON.stringify(rec))
|
||||
|
||||
// Insert/Delete/Update table to the server
|
||||
promiseChain = promiseChain.then(() =>
|
||||
fetch(link, {
|
||||
method: method,
|
||||
headers: headers,
|
||||
cache: 'no-cache',
|
||||
mode: 'cors', // 'no-cors',
|
||||
body: JSON.stringify(rec)
|
||||
mode: 'cors',
|
||||
body: JSON.stringify(rec),
|
||||
}).then(() => {
|
||||
deleteItemFromData(table, rec._id);
|
||||
deleteItemFromData('swmsg', mystrparam);
|
||||
})
|
||||
.then(() => {
|
||||
deleteItemFromData(table, rec._id)
|
||||
})
|
||||
.then(() => {
|
||||
deleteItemFromData('swmsg', mystrparam)
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.log('!!!!!!!!!!!!!!! Error while sending data', err, err.message);
|
||||
.catch(err => {
|
||||
if (err.message === 'Failed to fetch') {
|
||||
errorfromserver = true
|
||||
errorfromserver = true;
|
||||
}
|
||||
})
|
||||
}
|
||||
return errorfromserver
|
||||
);
|
||||
}
|
||||
})
|
||||
.then((errorfromserver) => {
|
||||
const mystate = !errorfromserver ? 'online' : 'offline'
|
||||
writeData('config', { _id: 2, stateconn: mystate })
|
||||
})
|
||||
|
||||
return promiseChain.then(() => {
|
||||
const mystate = !errorfromserver ? 'online' : 'offline';
|
||||
writeData('config', { _id: 2, stateconn: mystate });
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
// console.log('A2) ?????????????????????????? ESCO DAL LOOP !!!!!!!!! err=')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
;
|
||||
});
|
||||
|
||||
/*
|
||||
// Notifications
|
||||
self.addEventListener('notificationclick', (event) => {
|
||||
const { notification } = event;
|
||||
const { action } = event;
|
||||
|
||||
// send message to serviceWorker
|
||||
function sync (url, options) {
|
||||
navigator.serviceWorker.controller.postMessage({type: 'sync', url, options})
|
||||
}
|
||||
|
||||
const syncStore = {}
|
||||
self.addEventListener('message', event => {
|
||||
if(event.data.type === 'sync') {
|
||||
// get a unique id to save the data
|
||||
const id = uuid()
|
||||
syncStore[id] = event.data
|
||||
// register a sync and pass the id as tag for it to get the data
|
||||
self.registration.sync.register(id)
|
||||
}
|
||||
console.log(event.data)
|
||||
})
|
||||
|
||||
self.addEventListener('sync', event => {
|
||||
// get the data by tag
|
||||
const {url, options} = syncStore[event.tag]
|
||||
event.waitUntil(fetch(url, options))
|
||||
})
|
||||
*/
|
||||
|
||||
self.addEventListener('notificationclick', (event) => {
|
||||
const { notification } = event
|
||||
const { action } = event
|
||||
|
||||
console.log(notification)
|
||||
|
||||
if (action === 'confirm') {
|
||||
console.log('Confirm was chosen')
|
||||
notification.close()
|
||||
} else {
|
||||
console.log(action)
|
||||
event.waitUntil(
|
||||
clients.matchAll()
|
||||
.then((clis) => {
|
||||
const client = clis.find((c) => c.visibilityState === 'visible')
|
||||
|
||||
if (client) {
|
||||
client.navigate(notification.data.url)
|
||||
client.focus()
|
||||
} else {
|
||||
clients.openWindow(notification.data.url)
|
||||
}
|
||||
notification.close()
|
||||
}),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
self.addEventListener('notificationclose', (event) => {
|
||||
console.log('Notification was closed', event)
|
||||
})
|
||||
|
||||
self.addEventListener('push', (event) => {
|
||||
console.log('Push Notification received', event)
|
||||
|
||||
let data = {
|
||||
title: 'New!',
|
||||
content: 'Something new happened!',
|
||||
url: '/',
|
||||
}
|
||||
|
||||
try {
|
||||
let isobj = false
|
||||
if (event.data) {
|
||||
try {
|
||||
data = JSON.parse(event.data.text())
|
||||
isobj = true
|
||||
} catch (e) {
|
||||
data = event.data.text()
|
||||
}
|
||||
}
|
||||
|
||||
console.log('event.data', data)
|
||||
|
||||
let options = {}
|
||||
|
||||
let myid = '0'
|
||||
|
||||
if (isobj) {
|
||||
if (data.id) {
|
||||
myid = data.id
|
||||
}
|
||||
|
||||
options = {
|
||||
body: data.content,
|
||||
icon: data.icon ? data.icon : '/images/android-chrome-192x192.png',
|
||||
badge: data.badge ? data.badge : '/images/badge-96x96.png',
|
||||
data: {
|
||||
url: data.url,
|
||||
},
|
||||
tag: data.tag,
|
||||
renitify: true, // vibrate also with others messages.
|
||||
}
|
||||
|
||||
event.waitUntil(
|
||||
self.registration.showNotification(data.title ? data.title : data.content, options),
|
||||
)
|
||||
if (action === 'confirm') {
|
||||
notification.close();
|
||||
} else {
|
||||
let text = data;
|
||||
options = {
|
||||
body: text,
|
||||
icon: '/images/android-chrome-192x192.png',
|
||||
badge: '/images/badge-96x96.png',
|
||||
data: {
|
||||
url: '/',
|
||||
},
|
||||
tag: 'notif',
|
||||
renitify: true, // vibrate also with others messages.
|
||||
}
|
||||
|
||||
event.waitUntil(
|
||||
self.registration.showNotification('', options),
|
||||
)
|
||||
clients.matchAll().then((clis) => {
|
||||
const client = clis.find((c) => c.visibilityState === 'visible');
|
||||
if (client) {
|
||||
client.navigate(notification.data.url);
|
||||
client.focus();
|
||||
} else {
|
||||
clients.openWindow(notification.data.url);
|
||||
}
|
||||
notification.close();
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
self.registration.sync.register(myid)
|
||||
writeData('notifications', { _id: myid, tag: options.tag })
|
||||
self.addEventListener('notificationclose', (event) => {
|
||||
console.log('Notification was closed', event);
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.log('Error on event push:', e)
|
||||
}
|
||||
})
|
||||
self.addEventListener('push', (event) => {
|
||||
console.log('Push Notification received', event);
|
||||
let data = event.data ? event.data.json() : { title: 'New!', content: 'Something new happened!', url: '/' };
|
||||
|
||||
const options = {
|
||||
body: data.content,
|
||||
icon: data.icon ? data.icon : '/images/android-chrome-192x192.png',
|
||||
badge: data.badge ? data.badge : '/images/badge-96x96.png',
|
||||
data: { url: data.url },
|
||||
tag: data.tag,
|
||||
};
|
||||
|
||||
event.waitUntil(self.registration.showNotification(data.title, options));
|
||||
|
||||
const myid = data.id || '0';
|
||||
self.registration.sync.register(myid);
|
||||
writeData('notifications', { _id: myid, tag: options.tag });
|
||||
});
|
||||
} else {
|
||||
console.warn('Workbox could not be loaded.');
|
||||
}
|
||||
@@ -1,20 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%= productName %></title>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="description" content="<%= productDescription %>">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width<% if (ctx.mode.cordova || ctx.mode.capacitor) { %>, viewport-fit=cover<% } %>">
|
||||
<head>
|
||||
<title>
|
||||
<%= productName %>
|
||||
</title>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="description" content="<%= productDescription %>">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta name="version" content="1.0.43">
|
||||
<meta name="viewport"
|
||||
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width<% if (ctx.mode.cordova || ctx.mode.capacitor) { %>, viewport-fit=cover<% } %>">
|
||||
|
||||
<!-- Aggiungi le intestazioni di controllo della cache -->
|
||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
||||
<meta http-equiv="Pragma" content="no-cache">
|
||||
<meta http-equiv="Expires" content="0">
|
||||
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
|
||||
<link rel="icon" type="image/ico" href="favicon.ico">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- DO NOT touch the following DIV -->
|
||||
<div id="q-app"></div>
|
||||
</body>
|
||||
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
|
||||
<link rel="icon" type="image/ico" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<!-- DO NOT touch the following DIV -->
|
||||
<div id="q-app"></div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user