mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 23:30:28 +03:00
Add Desktop notifications (#252)
* Add notifications * Abide push actions * Handle browsers not having notification support * Ask for notification permission after loading * Make usePermission work without live permission support * Focus message when clicking the notification * make const all caps * Fix usePermission error in Safari * Fix live permissions * Remove userActivity and use document.visibilityState instead * Change setting label to "desktop notifications" * Check for notification permissions in the settings.js
This commit is contained in:
parent
d0b4e092b3
commit
c828dfd596
7 changed files with 174 additions and 15 deletions
28
src/app/hooks/usePermission.js
Normal file
28
src/app/hooks/usePermission.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* eslint-disable import/prefer-default-export */
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export function usePermission(name, initial) {
|
||||
const [state, setState] = useState(initial);
|
||||
|
||||
useEffect(() => {
|
||||
let descriptor;
|
||||
|
||||
const update = () => setState(descriptor.state);
|
||||
|
||||
if (navigator.permissions?.query) {
|
||||
navigator.permissions.query({ name }).then((_descriptor) => {
|
||||
descriptor = _descriptor;
|
||||
|
||||
update();
|
||||
descriptor.addEventListener('change', update);
|
||||
});
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (descriptor) descriptor.removeEventListener('change', update);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [state, setState];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue