From 48de7036b03a60a17cfd390c89f68dd69b3be7ac Mon Sep 17 00:00:00 2001 From: "oAnblu 194724113+oAnblu@users.noreply.github.com" <194724113+oAnblu@users.noreply.github.com> Date: Wed, 24 Dec 2025 12:35:02 +0200 Subject: [PATCH] Add host desktop notifications if ArcOS is not in focus --- .../user/daemon/contexts/notifications.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ts/server/user/daemon/contexts/notifications.ts b/src/ts/server/user/daemon/contexts/notifications.ts index 1d83e8b7..aec8ac1a 100644 --- a/src/ts/server/user/daemon/contexts/notifications.ts +++ b/src/ts/server/user/daemon/contexts/notifications.ts @@ -1,4 +1,5 @@ import { SysDispatch } from "$ts/env"; +import type { IconService } from "$ts/icon"; import type { Notification } from "$types/notification"; import type { UserDaemon } from ".."; import { UserContext } from "../context"; @@ -23,6 +24,27 @@ export class NotificationsUserContext extends UserContext { SysDispatch.dispatch("update-notifications", [this.notifications]); SysDispatch.dispatch("send-notification", [data]); + if (!document.hasFocus()) { + Notification.requestPermission().then((perm) => { + if (perm !== "granted") return; + + // there's probably a better way to do this rather than inserting a CDN link + const icon = data.icon ? `https://unpkg.com/lucide-static@latest/icons/${data.icon}.svg` : undefined; + const image = data.image + ? this.serviceHost?.getService("IconService")?.getIconCached(data.image) || data.image + : icon; + + const notif = new Notification(data.title, { body: data.message, icon: image, requireInteraction: true }); + notif.onclose = () => this.deleteNotification(id); + notif.onclick = () => { + window.focus(); + this.deleteNotification(id); + }; + + if (data.timeout) setTimeout(() => notif.close(), data.timeout); + }); + } + return id; }