versione 1.2.14 :
- aggiornati i file di configurazione, ENV e script non funzionanti., package. - corretto custom-service-worker.js con CORS - ottimizzato il server, la chiamata Load iniziale (senza promise, con async/await).
This commit is contained in:
@@ -864,36 +864,38 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
|
||||
let reg: any
|
||||
const mykey = import.meta.env.VITE_PUBLICKEY_PUSH
|
||||
return navigator.serviceWorker.ready
|
||||
.then((swreg) => {
|
||||
reg = swreg
|
||||
return swreg.pushManager.getSubscription()
|
||||
})
|
||||
.then((subscription) => {
|
||||
console.log('!!!!!!!! subscription = ', subscription)
|
||||
if (navigator.serviceWorker) {
|
||||
return navigator.serviceWorker.ready
|
||||
.then((swreg) => {
|
||||
reg = swreg
|
||||
return swreg.pushManager.getSubscription()
|
||||
})
|
||||
.then((subscription) => {
|
||||
console.log('!!!!!!!! subscription = ', subscription)
|
||||
|
||||
this.wasAlreadySubscribed = !(subscription === null)
|
||||
this.wasAlreadySubscribed = !(subscription === null)
|
||||
|
||||
if (this.wasAlreadySubscribed) {
|
||||
// console.log('User is already SAVED Subscribe on DB!')
|
||||
// return null
|
||||
return subscription
|
||||
} else {
|
||||
// Create a new subscription
|
||||
console.log('#### Create a new subscription !!!')
|
||||
const convertedVapidPublicKey = urlBase64ToUint8Array(mykey)
|
||||
return reg.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: convertedVapidPublicKey,
|
||||
})
|
||||
}
|
||||
})
|
||||
.then((newSub) => {
|
||||
this.saveNewSubscriptionToServer(newSub)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('ERR createPushSubscription:', err)
|
||||
})
|
||||
if (this.wasAlreadySubscribed) {
|
||||
// console.log('User is already SAVED Subscribe on DB!')
|
||||
// return null
|
||||
return subscription
|
||||
} else {
|
||||
// Create a new subscription
|
||||
console.log('#### Create a new subscription !!!')
|
||||
const convertedVapidPublicKey = urlBase64ToUint8Array(mykey)
|
||||
return reg.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: convertedVapidPublicKey,
|
||||
})
|
||||
}
|
||||
})
|
||||
.then((newSub) => {
|
||||
this.saveNewSubscriptionToServer(newSub)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('ERR createPushSubscription:', err)
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// Calling the Server to Save in the MongoDB the Subscriber
|
||||
@@ -985,23 +987,25 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
if ('serviceWorker' in navigator) {
|
||||
// REMOVE ALL SUBSCRIPTION
|
||||
console.log('REMOVE ALL SUBSCRIPTION...')
|
||||
navigator.serviceWorker.ready
|
||||
.then((reg) => {
|
||||
console.log('... Ready')
|
||||
reg.pushManager.getSubscription().then((subscription) => {
|
||||
console.log(' Found Subscription...')
|
||||
if (subscription) {
|
||||
subscription.unsubscribe().then((successful) => {
|
||||
// You've successfully unsubscribed
|
||||
console.log('You\'ve successfully unsubscribed')
|
||||
}).catch((e) => {
|
||||
// Unsubscription failed
|
||||
})
|
||||
}
|
||||
if (navigator.serviceWorker) {
|
||||
navigator.serviceWorker.ready
|
||||
.then((reg) => {
|
||||
console.log('... Ready')
|
||||
reg.pushManager.getSubscription().then((subscription) => {
|
||||
console.log(' Found Subscription...')
|
||||
if (subscription) {
|
||||
subscription.unsubscribe().then((successful) => {
|
||||
// You've successfully unsubscribed
|
||||
console.log('You\'ve successfully unsubscribed')
|
||||
}).catch((e) => {
|
||||
// Unsubscription failed
|
||||
})
|
||||
}
|
||||
})
|
||||
}).catch((err) => {
|
||||
console.error('err ready service worker', err)
|
||||
})
|
||||
}).catch((err) => {
|
||||
console.error('err ready service worker', err)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1838,8 +1842,17 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
// const isLogged = localStorage.getItem(toolsext.localStorage.username)
|
||||
// console.log('isLogged', isLogged)
|
||||
|
||||
let myidapp = ''
|
||||
try {
|
||||
if (res.data?.myuser) {
|
||||
myidapp = res.data?.myuser?.idapp
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
// calendarStore.editable = userStore.isAdmin || userStore.isManager || userStore.isFacilitatore
|
||||
if (res.data.myuser === null || (res.data.myuser.idapp !== tools.getEnv('VITE_APP_ID'))) {
|
||||
if (!myidapp || (myidapp !== tools.getEnv('VITE_APP_ID'))) {
|
||||
if (isLogged) {
|
||||
// Fai Logout
|
||||
// console.log('Fai Logout', 'isLogged', isLogged)
|
||||
|
||||
Reference in New Issue
Block a user