don't communicate with serviceworker if there's no support for it

This commit is contained in:
Henry Jameson 2023-11-22 21:38:54 +02:00
parent 33564d8ccc
commit a5f09b7263

View File

@ -98,12 +98,14 @@ export async function initServiceWorker (store) {
} }
export async function showDesktopNotification (content) { export async function showDesktopNotification (content) {
if (!isSWSupported) return
const { active: sw } = await window.navigator.serviceWorker.getRegistration() const { active: sw } = await window.navigator.serviceWorker.getRegistration()
if (!sw) return console.error('No serviceworker found!') if (!sw) return console.error('No serviceworker found!')
sw.postMessage({ type: 'desktopNotification', content }) sw.postMessage({ type: 'desktopNotification', content })
} }
export async function closeDesktopNotification ({ id }) { export async function closeDesktopNotification ({ id }) {
if (!isSWSupported) return
const { active: sw } = await window.navigator.serviceWorker.getRegistration() const { active: sw } = await window.navigator.serviceWorker.getRegistration()
if (!sw) return console.error('No serviceworker found!') if (!sw) return console.error('No serviceworker found!')
if (id >= 0) { if (id >= 0) {
@ -114,6 +116,7 @@ export async function closeDesktopNotification ({ id }) {
} }
export async function updateFocus () { export async function updateFocus () {
if (!isSWSupported) return
const { active: sw } = await window.navigator.serviceWorker.getRegistration() const { active: sw } = await window.navigator.serviceWorker.getRegistration()
if (!sw) return console.error('No serviceworker found!') if (!sw) return console.error('No serviceworker found!')
sw.postMessage({ type: 'updateFocus' }) sw.postMessage({ type: 'updateFocus' })