fix(ags notifs): use notif center code for popups to fix bugs

This commit is contained in:
matt1432 2023-11-03 00:03:14 -04:00
parent 43412c246e
commit 8764bfb459
2 changed files with 56 additions and 49 deletions

View file

@ -68,13 +68,22 @@ const Header = () => Box({
const NotificationList = Box({ const NotificationList = Box({
vertical: true, vertical: true,
valign: 'start',
vexpand: true, vexpand: true,
connections: [ connections: [
[Notifications, (box, id) => { [Notifications, (box, id) => {
if (box.children.length == 0) { if (box.children.length == 0) {
box.children = Notifications.notifications for (const notif of Notifications.notifications) {
.reverse() const NewNotif = Notification({
.map(n => Notification({ notif: n, command: () => n.close() })); notif,
command: () => notif.close(),
});
if (NewNotif) {
box.pack_end(NewNotif, false, false, 0);
box.show_all();
}
}
} }
else if (id) { else if (id) {
const notif = Notifications.getNotification(id); const notif = Notifications.getNotification(id);
@ -85,7 +94,7 @@ const NotificationList = Box({
}); });
if (NewNotif) { if (NewNotif) {
box.add(NewNotif); box.pack_end(NewNotif, false, false, 0);
box.show_all(); box.show_all();
} }
} }

View file

@ -7,61 +7,56 @@ import GLib from 'gi://GLib';
import Notification from './base.js'; import Notification from './base.js';
// FIXME: slide away when notif is seen // TODO: clean up code
const Popups = () => Box({ const Popups = () => Box({
vertical: true, vertical: true,
properties: [ properties: [
['map', new Map()], ['notify', (box, id) => {
if (id) {
const notif = Notifications.getNotification(id);
['dismiss', (box, id, force = false) => { const NewNotif = Notification({
if (!id || !box._map.has(id) || box._map.get(id)._hovered && !force) notif,
return; command: () => notif.dismiss(),
});
if (box._map.size - 1 === 0) if (NewNotif) {
box.get_parent().reveal_child = false; box.pack_end(NewNotif, false, false, 0);
box.show_all();
timeout(200, () => {
const notif = box._map.get(id);
if (notif.interval) {
GLib.source_remove(notif.interval);
notif.interval = undefined;
} }
}); }
}], }],
['notify', (box, id) => { ['dismiss', (box, id, force = false) => {
if (!id || Notifications.dnd) for (const ch of box.children) {
return; if (ch._id == id) {
if (!ch._hovered || force) {
if (! Notifications.getNotification(id)) ch.child.setStyle(ch.child._slideLeft);
return; ch.sensitive = false;
timeout(400, () => {
box._map.delete(id); ch.child.setStyle(ch.child._squeezeLeft);
timeout(500, () => box.remove(ch));
const notif = Notifications.getNotification(id); });
box._map.set(id, Notification({ return;
notif, }
command: () => notif.dismiss(), else if (ch._hovered) {
})); ch.interval = interval(2000, () => {
if (!ch._hovered) {
box.children = Array.from(box._map.values()).reverse(); if (ch.interval) {
ch.child.setStyle(ch.child._slideLeft);
timeout(10, () => { ch.sensitive = false;
box.get_parent().revealChild = true; timeout(400, () => {
}); ch.child.setStyle(ch.child._squeezeLeft);
timeout(500, () => box.remove(ch));
box._map.get(id).interval = interval(4500, () => { });
const notif = box._map.get(id); GLib.source_remove(ch.interval);
if (!notif._hovered) { ch.interval = undefined;
notif.child.setStyle(notif.child._slideLeft); }
}
if (notif.interval) { });
timeout(500, () => notif.destroy());
GLib.source_remove(notif.interval);
notif.interval = undefined;
} }
} }
}); }
}], }],
], ],
connections: [ connections: [
@ -77,6 +72,9 @@ const PopupList = ({ transition = 'none' } = {}) => Box({
children: [ children: [
Revealer({ Revealer({
transition, transition,
connections: [[Notifications, self => {
self.revealChild = self.child.children.length > 0;
}]],
child: Popups(), child: Popups(),
}), }),
], ],