diff --git a/src/hooks/use-notification.ts b/src/hooks/use-notification.ts index e985391b16..841a8b3852 100644 --- a/src/hooks/use-notification.ts +++ b/src/hooks/use-notification.ts @@ -10,13 +10,12 @@ let permissionGranted: boolean | null = null; const checkPermission = async () => { if (permissionGranted == null) { permissionGranted = await isPermissionGranted(); - } else if (permissionGranted == false) { + } + if (!permissionGranted) { const permission = await requestPermission(); permissionGranted = permission === "granted"; - return permissionGranted; - } else { - return permissionGranted; } + return permissionGranted; }; export type NotificationOptions = { @@ -39,15 +38,17 @@ export const useNotification = async ({ }: NotificationOptions) => { if (!title) { throw new Error("missing message argument!"); - } else if (!checkPermission()) { + } + const permissionGranted = await checkPermission(); + if (!permissionGranted) { // fallback to mui notification Notice[type](`${title} ${body ? `: ${body}` : ""}}`); // throw new Error("notification permission not granted!"); - } else { - const options: Options = { - title: title, - }; - if (body) options.body = body; - sendNotification(options); + return; } + const options: Options = { + title: title, + }; + if (body) options.body = body; + sendNotification(options); };