diff --git a/app/page.tsx b/app/page.tsx index d35290b..b3ec60a 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -22,6 +22,37 @@ export default function Home() { setSidebarOpen, } = useStore(); + // SSE — listen for dream notifications + const sseRef = useRef(null); + useEffect(() => { + function connect() { + const es = new EventSource('/api/events'); + sseRef.current = es; + es.onmessage = (e) => { + try { + const data = JSON.parse(e.data); + if (data.type === 'dream') { + if ('Notification' in window && Notification.permission === 'granted') { + new Notification('Bird dreamed', { + body: `${data.mode?.toUpperCase()} dream delivered — ${data.filename}`, + icon: '/icon-192.png', + }); + } + } + } catch {} + }; + es.onerror = () => { + es.close(); + setTimeout(connect, 10000); + }; + } + if ('Notification' in window) { + Notification.requestPermission(); + } + connect(); + return () => sseRef.current?.close(); + }, []); + useEffect(() => { api.getSettings().then(s => { setSettings(s);