import { GLib } from "astal" import { Gtk, Astal } from "astal/gtk3" import { type EventBox } from "astal/gtk3/widget" import Notifd from "gi://AstalNotifd" const isIcon = (icon: string) => !!Astal.Icon.lookup_icon(icon) const fileExists = (path: string) => GLib.file_test(path, GLib.FileTest.EXISTS) const time = (time: number, format = "%H:%M") => GLib.DateTime .new_from_unix_local(time) .format(format)! const urgency = (n: Notifd.Notification) => { const { LOW, NORMAL, CRITICAL } = Notifd.Urgency // match operator when? switch (n.urgency) { case LOW: return "low" case CRITICAL: return "critical" case NORMAL: default: return "normal" } } type Props = { setup(self: EventBox): void onHoverLost(self: EventBox): void notification: Notifd.Notification } export default function Notification(props: Props) { const { notification: n, onHoverLost, setup } = props const { START, CENTER, END } = Gtk.Align return {(n.appIcon || n.desktopEntry) && } {n.image && fileExists(n.image) && } {n.image && isIcon(n.image) && } {n.get_actions().length > 0 && {n.get_actions().map(({ label, id }) => ( ))} } }