2023-10-31 08:32:40 -04:00
|
|
|
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
|
2023-11-03 15:28:08 -04:00
|
|
|
import { Box, Window } from 'resource:///com/github/Aylur/ags/widget.js';
|
|
|
|
import { interval } 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-11-03 15:28:08 -04:00
|
|
|
import { Notification } from './base.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
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) {
|
2023-11-03 15:28:08 -04:00
|
|
|
// use this instead of add to put it at the top
|
2023-11-03 00:03:14 -04:00
|
|
|
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) {
|
2023-11-03 15:28:08 -04:00
|
|
|
// If notif isn't hovered or was closed, slide away
|
2023-11-03 00:03:14 -04:00
|
|
|
if (!ch._hovered || force) {
|
2023-11-03 15:28:08 -04:00
|
|
|
ch.slideAway('Left');
|
2023-11-03 00:03:14 -04:00
|
|
|
return;
|
|
|
|
}
|
2023-11-03 15:28:08 -04:00
|
|
|
|
|
|
|
// If notif is hovered, delay close
|
2023-11-03 00:03:14 -04:00
|
|
|
else if (ch._hovered) {
|
|
|
|
ch.interval = interval(2000, () => {
|
2023-11-03 15:28:08 -04:00
|
|
|
if (!ch._hovered && ch.interval) {
|
|
|
|
ch.slideAway('Left');
|
|
|
|
|
|
|
|
GLib.source_remove(ch.interval);
|
|
|
|
ch.interval = undefined;
|
|
|
|
return;
|
2023-11-03 00:03:14 -04:00
|
|
|
}
|
|
|
|
});
|
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-10-16 18:11:19 -04:00
|
|
|
export default () => Window({
|
2023-10-20 23:11:21 -04:00
|
|
|
name: 'notifications',
|
|
|
|
anchor: ['top', 'left'],
|
2023-11-03 15:28:08 -04:00
|
|
|
child: Box({
|
|
|
|
style: `min-height:1px;
|
|
|
|
min-width:1px;
|
|
|
|
padding: 1px;`,
|
|
|
|
children: [Popups()],
|
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|