2023-10-31 08:32:40 -04:00
|
|
|
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
|
|
|
|
import { Box, Revealer, Window } from 'resource:///com/github/Aylur/ags/widget.js';
|
|
|
|
import { interval, timeout } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
|
2023-09-11 13:59:51 -04:00
|
|
|
import Notification from './base.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-11-01 14:33:06 -04:00
|
|
|
// FIXME: slide away when notif is seen
|
2023-09-11 13:59:51 -04:00
|
|
|
const Popups = () => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
vertical: true,
|
|
|
|
properties: [
|
|
|
|
['map', new Map()],
|
|
|
|
|
|
|
|
['dismiss', (box, id, force = false) => {
|
2023-10-28 13:04:35 -04:00
|
|
|
if (!id || !box._map.has(id) || box._map.get(id)._hovered && !force)
|
2023-10-20 23:11:21 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (box._map.size - 1 === 0)
|
|
|
|
box.get_parent().reveal_child = false;
|
|
|
|
|
2023-10-31 08:32:40 -04:00
|
|
|
timeout(200, () => {
|
2023-10-28 18:47:39 -04:00
|
|
|
const notif = box._map.get(id);
|
|
|
|
if (notif.interval) {
|
|
|
|
GLib.source_remove(notif.interval);
|
|
|
|
notif.interval = undefined;
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}],
|
|
|
|
|
|
|
|
['notify', (box, id) => {
|
|
|
|
if (!id || Notifications.dnd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (! Notifications.getNotification(id))
|
|
|
|
return;
|
|
|
|
|
|
|
|
box._map.delete(id);
|
|
|
|
|
|
|
|
const notif = Notifications.getNotification(id);
|
|
|
|
box._map.set(id, Notification({
|
|
|
|
notif,
|
|
|
|
command: () => notif.dismiss(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
box.children = Array.from(box._map.values()).reverse();
|
|
|
|
|
2023-10-31 08:32:40 -04:00
|
|
|
timeout(10, () => {
|
2023-10-20 23:11:21 -04:00
|
|
|
box.get_parent().revealChild = true;
|
|
|
|
});
|
|
|
|
|
2023-10-31 08:32:40 -04:00
|
|
|
box._map.get(id).interval = interval(4500, () => {
|
2023-10-28 13:04:35 -04:00
|
|
|
const notif = box._map.get(id);
|
|
|
|
if (!notif._hovered) {
|
2023-11-01 15:29:47 -04:00
|
|
|
notif.child.setStyle(notif.child._slideLeft);
|
2023-10-28 13:04:35 -04:00
|
|
|
|
|
|
|
if (notif.interval) {
|
2023-10-31 08:32:40 -04:00
|
|
|
timeout(500, () => notif.destroy());
|
2023-10-28 13:04:35 -04:00
|
|
|
GLib.source_remove(notif.interval);
|
|
|
|
notif.interval = undefined;
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}],
|
|
|
|
],
|
|
|
|
connections: [
|
|
|
|
[Notifications, (box, id) => box._notify(box, id), 'notified'],
|
|
|
|
[Notifications, (box, id) => box._dismiss(box, id), 'dismissed'],
|
|
|
|
[Notifications, (box, id) => box._dismiss(box, id, true), 'closed'],
|
|
|
|
],
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-09-14 16:42:39 -04:00
|
|
|
const PopupList = ({ transition = 'none' } = {}) => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'notifications-popup-list',
|
|
|
|
style: 'padding: 1px',
|
|
|
|
children: [
|
|
|
|
Revealer({
|
|
|
|
transition,
|
|
|
|
child: Popups(),
|
|
|
|
}),
|
|
|
|
],
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-10-16 18:11:19 -04:00
|
|
|
export default () => Window({
|
2023-10-20 23:11:21 -04:00
|
|
|
name: 'notifications',
|
|
|
|
anchor: ['top', 'left'],
|
|
|
|
child: PopupList(),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|