dots-hyprland/.config/ags/widgets/indicators/notificationpopups.js
2023-12-29 18:17:08 +07:00

80 lines
No EOL
2.6 KiB
JavaScript

// This file is for popup notifications
const { GLib, Gtk } = imports.gi;
import { App, Service, Utils, Widget } from '../../imports.js';
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
const { Box, EventBox, Icon, Scrollable, Label, Button, Revealer } = Widget;
import Notification from '../../lib/notification.js';
const PopupNotification = (notifObject) => Widget.Box({
homogeneous: true,
children: [
Widget.EventBox({
onHoverLost: () => {
notifObject.dismiss();
},
child: Widget.Revealer({
revealChild: true,
child: Widget.Box({
children: [Notification({
notifObject: notifObject,
isPopup: true,
props: { hpack: 'fill' },
})],
}),
})
})
]
})
const naiveNotifPopupList = Widget.Box({
vertical: true,
className: 'spacing-v-5',
setup: (self) => self.hook(Notifications, (box) => {
box.children = Notifications.popups.reverse()
.map(notifItem => PopupNotification(notifItem));
}),
})
const notifPopupList = Box({
vertical: true,
className: 'osd-notifs spacing-v-5-revealer',
properties: [
['map', new Map()],
['dismiss', (box, id, force = false) => {
if (!id || !box._map.has(id) || box._map.get(id)._hovered && !force)
return;
const notif = box._map.get(id);
notif.revealChild = false;
notif._destroyWithAnims();
}],
['notify', (box, id) => {
// console.log('new notiffy', id, Notifications.getNotification(id))
if (!id || Notifications.dnd) return;
if (!Notifications.getNotification(id)) return;
box._map.delete(id);
const notif = Notifications.getNotification(id);
const newNotif = Notification({
notifObject: notif,
isPopup: true,
});
box._map.set(id, newNotif);
box.pack_end(box._map.get(id), false, false, 0);
box.show_all();
// box.children = Array.from(box._map.values()).reverse();
}],
],
setup: (self) => self
.hook(Notifications, (box, id) => box._notify(box, id), 'notified')
.hook(Notifications, (box, id) => box._dismiss(box, id), 'dismissed')
.hook(Notifications, (box, id) => box._dismiss(box, id, true), 'closed')
,
});
export default () => notifPopupList;