From 1562a4696d97d7976f72ae4aae3bfbca471a20d2 Mon Sep 17 00:00:00 2001 From: Xeovalyte Date: Tue, 4 Oct 2022 17:06:49 +0200 Subject: [PATCH] small changes --- frontend/app.vue | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/frontend/app.vue b/frontend/app.vue index fbb6710..a6764d4 100644 --- a/frontend/app.vue +++ b/frontend/app.vue @@ -43,24 +43,10 @@ onMounted(() => { if (process.client) { if ('serviceWorker' in navigator && window.isSecureContext) { - messaging.value = getMessaging() - navigator.serviceWorker.register('/sw.js').catch(e => alert(e)); - - onMessage(messaging.value, (payload) => { - console.log('Message received. ', payload); - - const { show } = useWebNotification({ - title: payload.notification.title, - body: payload.notification.body, - icon: '/ios/256.png', - dir: 'auto', - lang: 'en', - renotify: true, - tag: 'wrbapp', - }) - - show() + Device.getInfo().then(info => { + if (info.platform === 'web') registerSW() }); + } } @@ -167,6 +153,27 @@ const registerFCM = () => { }); } +const registerSW = () => { + messaging.value = getMessaging() + navigator.serviceWorker.register('/sw.js').catch(e => alert(e)); + + onMessage(messaging.value, (payload) => { + console.log('Message received. ', payload); + + const { show } = useWebNotification({ + title: payload.notification.title, + body: payload.notification.body, + icon: '/ios/256.png', + dir: 'auto', + lang: 'en', + renotify: true, + tag: 'wrbapp', + }) + + show() + }); +} + const logDeviceInfo = async () => { const info = await Device.getInfo();