import { GLib, Variable } from "astal"; import { bind, Subscribable } from "astal/binding"; import { Astal, Gdk, Gtk } from "astal/gtk4"; import AstalNotifd from "gi://AstalNotifd?version=0.1"; const notificationTimeout: number = 5000; class NotificationHandler implements Subscribable { private notifications: Variable = Variable([]); private notificationsMap: Map = new Map(); constructor() { const notifd = AstalNotifd.get_default(); notifd.connect("notified", (_source, id, _replaced) => { const n = notifd.get_notification(id); this.create(n); setTimeout(() => this.remove(id), notificationTimeout); }); notifd.connect("resolved", (_source, id, _reason) => { this.remove(id); }); } private rerender() { this.notifications.set([...this.notificationsMap.values()].reverse()); } private create(n: AstalNotifd.Notification) { const notification = Notification(n); this.notificationsMap.get(n.id)?.emit("destroy"); this.notificationsMap.set(n.id, notification); this.rerender(); } private remove(id: number) { this.notificationsMap.get(id)?.emit("destroy"); this.notificationsMap.delete(id); this.rerender(); } subscribe(callback: (value: Gtk.Widget[]) => void): () => void { return this.notifications.subscribe(callback); } get(): Gtk.Widget[] { return this.notifications.get(); } } function getUrgencyClass(n: AstalNotifd.Notification): string { switch (n.urgency) { case AstalNotifd.Urgency.LOW: return "low"; case AstalNotifd.Urgency.CRITICAL: return "critical"; case AstalNotifd.Urgency.NORMAL: default: return "normal"; } } function Notification(n: AstalNotifd.Notification) { const appName = n.appName; const time = GLib.DateTime.new_from_unix_local(n.time); return {n.get_actions().length > 0 && <> {n.get_actions().map(({ label, id }) => )} } ; } export default function(gdkmonitor: Gdk.Monitor) { const { TOP, RIGHT } = Astal.WindowAnchor; const notifications = new NotificationHandler(); return v.length != 0)} name={"Notifications"} cssClasses={["Notifications"]} gdkmonitor={gdkmonitor} exclusivity={Astal.Exclusivity.EXCLUSIVE} anchor={TOP | RIGHT}> {bind(notifications)} }