nixos-configs/config/ags/js/notifications/popup.js

88 lines
2.2 KiB
JavaScript
Raw Normal View History

import { Notifications, Utils, Widget } from '../../imports.js';
const { Box, Revealer, Window } = Widget;
const { timeout, interval } = Utils;
import GLib from 'gi://GLib';
const { source_remove } = GLib;
import Notification from './base.js';
const Popups = () => Box({
2023-09-11 14:18:22 -04:00
vertical: true,
properties: [
['map', new Map()],
['dismiss', (box, id, force = false) => {
if (!id || !box._map.has(id))
return;
2023-09-11 14:18:22 -04:00
if (box._map.get(id)._hovered && !force)
return;
2023-09-11 14:18:22 -04:00
if (box._map.size - 1 === 0)
box.get_parent().reveal_child = false;
2023-09-11 14:18:22 -04:00
timeout(200, () => {
if (box._map.get(id)?.interval) {
source_remove(box._map.get(id).interval);
box._map.get(id).interval = undefined;
}
2023-09-11 14:18:22 -04:00
box._map.get(id)?.destroy();
box._map.delete(id);
});
}],
['notify', (box, id) => {
if (!id || Notifications.dnd)
return;
if (! Notifications.getNotification(id))
return;
2023-09-11 14:18:22 -04:00
box._map.delete(id);
let notif = Notifications.getNotification(id);
box._map.set(id, Notification({
notif,
command: () => notif.dismiss(),
}));
2023-09-11 14:18:22 -04:00
box.children = Array.from(box._map.values()).reverse();
timeout(10, () => {
box.get_parent().revealChild = true;
});
box._map.get(id).interval = interval(4500, () => {
if (!box._map.get(id)._hovered) {
box._map.get(id).child.setStyle(box._map.get(id).child._leftAnim1);
if (box._map.get(id).interval) {
source_remove(box._map.get(id).interval);
box._map.get(id).interval = undefined;
}
}
});
2023-09-11 14:18:22 -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'],
],
});
const PopupList = ({ transition = 'none' } = {}) => Box({
2023-09-11 14:18:22 -04:00
className: 'notifications-popup-list',
style: 'padding: 1px',
children: [
Revealer({
transition,
child: Popups(),
}),
],
});
export const NotificationsPopupList = Window({
2023-09-11 14:18:22 -04:00
name: `notifications`,
anchor: 'top left',
child: PopupList(),
});