FIX SPAMMING NOTIF ERRORS FINALLY OMGGGGGGGGGG (btw #215)

This commit is contained in:
end-4 2024-02-03 07:20:44 +07:00
parent 13f634fffa
commit fb86c7316c
3 changed files with 33 additions and 13 deletions

View file

@ -20,6 +20,10 @@ function guessMessageType(summary) {
return 'chat';
}
function exists(widget) {
return widget !== null;
}
const NotificationIcon = (notifObject) => {
// { appEntry, appIcon, image }, urgency = 'normal'
if (notifObject.image) {
@ -71,9 +75,9 @@ const NotificationIcon = (notifObject) => {
export default ({
notifObject,
isPopup = false,
popupTimeout = 3000,
props = {},
} = {}) => {
const popupTimeout = notifObject.urgency == 'critical' ? 8000 : 3000;
const command = (isPopup ?
() => notifObject.dismiss() :
() => notifObject.close()
@ -82,11 +86,14 @@ export default ({
widget.sensitive = false;
notificationBox.setCss(middleClickClose);
Utils.timeout(200, () => {
wholeThing.revealChild = false;
if (wholeThing) wholeThing.revealChild = false;
}, wholeThing);
Utils.timeout(400, () => {
command();
wholeThing.destroy();
if (wholeThing) {
wholeThing.destroy();
wholeThing = null;
}
}, wholeThing);
}
const widget = EventBox({
@ -111,7 +118,7 @@ export default ({
wholeThing.attribute.held = true;
notificationContent.toggleClassName(`${isPopup ? 'popup-' : ''}notif-clicked-${notifObject.urgency}`, true);
Utils.timeout(800, () => {
if (wholeThing.attribute.held) {
if (wholeThing?.attribute.held) {
Utils.execAsync(['wl-copy', `${notifObject.body}`])
notifTextSummary.label = notifObject.summary + " (copied)";
Utils.timeout(3000, () => notifTextSummary.label = notifObject.summary)
@ -123,10 +130,10 @@ export default ({
})
}
});
const wholeThing = Revealer({
let wholeThing = Revealer({
attribute: {
'close': undefined,
'destroyWithAnims': () => destroyWithAnims,
'destroyWithAnims': destroyWithAnims,
'dragging': false,
'held': false,
'hovered': false,
@ -137,7 +144,7 @@ export default ({
transitionDuration: 200,
child: Box({ // Box to make sure css-based spacing works
homogeneous: true,
})
}),
});
const display = Gdk.Display.get_default();
@ -400,11 +407,14 @@ export default ({
widget.sensitive = false;
}
Utils.timeout(200, () => {
wholeThing.revealChild = false
if (wholeThing) wholeThing.revealChild = false;
}, wholeThing);
Utils.timeout(400, () => {
command();
wholeThing.destroy();
if (wholeThing) {
wholeThing.destroy();
wholeThing = null;
}
}, wholeThing);
}
else {
@ -425,6 +435,17 @@ export default ({
})
widget.add(notificationBox);
wholeThing.child.children = [widget];
if (isPopup) Utils.timeout(popupTimeout, () => {
if (wholeThing) {
wholeThing.revealChild = false;
Utils.timeout(200, () => {
if (wholeThing) {
wholeThing.destroy();
wholeThing = null;
}
command();
}, wholeThing);
}
})
return wholeThing;
}

View file

@ -32,8 +32,6 @@ export default () => Box({
box.attribute.map.set(id, newNotif);
box.pack_end(box.attribute.map.get(id), false, false, 0);
box.show_all();
// box.children = Array.from(box.attribute.map.values()).reverse();
},
},
setup: (self) => self

View file

@ -85,7 +85,8 @@ export default (props) => {
self.toggleClassName('notif-listaction-btn-enabled', Notifications.dnd);
});
const clearButton = ListActionButton('clear_all', 'Clear', () => {
notificationList.get_children().forEach(ch => ch.destroy());
// Manual destruction is not necessary
// since Notifications.clear() sends destroy signals to every notif
Notifications.clear();
});
const listTitle = Box({