The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/views/root/hooks/useNotificationPermission.ts

21 lines
696 B

import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
import { notificationManager } from '../../../lib/notificationManager';
export const useNotificationPermission = () => {
const requestPermission = useEffectEvent(async () => {
const response = await Notification.requestPermission();
notificationManager.allowed = response === 'granted';
notificationManager.emit('change');
const notifications = await navigator.permissions.query({ name: 'notifications' });
notifications.onchange = () => {
notificationManager.allowed = notifications.state === 'granted';
notificationManager.emit('change');
};
});
if ('Notification' in window) {
requestPermission();
}
};