claude-code

This commit is contained in:
ashutoshpythoncs@gmail.com
2026-03-31 18:58:05 +05:30
parent a2a44a5841
commit b564857c0b
2148 changed files with 564518 additions and 2 deletions

View File

@@ -0,0 +1,50 @@
export interface BrowserNotificationOptions {
title: string;
body?: string;
onClick?: () => void;
}
class BrowserNotificationService {
async requestPermission(): Promise<boolean> {
if (typeof window === "undefined") return false;
if (!("Notification" in window)) return false;
if (Notification.permission === "granted") return true;
if (Notification.permission === "denied") return false;
const result = await Notification.requestPermission();
return result === "granted";
}
async send(options: BrowserNotificationOptions): Promise<void> {
if (typeof window === "undefined") return;
if (!("Notification" in window)) return;
// Only notify when the tab is in the background
if (!document.hidden) return;
const granted = await this.requestPermission();
if (!granted) return;
const n = new Notification(options.title, {
body: options.body,
icon: "/favicon.ico",
});
n.onclick = () => {
window.focus();
options.onClick?.();
n.close();
};
}
getPermission(): NotificationPermission {
if (typeof window === "undefined") return "default";
if (!("Notification" in window)) return "denied";
return Notification.permission;
}
isSupported(): boolean {
return typeof window !== "undefined" && "Notification" in window;
}
}
export const browserNotifications = new BrowserNotificationService();