initial: bootstrap from BukidBountyApp base
This commit is contained in:
41
resources/js/utils/notifications.js
Normal file
41
resources/js/utils/notifications.js
Normal file
@@ -0,0 +1,41 @@
|
||||
export function setNotif(title, body = '', icon = '', tag = '') {
|
||||
Notification.requestPermission(result => {
|
||||
if (result === 'granted') {
|
||||
navigator.serviceWorker.ready.then(reg =>
|
||||
reg.showNotification(title, { body, icon, tag })
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function eraseAllNotif() {
|
||||
Notification.requestPermission(result => {
|
||||
if (result === 'granted') {
|
||||
navigator.serviceWorker.ready.then(reg =>
|
||||
reg.getNotifications().then(n => n.forEach(x => x.close()))
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function EraseNotifwithTag(tag) {
|
||||
Notification.requestPermission(function (result) {
|
||||
if (result === 'granted') {
|
||||
// Replace 'specific-tag' with the tag you want to target
|
||||
const specificTag = tag;
|
||||
|
||||
// Check if service workers are available
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready.then(function (registration) {
|
||||
registration.getNotifications().then(function (notifications) {
|
||||
notifications.forEach(function (notification) {
|
||||
if (notification.tag === specificTag) {
|
||||
notification.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user