INNER CODE UNIT · TypeScript

getNotificationPermission

radzionc/radzionkit · lib/ui/notifications/utils/index.ts:1

export const getNotificationPermission = () => window?.Notification?.permission

export const areNotificationsAllowed = () =>
  getNotificationPermission() === 'granted'

export const areNotificationsBlocked = () =>
  getNotificationPermission() === 'denied'

export const showNotification = (text: string) => {
  if (!areNotificationsAllowed()) return

  const notification = new window.Notification(text)
  notification.onclick = function () {
    window.focus()
    notification.close()
  }
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…