puck / frontend /src /lib /notify.ts
vu1n's picture
Puck — desktop fairy familiar (HF Build Small)
3c124f3
Raw
History Blame Contribute Delete
898 Bytes
// System notifications for when the tab is buried — the bridge to real
// desktop usage until the Tauri overlay exists. Click = engagement,
// which the caller records as a clicked_through outcome.
export function notifyPermission(): NotificationPermission | "unsupported" {
return "Notification" in window ? Notification.permission : "unsupported";
}
/** Must be called from a user gesture (settings toggle). */
export async function requestNotifyPermission(): Promise<boolean> {
if (!("Notification" in window)) return false;
return (await Notification.requestPermission()) === "granted";
}
export function osNotify(body: string, onClick: () => void): void {
if (!("Notification" in window) || Notification.permission !== "granted") return;
const n = new Notification("Puck", { body, silent: true });
n.onclick = () => {
window.focus();
onClick();
n.close();
};
}