Files
custum-hyprpanel/modules/notifications/index.ts
Jas Singh f624153eab Added pagination to the notifications menu and a configurable limit to the amount of notifications spawned. (#199)
* Added notification pagination and pagination configuration options. fixes #171

* Added skip to end buttons

* Update theme

* Removed unused theme parts

* Update pager colors

* Theme auto-generator

* Update label color in options for pager.

* Updated themes

* Added option to change footer background for notifications menu.

* Changes to the Displayed Total options now update the menu. Bugfix
2024-08-30 01:32:11 -07:00

73 lines
2.7 KiB
TypeScript

const notifs = await Service.import("notifications");
import options from "options";
import { notifHasImg } from "../menus/notifications/utils.js";
import { Image } from "./image/index.js";
import { Action } from "./actions/index.js";
import { Header } from "./header/index.js";
import { Body } from "./body/index.js";
import { CloseButton } from "./close/index.js";
import { getPosition } from "lib/utils.js";
const hyprland = await Service.import("hyprland");
const { position, timeout, cache_actions, monitor, active_monitor, displayedTotal } = options.notifications;
const curMonitor = Variable(monitor.value);
hyprland.active.connect("changed", () => {
curMonitor.value = hyprland.active.monitor.id;
})
export default () => {
Utils.merge([timeout.bind("value"), cache_actions.bind("value")], (timeout, doCaching) => {
notifs.popupTimeout = timeout;
notifs.cacheActions = doCaching;
});
return Widget.Window({
name: "notifications-window",
class_name: "notifications-window",
monitor: Utils.merge([
curMonitor.bind("value"),
monitor.bind("value"),
active_monitor.bind("value")], (curMon, mon, activeMonitor) => {
if (activeMonitor === true) {
return curMon;
}
return mon;
}
),
layer: "overlay",
anchor: position.bind("value").as(v => getPosition(v)),
exclusivity: "normal",
child: Widget.Box({
class_name: "notification-card-container",
vertical: true,
hexpand: true,
setup: (self) => {
self.hook(notifs, () => {
return (self.children = notifs.popups.slice(0, displayedTotal.value).map((notif) => {
return Widget.Box({
class_name: "notification-card",
vpack: "start",
hexpand: true,
children: [
Image(notif),
Widget.Box({
vpack: "start",
vertical: true,
hexpand: true,
class_name: `notification-card-content ${!notifHasImg(notif) ? "noimg" : ""}`,
children: [Header(notif), Body(notif), Action(notif, notifs)],
}),
CloseButton(notif, notifs),
],
});
}));
});
},
}),
});
};