| import { logoPath } from "@/Core/GlobalVars"; |
| import { toSentenceCase } from "@/Core/Utils/StringUtils"; |
| |
| |
| |
| |
| |
| |
| |
| export async function showSystemNotification(title: string, body: string) { |
| if (!("Notification" in window)) { |
| console.log("This browser does not support desktop notification"); |
| return; |
| } |
| const show = () => { |
| |
| const parser = new DOMParser(); |
| const doc = parser.parseFromString(body, "text/html"); |
| const plainTextBody = doc.body.textContent || ""; |
| const notification = new Notification(toSentenceCase(title), { |
| body: plainTextBody, |
| icon: logoPath, |
| }); |
| |
| notification.onclick = () => { |
| window.focus(); |
| notification.close(); |
| }; |
| }; |
| let {permission} = Notification; |
| if (permission === "default") { |
| try { |
| permission = await Notification.requestPermission(); |
| } catch (error) { |
| console.error("Error requesting notification permission:", error); |
| return; |
| } |
| } |
| if (permission === "granted") { |
| show(); |
| } |
| } |
|
|
| |
| |
| |
|
|
|
|