🐛 (notification) fix notification
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="dream-maker">
|
<div class="dream-maker">
|
||||||
<h2>code {{ position }}</h2>
|
<h2>dev {{ position }}</h2>
|
||||||
<h4 v-show="isTurn">{{ session }}</h4>
|
<h4 v-show="isTurn">{{ session }}</h4>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
import { register } from 'register-service-worker'
|
import { register } from 'register-service-worker'
|
||||||
|
import { setNotificationInstance } from './utils/notification'
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||||
ready(sw) {
|
ready(sw) {
|
||||||
console.log('App is being served from cache by a service worker')
|
console.log('App is being served from cache by a service worker')
|
||||||
sw.showNotification('Session started!', {
|
setNotificationInstance(sw.showNotification)
|
||||||
vibrate: [300, 100, 400]
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
registered() {
|
registered() {
|
||||||
console.log('Service worker has been registered.')
|
console.log('Service worker has been registered.')
|
||||||
@@ -21,6 +20,7 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
},
|
},
|
||||||
updated() {
|
updated() {
|
||||||
console.log('New content is available; please refresh.')
|
console.log('New content is available; please refresh.')
|
||||||
|
location.reload(true)
|
||||||
},
|
},
|
||||||
offline() {
|
offline() {
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
@@ -1,19 +1,46 @@
|
|||||||
declare const Notification: any
|
declare const Notification: any
|
||||||
|
|
||||||
export const notify = (message: string) => {
|
let showNotification:
|
||||||
|
| ((
|
||||||
|
title: string,
|
||||||
|
options?: NotificationOptions | undefined
|
||||||
|
) => Promise<void>)
|
||||||
|
| null = null
|
||||||
|
|
||||||
|
export const setNotificationInstance = (
|
||||||
|
sn: (
|
||||||
|
title: string,
|
||||||
|
options?: NotificationOptions | undefined
|
||||||
|
) => Promise<void>
|
||||||
|
) => {
|
||||||
|
showNotification = sn
|
||||||
|
}
|
||||||
|
|
||||||
|
export const notify = (
|
||||||
|
title: string,
|
||||||
|
options?: NotificationOptions | undefined
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
|
console.log(showNotification)
|
||||||
|
|
||||||
|
if (!showNotification) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!('Notification' in window)) {
|
if (!('Notification' in window)) {
|
||||||
return
|
return
|
||||||
} else if (Notification.permission === 'granted') {
|
} else if (Notification.permission === 'granted') {
|
||||||
new Notification(message)
|
showNotification(title, options)
|
||||||
} else if (Notification.permission !== 'denied') {
|
} else if (Notification.permission !== 'denied') {
|
||||||
Notification.requestPermission((permission: any) => {
|
Notification.requestPermission((permission: any) => {
|
||||||
|
if (!showNotification) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!('permission' in Notification)) {
|
if (!('permission' in Notification)) {
|
||||||
Notification.permission = permission
|
Notification.permission = permission
|
||||||
}
|
}
|
||||||
|
|
||||||
if (permission === 'granted') {
|
if (permission === 'granted') {
|
||||||
new Notification(message)
|
showNotification(title, options)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export default defineComponent({
|
|||||||
? 'Programmer 1'
|
? 'Programmer 1'
|
||||||
: 'Programmer 2'
|
: 'Programmer 2'
|
||||||
|
|
||||||
notify(`Time to change, ${programmer}, your turn!`)
|
notify('Time to change', { body: `${programmer}, your turn!` })
|
||||||
}
|
}
|
||||||
}, 1000)
|
}, 1000)
|
||||||
stopWatchSessionId = setInterval(() => {
|
stopWatchSessionId = setInterval(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user