|
@ -235,7 +235,10 @@ |
|
|
Turn Off Notifications |
|
|
Turn Off Notifications |
|
|
</button> |
|
|
</button> |
|
|
<button |
|
|
<button |
|
|
@click="close(notification.id)" |
|
|
@click=" |
|
|
|
|
|
close(notification.id); |
|
|
|
|
|
turnOffNotifications(); |
|
|
|
|
|
" |
|
|
class="block w-full text-center text-md font-bold uppercase bg-slate-600 text-white px-2 py-2 rounded-md" |
|
|
class="block w-full text-center text-md font-bold uppercase bg-slate-600 text-white px-2 py-2 rounded-md" |
|
|
> |
|
|
> |
|
|
Leave it On |
|
|
Leave it On |
|
@ -534,5 +537,50 @@ export default class App extends Vue { |
|
|
console.log("Subscription sent to server successfully."); |
|
|
console.log("Subscription sent to server successfully."); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async turnOffNotifications() { |
|
|
|
|
|
let subscription; |
|
|
|
|
|
const pushProviderSuccess = await navigator.serviceWorker.ready |
|
|
|
|
|
.then((registration) => { |
|
|
|
|
|
return registration.pushManager.getSubscription(); |
|
|
|
|
|
}) |
|
|
|
|
|
.then((subscript) => { |
|
|
|
|
|
subscription = subscript; |
|
|
|
|
|
if (subscription) { |
|
|
|
|
|
return subscription.unsubscribe(); |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log("Subscription object is not available."); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
console.log("Push provider server communication failed:", error); |
|
|
|
|
|
return false; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const pushServerSuccess = await fetch("/web-push/unsubscribe", { |
|
|
|
|
|
method: "POST", |
|
|
|
|
|
headers: { |
|
|
|
|
|
"Content-Type": "application/json", |
|
|
|
|
|
}, |
|
|
|
|
|
body: JSON.stringify(subscription), |
|
|
|
|
|
}) |
|
|
|
|
|
.then((response) => { |
|
|
|
|
|
return response.ok; |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
console.log("Push server communication failed:", error); |
|
|
|
|
|
return false; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
alert( |
|
|
|
|
|
"Notifications are off. Push provider unsubscribe " + |
|
|
|
|
|
(pushProviderSuccess ? "succeeded" : "failed") + |
|
|
|
|
|
(pushProviderSuccess === pushServerSuccess ? " and" : " but") + |
|
|
|
|
|
" push server unsubscribe " + |
|
|
|
|
|
(pushServerSuccess ? "succeeded" : "failed") + |
|
|
|
|
|
".", |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|