fix push changes
This commit is contained in:
parent
e6e3ab0374
commit
6ab94bb3cd
@ -6,16 +6,10 @@ function checkServiceWorkerSupport() {
|
||||
async function isPushRegistered() {
|
||||
checkServiceWorkerSupport();
|
||||
try {
|
||||
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||
if (!registrations || registrations.length === 0) return false;
|
||||
|
||||
for (let reg of registrations) {
|
||||
const subscription = await reg.pushManager.getSubscription();
|
||||
if (subscription) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
const reg = await navigator.serviceWorker.ready;
|
||||
const sub = await reg.pushManager.getSubscription();
|
||||
return !!sub;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -23,18 +17,19 @@ async function isPushRegistered() {
|
||||
async function unregisterPush() {
|
||||
checkServiceWorkerSupport();
|
||||
try {
|
||||
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||
if (!registrations || registrations.length === 0) return;
|
||||
const reg = await navigator.serviceWorker.ready;
|
||||
const sub = await reg.pushManager.getSubscription();
|
||||
|
||||
for (let i = 0; i < registrations.length; i++) {
|
||||
const reg = registrations[i];
|
||||
const sub = await reg.pushManager.getSubscription();
|
||||
|
||||
if (sub) await sub.unsubscribe();
|
||||
if (sub) {
|
||||
await sub.unsubscribe();
|
||||
}
|
||||
|
||||
if (!window.isIOS()) {
|
||||
await reg.unregister();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to unregister push:", err);
|
||||
alert("Failed to unregister push");
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -37,4 +37,12 @@ self.addEventListener("notificationclick", (event) => {
|
||||
return clients.openWindow(targetUrl);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("install", () => {
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(self.clients.claim());
|
||||
});
|
||||
@ -16,10 +16,6 @@
|
||||
"hsl(139, calc(var(--saturation-factor, 1) * 47.3%), 43.9%)": "#43B581", // Online (green)
|
||||
};
|
||||
|
||||
const IS_MOBILE = window
|
||||
.matchMedia("(pointer: coarse)")
|
||||
.matches;
|
||||
|
||||
const TAB_CONTENT = `
|
||||
<h2 class="${CSS_CLASSES.title}">RSCord Settings</h2>
|
||||
<h5 class="${CSS_CLASSES.miniTitle}" style="margin-bottom: 10px">Options</h5>
|
||||
@ -221,7 +217,7 @@
|
||||
|
||||
document.body.addEventListener("click", (e) => {
|
||||
const clickedHamburger = e.target.closest(`.${CSS_CLASSES.hamburger}`)
|
||||
if (clickedHamburger && IS_MOBILE) {
|
||||
if (clickedHamburger && window.IS_MOBILE) {
|
||||
const settingsRegion = document.querySelector(`.${CSS_CLASSES.settingsRegion}`)
|
||||
settingsRegion.classList.remove(CSS_CLASSES.hidden);
|
||||
|
||||
@ -249,7 +245,7 @@
|
||||
child.style.display = "none";
|
||||
}
|
||||
|
||||
if (IS_MOBILE) {
|
||||
if (window.IS_MOBILE) {
|
||||
const settingsRegion = document.querySelector(`.${CSS_CLASSES.settingsRegion}`)
|
||||
settingsRegion.classList.add(CSS_CLASSES.hidden);
|
||||
|
||||
|
||||
@ -33,10 +33,13 @@
|
||||
window.GLOBAL_ENV = {};
|
||||
window.__OVERLAY__ = /overlay/.test(location.pathname)
|
||||
window.__BILLING_STANDALONE__ = /^\/billing/.test(location.pathname)
|
||||
|
||||
|
||||
window.AUTH_TOKEN = null;
|
||||
window.localStorage_ = localStorage;
|
||||
|
||||
window.IS_IOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
|
||||
window.IS_MOBILE = window.matchMedia("(pointer: coarse)").matches;
|
||||
|
||||
function protocolRelative(url) {
|
||||
if (!url) return "";
|
||||
return "//" + url.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
||||
|
||||
Reference in New Issue
Block a user