mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-09 18:15:28 +00:00
Make some updates to the push notification script; not registering, test this out in prod
This commit is contained in:
@@ -26,6 +26,7 @@ export const Notifications = observer(() => {
|
|||||||
?.getRegistration()
|
?.getRegistration()
|
||||||
.then(async (registration) => {
|
.then(async (registration) => {
|
||||||
const sub = await registration?.pushManager?.getSubscription();
|
const sub = await registration?.pushManager?.getSubscription();
|
||||||
|
console.log(sub);
|
||||||
setPushEnabled(sub !== null && sub !== undefined);
|
setPushEnabled(sub !== null && sub !== undefined);
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
@@ -73,8 +74,24 @@ export const Notifications = observer(() => {
|
|||||||
}
|
}
|
||||||
onChange={async (pushEnabled) => {
|
onChange={async (pushEnabled) => {
|
||||||
try {
|
try {
|
||||||
const reg =
|
if (!("serviceWorker" in navigator)) {
|
||||||
await navigator.serviceWorker?.getRegistration();
|
return modalController.push({
|
||||||
|
type: "error",
|
||||||
|
error: "NoServiceWorker",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let reg =
|
||||||
|
await navigator.serviceWorker.getRegistration(
|
||||||
|
`${window.location.origin}/sw.js`,
|
||||||
|
);
|
||||||
|
if (!reg) {
|
||||||
|
reg =
|
||||||
|
await navigator.serviceWorker.register(
|
||||||
|
`${window.location.origin}/sw.js`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (reg) {
|
if (reg) {
|
||||||
if (pushEnabled) {
|
if (pushEnabled) {
|
||||||
const sub =
|
const sub =
|
||||||
@@ -87,6 +104,8 @@ export const Notifications = observer(() => {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(sub);
|
||||||
|
|
||||||
// tell the server we just subscribed
|
// tell the server we just subscribed
|
||||||
const json = sub.toJSON();
|
const json = sub.toJSON();
|
||||||
if (json.keys) {
|
if (json.keys) {
|
||||||
|
|||||||
Reference in New Issue
Block a user