move enable notification from html

This commit is contained in:
creeper123123321 2021-03-17 12:38:11 -03:00
parent 7dde4c81db
commit 8586f08adb
3 changed files with 8 additions and 6 deletions

View File

@ -1,5 +1,5 @@
// SW
navigator.serviceWorker.register("sw.js")
navigator.serviceWorker.register("sw.js");
// Minecraft.id
let urlParams = new URLSearchParams();
@ -236,6 +236,10 @@ function refreshAccountList() {
}
function renderActions() {
actions.innerHTML = "";
if (Notification.permission == "default") {
actions.innerHTML += '<p><a href="javascript:" id="notificate">Enable notifications</a></p>';
$("#notificate").on("click", e => Notification.requestPermission().then(renderActions)); // i'm lazy
}
if (listenVisible) {
if (mcIdUsername != null && mcauth_code != null) {
addAction("Listen to " + mcIdUsername, () => {
@ -435,8 +439,7 @@ $(() => {
// Heroku sleeps in 30 minutes, let's call it every 10 minutes to keep the same address, so Mojang see it as less suspect
setInterval(refreshCorsStatus, 10 * 60 * 1000);
refreshCorsStatus();
$("#notificate").on("click", e => Notification.requestPermission());
resetHtml();
connect();
});

View File

@ -62,7 +62,6 @@
<p>WebSocket connection status: <span id="connection_status" class="text-white bg-dark">?</span></p>
<p>CORS Proxy status: <span id="cors_status" class="text-white bg-dark">?</span></p>
<hr>
<p><a href="javascript:" id="notificate">Enable notifications</a></p>
<p><span id="actions"></span></p>
<p><span id="listening"></span></p>
</div>

View File

@ -1,8 +1,8 @@
// https://stackoverflow.com/questions/42127148/service-worker-communicate-to-clients
let viac = new BroadcastChannel('viaaas-notification');
let viac = new BroadcastChannel("viaaas-notification");
self.addEventListener("notificationclick", event => {
console.log("On notification click: " + event);
event.preventDefault();
event.notification.close();
viac.postMessage({tag: event.notification.tag, action: event.action});
});