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-03 00:03:14 -04:00
|
|
|
// TODO: clean up code
|
2023-09-11 13:59:51 -04:00
|
|
|
const Popups = () => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
vertical: true,
|
|
|
|
properties: [
|
2023-11-03 00:03:14 -04:00
|
|
|
['notify', (box, id) => {
|
|
|
|
if (id) {
|
|
|
|
const notif = Notifications.getNotification(id);
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-03 00:03:14 -04:00
|
|
|
const NewNotif = Notification({
|
|
|
|
notif,
|
|
|
|
command: () => notif.dismiss(),
|
|
|
|
});
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-03 00:03:14 -04:00
|
|
|
if (NewNotif) {
|
|
|
|
box.pack_end(NewNotif, false, false, 0);
|
|
|
|
box.show_all();
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
2023-11-03 00:03:14 -04:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
}],
|
|
|
|
|
2023-11-03 00:03:14 -04:00
|
|
|
['dismiss', (box, id, force = false) => {
|
|
|
|
for (const ch of box.children) {
|
|
|
|
if (ch._id == id) {
|
|
|
|
if (!ch._hovered || force) {
|
|
|
|
ch.child.setStyle(ch.child._slideLeft);
|
|
|
|
ch.sensitive = false;
|
|
|
|
timeout(400, () => {
|
|
|
|
ch.child.setStyle(ch.child._squeezeLeft);
|
|
|
|
timeout(500, () => box.remove(ch));
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (ch._hovered) {
|
|
|
|
ch.interval = interval(2000, () => {
|
|
|
|
if (!ch._hovered) {
|
|
|
|
if (ch.interval) {
|
|
|
|
ch.child.setStyle(ch.child._slideLeft);
|
|
|
|
ch.sensitive = false;
|
|
|
|
timeout(400, () => {
|
|
|
|
ch.child.setStyle(ch.child._squeezeLeft);
|
|
|
|
timeout(500, () => box.remove(ch));
|
|
|
|
});
|
|
|
|
GLib.source_remove(ch.interval);
|
|
|
|
ch.interval = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
|
|
|
}
|
2023-11-03 00:03:14 -04:00
|
|
|
}
|
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,
|
2023-11-03 00:03:14 -04:00
|
|
|
connections: [[Notifications, self => {
|
|
|
|
self.revealChild = self.child.children.length > 0;
|
|
|
|
}]],
|
2023-10-20 23:11:21 -04:00
|
|
|
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
|
|
|
});
|