update Push Notification
This commit is contained in:
@@ -1077,19 +1077,13 @@
|
||||
});
|
||||
}
|
||||
|
||||
// --- FUNZIONE PER ISCRIVERSI ALLE PUSH ---
|
||||
// --- FUNZIONE PER ISCRIVERSI ALLE PUSH ---
|
||||
async function subscribeToPush() {
|
||||
const lang = document.documentElement.lang || 'it';
|
||||
const msg = {
|
||||
it: { ok: "Notifiche attivate!", err: "Errore o permesso negato", title: "PUSH" },
|
||||
en: { ok: "Notifications enabled!", err: "Error or permission denied", title: "PUSH" }
|
||||
};
|
||||
|
||||
if (!('serviceWorker' in navigator)) return;
|
||||
|
||||
const permission = await Notification.requestPermission();
|
||||
if (permission !== 'granted') {
|
||||
customAlert("Error", msg[lang].err, true);
|
||||
customAlert("Error", "Push notifications permission denied.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1109,10 +1103,11 @@
|
||||
body: JSON.stringify(subscription)
|
||||
});
|
||||
|
||||
customAlert("Success", msg[lang].ok);
|
||||
customAlert("Success", "Push notifications enabled successfully!");
|
||||
document.getElementById('push-btn').style.color = 'var(--success)';
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
customAlert("Error", "Failed to enable notifications.", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user