From 31ece1083a076d59e737a1f51dd272f0d745fe0f Mon Sep 17 00:00:00 2001 From: matt1432 Date: Thu, 14 Sep 2023 17:24:02 -0400 Subject: [PATCH] feat(ags): allow defining notif command at instantiation --- config/ags/js/notifications/base.js | 4 ++-- config/ags/js/notifications/center.js | 7 +++++-- config/ags/js/notifications/popup.js | 15 +++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/config/ags/js/notifications/base.js b/config/ags/js/notifications/base.js index 956aa99..ed61ccb 100644 --- a/config/ags/js/notifications/base.js +++ b/config/ags/js/notifications/base.js @@ -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, - command: () => Notifications.close(id), + command: () => command(id), properties: [['hovered', false]], onHover: w => { if (!w._hovered) { diff --git a/config/ags/js/notifications/center.js b/config/ags/js/notifications/center.js index 149f335..7f9686d 100644 --- a/config/ags/js/notifications/center.js +++ b/config/ags/js/notifications/center.js @@ -37,10 +37,13 @@ const NotificationList = () => Box({ if (box.children.length == 0) { box.children = Notifications.notifications .reverse() - .map(n => Notification(n)); + .map(n => Notification({ ...n, command: i => Notifications.close(i), })); } else if (id) { - box.add(Notification(Notifications.getNotification(id))); + box.add(Notification({ + ...Notifications.getNotification(id), + command: i => Notifications.close(i), + })); box.show_all(); } diff --git a/config/ags/js/notifications/popup.js b/config/ags/js/notifications/popup.js index 7854036..d30c036 100644 --- a/config/ags/js/notifications/popup.js +++ b/config/ags/js/notifications/popup.js @@ -19,7 +19,9 @@ const Popups = () => Box({ box.get_parent().reveal_child = false; 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.delete(id); }); @@ -29,7 +31,12 @@ const Popups = () => Box({ return; 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(); timeout(10, () => { box.get_parent().revealChild = true; @@ -38,8 +45,8 @@ const Popups = () => Box({ if (!box._map.get(id)._hovered) { box._map.get(id).child.setStyle(box._map.get(id).child._leftAnim); - if (box._map.get(id)?.interval) { - source_remove(box._map.get(id)?.interval); + if (box._map.get(id).interval) { + source_remove(box._map.get(id).interval); } } });