Notification with Service Workers now is working!

When a Notification arrives, it save into the IndexDb,
then in Vue.js call a polling to check in the db if there is a different record count.
If is different then call a get to update the notification.
This commit is contained in:
paoloar77
2022-08-07 02:01:20 +02:00
parent 66ee007e92
commit ce20daed6d
27 changed files with 411 additions and 232 deletions

View File

@@ -8,7 +8,7 @@ export let idbKeyval = (() => {
// console.log('CREO DB STORAGE JS !')
db = new Promise((resolve, reject) => {
// console.log('open mydb3')
const openreq = indexedDB.open('mydb3', 12);
const openreq = indexedDB.open('mydb3', 13);
openreq.onerror = () => {
reject(openreq.error);
@@ -50,7 +50,7 @@ export let idbKeyval = (() => {
return {
async get(key) {
let req;
withStore('readonly', 'keyval', store => {
await withStore('readonly', 'keyval', store => {
req = store.get(key);
});
return req.result;
@@ -62,30 +62,49 @@ export let idbKeyval = (() => {
async getdata(table, key) {
let req;
withStore('readonly', table, store => {
await withStore('readonly', table, store => {
// console.log('getdata', table, key)
req = store.get(key);
// console.log(' req', req)
});
return req.result;
if (req) {
console.log('getdata', table, key, req.result)
return req.result;
} else {
return null;
}
},
async getalldata(table) {
let req;
withStore('readonly', table, store => {
await withStore('readonly', table, store => {
req = store.getAll();
console.log(' req', req)
});
return req.result;
if (req) {
return req.result;
} else {
return null;
}
},
async count(table) {
let req;
withStore('readonly', table, store => {
await withStore('readonly', table, store => {
req = store.count();
});
return req.result;
// console.log('req', req)
if (req) {
// console.log('COUNT:', table, req.result)
return req.result;
} else {
return 0;
}
},
async set(key, value) {
let req;
withStore('readwrite', 'keyval', store => {
await withStore('readwrite', 'keyval', store => {
req = store.put(value, key);
});
return req.result;
@@ -94,7 +113,7 @@ export let idbKeyval = (() => {
let req;
// console.log('setdata', table, value)
withStore('readwrite', table, store => {
await withStore('readwrite', table, store => {
req = store.put(value);
});
return req.result;
@@ -121,6 +140,7 @@ export let idbKeyval = (() => {
// iOS add-to-homescreen is missing IDB, or at least it used to.
// I haven't tested this in a while.
if (!self.indexedDB) {
console.log('NO indexedDB')
idbKeyval = {
get: key => Promise.resolve(localStorage.getItem(key)),
set: (key, val) => Promise.resolve(localStorage.setItem(key, val)),