handle no sw registration gracefully
This commit is contained in:
parent
92685e37b6
commit
33564d8ccc
@ -99,11 +99,13 @@ export async function initServiceWorker (store) {
|
|||||||
|
|
||||||
export async function showDesktopNotification (content) {
|
export async function showDesktopNotification (content) {
|
||||||
const { active: sw } = await window.navigator.serviceWorker.getRegistration()
|
const { active: sw } = await window.navigator.serviceWorker.getRegistration()
|
||||||
|
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 }) {
|
||||||
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 (id >= 0) {
|
if (id >= 0) {
|
||||||
sw.postMessage({ type: 'desktopNotificationClose', content: { id } })
|
sw.postMessage({ type: 'desktopNotificationClose', content: { id } })
|
||||||
} else {
|
} else {
|
||||||
@ -113,6 +115,7 @@ export async function closeDesktopNotification ({ id }) {
|
|||||||
|
|
||||||
export async function updateFocus () {
|
export async function updateFocus () {
|
||||||
const { active: sw } = await window.navigator.serviceWorker.getRegistration()
|
const { active: sw } = await window.navigator.serviceWorker.getRegistration()
|
||||||
|
if (!sw) return console.error('No serviceworker found!')
|
||||||
sw.postMessage({ type: 'updateFocus' })
|
sw.postMessage({ type: 'updateFocus' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user