From d5a9b24de1b079c98ddc830ca9400a2bd4532338 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Tue, 19 Sep 2023 10:22:08 -0400 Subject: [PATCH] feat(ags notifs): add blocked apps list --- config/ags/js/notifications/base.js | 183 ++++++++++++++------------ config/ags/js/notifications/center.js | 10 +- config/ags/js/notifications/popup.js | 3 + 3 files changed, 107 insertions(+), 89 deletions(-) diff --git a/config/ags/js/notifications/base.js b/config/ags/js/notifications/base.js index a36e6d8..abbd64a 100644 --- a/config/ags/js/notifications/base.js +++ b/config/ags/js/notifications/base.js @@ -73,93 +73,104 @@ const NotificationIcon = ({ appEntry, appIcon, image }) => { }); }; -export default ({ id, summary, body, actions, urgency, time, command = i => {}, ...icon }) => Draggable({ - maxOffset: 200, - command: () => command(id), - properties: [ - ['hovered', false], - ['id', id], - ], - onHover: w => { - if (!w._hovered) { - w._hovered = true; - } - }, - onHoverLost: w => { - if (w._hovered) { - w._hovered = false; - } - }, +export default ({ id, summary, body, actions, urgency, time, command = i => {}, ...icon }) => { + const BlockedApps = [ + 'Spotify', + ]; + + if (BlockedApps.find(app => app == Notifications.getNotification(id).appName)) { + Notifications.close(id); + return; + } + + return Draggable({ + maxOffset: 200, + command: () => command(id), + properties: [ + ['hovered', false], + ['id', id], + ], + onHover: w => { + if (!w._hovered) { + w._hovered = true; + } + }, + onHoverLost: w => { + if (w._hovered) { + w._hovered = false; + } + }, - child: Box({ - className: `notification ${urgency}`, - vexpand: false, - // Notification child: Box({ - vertical: true, - children: [ - // Content - Box({ - children: [ - NotificationIcon(icon), - Box({ - hexpand: true, - vertical: true, - children: [ - // Top of Content - Box({ - children: [ - Label({ - className: 'title', - xalign: 0, - justification: 'left', - hexpand: true, - maxWidthChars: 24, - truncate: 'end', - wrap: true, - label: summary, - useMarkup: summary.startsWith('<'), - }), - Label({ - className: 'time', - valign: 'start', - label: GLib.DateTime.new_from_unix_local(time).format('%H:%M'), - }), - EventBox({ - reset: false, - child: Button({ - className: 'close-button', - valign: 'start', - onClicked: () => Notifications.close(id), - child: Icon('window-close-symbolic'), + className: `notification ${urgency}`, + vexpand: false, + // Notification + child: Box({ + vertical: true, + children: [ + // Content + Box({ + children: [ + NotificationIcon(icon), + Box({ + hexpand: true, + vertical: true, + children: [ + // Top of Content + Box({ + children: [ + Label({ + className: 'title', + xalign: 0, + justification: 'left', + hexpand: true, + maxWidthChars: 24, + truncate: 'end', + wrap: true, + label: summary, + useMarkup: summary.startsWith('<'), }), - }), - ], - }), - Label({ - className: 'description', - hexpand: true, - useMarkup: true, - xalign: 0, - justification: 'left', - label: body, - wrap: true, - }), - ], - }), - ], - }), - // Actions - Box({ - className: 'actions', - children: actions.map(action => Button({ - className: 'action-button', - onClicked: () => Notifications.invoke(id, action.id), - hexpand: true, - child: Label(action.label), - })), - }), - ], + Label({ + className: 'time', + valign: 'start', + label: GLib.DateTime.new_from_unix_local(time).format('%H:%M'), + }), + EventBox({ + reset: false, + child: Button({ + className: 'close-button', + valign: 'start', + onClicked: () => Notifications.close(id), + child: Icon('window-close-symbolic'), + }), + }), + ], + }), + Label({ + className: 'description', + hexpand: true, + useMarkup: true, + xalign: 0, + justification: 'left', + label: body, + wrap: true, + }), + ], + }), + ], + }), + // Actions + Box({ + className: 'actions', + children: actions.map(action => Button({ + className: 'action-button', + onClicked: () => Notifications.invoke(id, action.id), + hexpand: true, + child: Label(action.label), + })), + }), + ], + }), }), - }), -}); + }); +}; diff --git a/config/ags/js/notifications/center.js b/config/ags/js/notifications/center.js index b2f68f9..9162bd9 100644 --- a/config/ags/js/notifications/center.js +++ b/config/ags/js/notifications/center.js @@ -61,11 +61,15 @@ const NotificationList = () => Box({ .map(n => Notification({ ...n, command: i => Notifications.close(i), })); } else if (id) { - box.add(Notification({ + const NewNotif = Notification({ ...Notifications.getNotification(id), command: i => Notifications.close(i), - })); - box.show_all(); + }); + + if (NewNotif) { + box.add(NewNotif); + box.show_all(); + } } }, 'notified'], diff --git a/config/ags/js/notifications/popup.js b/config/ags/js/notifications/popup.js index 28547fe..fe3e577 100644 --- a/config/ags/js/notifications/popup.js +++ b/config/ags/js/notifications/popup.js @@ -31,6 +31,9 @@ const Popups = () => Box({ if (!id || Notifications.dnd) return; + if (! Notifications.getNotification(id)) + return; + box._map.delete(id); box._map.set(id, Notification({