mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2025-02-16 01:41:24 +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
|
// Minecraft.id
|
||||||
let urlParams = new URLSearchParams();
|
let urlParams = new URLSearchParams();
|
||||||
@ -296,7 +298,6 @@ function handleSWMsg(event) {
|
|||||||
if (callback == null) return;
|
if (callback == null) return;
|
||||||
callback(data.action);
|
callback(data.action);
|
||||||
}
|
}
|
||||||
navigator.serviceWorker.addEventListener("message", handleSWMsg);
|
|
||||||
function authNotification(msg, yes, no) {
|
function authNotification(msg, yes, no) {
|
||||||
if ((!pageBlur && !document.hidden) || Notification.permission != "granted") {
|
if ((!pageBlur && !document.hidden) || Notification.permission != "granted") {
|
||||||
if (confirm(msg)) yes(); else no();
|
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 => {
|
self.addEventListener("notificationclick", event => {
|
||||||
console.log("On notification click: " + event);
|
console.log("On notification click: " + event);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.notification.close();
|
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