fix missing check for Notification

This commit is contained in:
Ajay Bura 2025-02-10 15:27:24 +05:30
parent 95e28caf38
commit c4a132d4dd
3 changed files with 8 additions and 9 deletions

View file

@ -38,9 +38,9 @@ function SystemNotification() {
description={ description={
notifPermission === 'denied' ? ( notifPermission === 'denied' ? (
<Text as="span" style={{ color: color.Critical.Main }} size="T200"> <Text as="span" style={{ color: color.Critical.Main }} size="T200">
{!Notification {'Notification' in window
? 'Notifications are not supported by the system.' ? 'Notification permission is blocked. Please allow notification permission from browser address bar.'
: 'Notification permission is blocked. Please allow notification permission from browser address bar.'} : 'Notifications are not supported by the system.'}
</Text> </Text>
) : ( ) : (
<span>Show desktop notifications when message arrive.</span> <span>Show desktop notifications when message arrive.</span>

View file

@ -1,15 +1,15 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
export const getNotificationState = (): PermissionState => { export const getNotificationState = (): PermissionState => {
try { if ('Notification' in window) {
if (window.Notification.permission === 'default') { if (window.Notification.permission === 'default') {
return 'prompt'; return 'prompt';
} }
return window.Notification.permission; return window.Notification.permission;
} catch {
return 'denied';
} }
return 'denied';
}; };
export function usePermissionState(name: PermissionName, initialValue: PermissionState = 'prompt') { export function usePermissionState(name: PermissionName, initialValue: PermissionState = 'prompt') {

View file

@ -219,9 +219,8 @@ export const syntaxErrorPosition = (error: SyntaxError): number | undefined => {
}; };
export const notificationPermission = (permission: NotificationPermission) => { export const notificationPermission = (permission: NotificationPermission) => {
try { if ('Notification' in window) {
return window.Notification.permission === permission; return window.Notification.permission === permission;
} catch {
return false;
} }
return false;
}; };