import { Gtk, Gdk } from "ags/gtk4"; import Adw from "gi://Adw"; import GLib from "gi://GLib"; import AstalNotifd from "gi://AstalNotifd"; import Pango from "gi://Pango"; import { timeout } from "ags/time"; function isIcon(icon?: string | null) { const iconTheme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default()!); return icon && iconTheme.has_icon(icon); } function fileExists(path: string) { return GLib.file_test(path, GLib.FileTest.EXISTS); } function time(time: number, format = "%H:%M") { return GLib.DateTime.new_from_unix_local(time).format(format)!; } function urgency(n: AstalNotifd.Notification) { const { LOW, NORMAL, CRITICAL } = AstalNotifd.Urgency; switch (n.urgency) { case LOW: return "low"; case CRITICAL: return "critical"; case NORMAL: default: return "normal"; } } export default function Notification({ notification: n, onHoverLost, }: { notification: AstalNotifd.Notification; onHoverLost: () => void; }) { const timer = timeout(3000, () => { onHoverLost(); }); return ( timer.cancel()} onLeave={onHoverLost} /> {(n.appIcon || isIcon(n.desktopEntry)) && ( )} {n.image && fileExists(n.image) && ( )} {n.image && isIcon(n.image) && ( )} {n.actions.length > 0 && ( {n.actions.map(({ label, id }) => ( ))} )} ); }