♻️ (notification)

This commit is contained in:
2021-02-28 17:26:36 +01:00
parent 2cc22b29f1
commit 7039c86b4f

View File

@@ -9,22 +9,17 @@ export const setNotificationInstance = (sn: ShowNotification) => {
showNotification = sn showNotification = sn
} }
export const notify: ShowNotification = async ( export const notify: ShowNotification = async (title, options?) => {
title: string, const showCustomNotification = async () => {
options?: NotificationOptions
) => {
const showCustomNotification = (
title: string,
options?: NotificationOptions
) => {
if (!showNotification) { if (!showNotification) {
return return
} }
showNotification(title, { await showNotification(title, {
icon: '/img/icons/apple-touch-icon.png', icon: '/img/icons/apple-touch-icon.png',
badge: '/img/badge.png', badge: '/img/badge.png',
tag: 'binome', tag: 'binome',
renotify: true, renotify: true,
silent: true,
...options ...options
}) })
} }
@@ -35,7 +30,7 @@ export const notify: ShowNotification = async (
} }
if (Notification.permission === 'granted') { if (Notification.permission === 'granted') {
showCustomNotification(title, options) showCustomNotification()
return return
} }
@@ -43,7 +38,7 @@ export const notify: ShowNotification = async (
const permission = await Notification.requestPermission() const permission = await Notification.requestPermission()
if (permission === 'granted') { if (permission === 'granted') {
showCustomNotification(title, options) showCustomNotification()
} }
} }
} catch (error) { } catch (error) {