feat(ags): allow defining notif command at instantiation

This commit is contained in:
matt1432 2023-09-14 17:24:02 -04:00
parent bc3e5525c3
commit 31ece1083a
3 changed files with 18 additions and 8 deletions

View file

@ -51,9 +51,9 @@ const NotificationIcon = ({ appEntry, appIcon, image }) => {
}); });
}; };
export default ({ id, summary, body, actions, urgency, time, ...icon }) => Draggable({ export default ({ id, summary, body, actions, urgency, time, command = i => {}, ...icon }) => Draggable({
maxOffset: 200, maxOffset: 200,
command: () => Notifications.close(id), command: () => command(id),
properties: [['hovered', false]], properties: [['hovered', false]],
onHover: w => { onHover: w => {
if (!w._hovered) { if (!w._hovered) {

View file

@ -37,10 +37,13 @@ const NotificationList = () => Box({
if (box.children.length == 0) { if (box.children.length == 0) {
box.children = Notifications.notifications box.children = Notifications.notifications
.reverse() .reverse()
.map(n => Notification(n)); .map(n => Notification({ ...n, command: i => Notifications.close(i), }));
} }
else if (id) { else if (id) {
box.add(Notification(Notifications.getNotification(id))); box.add(Notification({
...Notifications.getNotification(id),
command: i => Notifications.close(i),
}));
box.show_all(); box.show_all();
} }

View file

@ -19,7 +19,9 @@ const Popups = () => Box({
box.get_parent().reveal_child = false; box.get_parent().reveal_child = false;
timeout(200, () => { timeout(200, () => {
source_remove(box._map.get(id)?.interval); if (box._map.get(id).interval) {
source_remove(box._map.get(id).interval);
}
box._map.get(id)?.destroy(); box._map.get(id)?.destroy();
box._map.delete(id); box._map.delete(id);
}); });
@ -29,7 +31,12 @@ const Popups = () => Box({
return; return;
box._map.delete(id); box._map.delete(id);
box._map.set(id, Notification(Notifications.getNotification(id)));
box._map.set(id, Notification({
...Notifications.getNotification(id),
command: i => Notifications.dismiss(i),
}));
box.children = Array.from(box._map.values()).reverse(); box.children = Array.from(box._map.values()).reverse();
timeout(10, () => { timeout(10, () => {
box.get_parent().revealChild = true; box.get_parent().revealChild = true;
@ -38,8 +45,8 @@ const Popups = () => Box({
if (!box._map.get(id)._hovered) { if (!box._map.get(id)._hovered) {
box._map.get(id).child.setStyle(box._map.get(id).child._leftAnim); box._map.get(id).child.setStyle(box._map.get(id).child._leftAnim);
if (box._map.get(id)?.interval) { if (box._map.get(id).interval) {
source_remove(box._map.get(id)?.interval); source_remove(box._map.get(id).interval);
} }
} }
}); });