mirror of
https://github.com/BlowaterNostr/blowater.git
synced 2024-10-18 15:43:20 +00:00
26 lines
838 B
TypeScript
26 lines
838 B
TypeScript
export async function notify(title: string, msg: string, icon: string, onclick: () => void) {
|
|
try {
|
|
if (Notification.permission == "denied") {
|
|
console.warn(`Notification.permission == "denied"`);
|
|
return;
|
|
} else if (Notification.permission !== "granted") {
|
|
const result = await Notification.requestPermission();
|
|
if (result != "granted") {
|
|
console.warn(`the user denied the request: ${result}`);
|
|
}
|
|
return;
|
|
}
|
|
const notification = new Notification(title, {
|
|
body: msg,
|
|
icon: icon,
|
|
});
|
|
notification.onclick = (_) => {
|
|
window.parent.parent.focus();
|
|
notification.close();
|
|
onclick();
|
|
};
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|