Skip to content

Commit

Permalink
catch notification variable error
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbura committed Feb 10, 2025
1 parent e3efde0 commit 95e28ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/app/hooks/usePermission.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useEffect, useState } from 'react';

export const getNotificationState = (): PermissionState => {
if ('Notification' in window) {
try {
if (window.Notification.permission === 'default') {
return 'prompt';
}

return window.Notification.permission;
} catch {
return 'denied';
}

return 'denied';
};

export function usePermissionState(name: PermissionName, initialValue: PermissionState = 'prompt') {
Expand Down
5 changes: 3 additions & 2 deletions src/app/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ export const syntaxErrorPosition = (error: SyntaxError): number | undefined => {
};

export const notificationPermission = (permission: NotificationPermission) => {
if ('Notification' in window) {
try {
return window.Notification.permission === permission;
} catch {
return false;
}
return false;
};

0 comments on commit 95e28ca

Please sign in to comment.