mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-11-22 12:05:45 +01:00
use broadcastchannel
This commit is contained in:
parent
c6a0496927
commit
ab67c699b8
@ -1,4 +1,6 @@
|
||||
navigator.serviceWorker.register("sw.js");
|
||||
// SW
|
||||
navigator.serviceWorker.register("sw.js")
|
||||
new BroadcastChannel('viaaas-notification').addEventListener("message", e => handleSWMsg(e));
|
||||
|
||||
// Minecraft.id
|
||||
let urlParams = new URLSearchParams();
|
||||
@ -296,7 +298,6 @@ function handleSWMsg(event) {
|
||||
if (callback == null) return;
|
||||
callback(data.action);
|
||||
}
|
||||
navigator.serviceWorker.addEventListener("message", handleSWMsg);
|
||||
function authNotification(msg, yes, no) {
|
||||
if ((!pageBlur && !document.hidden) || Notification.permission != "granted") {
|
||||
if (confirm(msg)) yes(); else no();
|
||||
|
@ -1,6 +1,8 @@
|
||||
// https://stackoverflow.com/questions/42127148/service-worker-communicate-to-clients
|
||||
let viac = new BroadcastChannel('viaaas-notification');
|
||||
self.addEventListener("notificationclick", event => {
|
||||
console.log("On notification click: " + event);
|
||||
event.preventDefault();
|
||||
event.notification.close();
|
||||
self.clients.matchAll({type: "window"}).then(it => it.forEach(c => c.postMessage({tag: event.notification.tag, action: event.action})));
|
||||
viac.postMessage({tag: event.notification.tag, action: event.action});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user