2026-02-24 13:18:48 +02:00
|
|
|
import type { NotificationPayload, NotificationsAPI } from '@openchamber/ui/lib/api/types';
|
|
|
|
|
|
2026-05-19 02:06:32 +03:00
|
|
|
const showWebviewNotification = async (payload?: NotificationPayload): Promise<boolean> => {
|
|
|
|
|
if (typeof Notification === 'undefined') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Notification.permission === 'default') {
|
|
|
|
|
const permission = await Notification.requestPermission();
|
|
|
|
|
if (permission !== 'granted') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Notification.permission !== 'granted') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const title = typeof payload?.title === 'string' && payload.title.trim().length > 0
|
|
|
|
|
? payload.title.trim()
|
|
|
|
|
: 'OpenChamber';
|
|
|
|
|
const body = typeof payload?.body === 'string' ? payload.body : '';
|
|
|
|
|
|
|
|
|
|
new Notification(title, { body });
|
|
|
|
|
return true;
|
|
|
|
|
};
|
2026-02-24 13:18:48 +02:00
|
|
|
|
|
|
|
|
export const createVSCodeNotificationsAPI = (): NotificationsAPI => ({
|
|
|
|
|
async notifyAgentCompletion(payload?: NotificationPayload): Promise<boolean> {
|
|
|
|
|
try {
|
2026-05-19 02:06:32 +03:00
|
|
|
return await showWebviewNotification(payload);
|
2026-02-24 13:18:48 +02:00
|
|
|
} catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async canNotify(): Promise<boolean> {
|
2026-05-19 02:06:32 +03:00
|
|
|
return typeof Notification !== 'undefined' && Notification.permission !== 'denied';
|
2026-02-24 13:18:48 +02:00
|
|
|
},
|
|
|
|
|
});
|