From 467269d09e488338ef70ffab63b8941790024eaf Mon Sep 17 00:00:00 2001 From: Aaron Nelson Date: Sun, 26 Apr 2026 22:17:33 -0400 Subject: [PATCH] =?UTF-8?q?Add=20SSE=20push=20notifications=20=E2=80=94=20?= =?UTF-8?q?dream=20delivery=20triggers=20browser=20notification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/page.tsx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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);