Merge branch 'handle-service-worker-registration-firefox-privacy' into 'master'

Handle service worker registration with Firefox « forget all site data »

Closes #819

See merge request framasoft/mobilizon!1022
This commit is contained in:
Thomas Citharel 2021-08-11 10:05:32 +00:00
commit 9ec91c8796

View File

@ -686,10 +686,15 @@ export default class Notifications extends Vue {
} }
async checkCanShowWebPush(): Promise<boolean> { async checkCanShowWebPush(): Promise<boolean> {
if (!window.isSecureContext || !("serviceWorker" in navigator)) try {
if (!window.isSecureContext || !("serviceWorker" in navigator))
return Promise.resolve(false);
const registration = await navigator.serviceWorker.getRegistration();
return registration !== undefined;
} catch (e) {
console.error(e);
return Promise.resolve(false); return Promise.resolve(false);
const registration = await navigator.serviceWorker.getRegistration(); }
return registration !== undefined;
} }
async created(): Promise<void> { async created(): Promise<void> {
@ -713,9 +718,14 @@ export default class Notifications extends Vue {
} }
private async isSubscribed(): Promise<boolean> { private async isSubscribed(): Promise<boolean> {
if (!("serviceWorker" in navigator)) return Promise.resolve(false); try {
const registration = await navigator.serviceWorker.getRegistration(); if (!("serviceWorker" in navigator)) return Promise.resolve(false);
return (await registration?.pushManager?.getSubscription()) != null; const registration = await navigator.serviceWorker.getRegistration();
return (await registration?.pushManager?.getSubscription()) != null;
} catch (e) {
console.error(e);
return Promise.resolve(false);
}
} }
private async deleteFeedToken(token: string): Promise<void> { private async deleteFeedToken(token: string): Promise<void> {