2023-10-31 08:32:40 -04:00
|
|
|
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
|
|
|
|
import { Button, Label, Box, Icon, Scrollable, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
import { Notification, HasNotifs } from './base.js';
|
2023-10-17 13:47:02 -04:00
|
|
|
import PopupWindow from '../misc/popup.js';
|
|
|
|
import EventBox from '../misc/cursorbox.js';
|
2023-09-11 19:57:21 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
// Needs to be wrapped to still have onHover when disabled
|
2023-09-15 13:51:03 -04:00
|
|
|
const ClearButton = () => EventBox({
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Button({
|
2023-11-03 15:28:08 -04:00
|
|
|
onPrimaryClickRelease: () => Notifications.clear(),
|
|
|
|
binds: [['sensitive', HasNotifs]],
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
|
|
|
children: [
|
|
|
|
Label('Clear '),
|
|
|
|
Icon({
|
|
|
|
connections: [[Notifications, self => {
|
|
|
|
self.icon = Notifications.notifications.length > 0
|
|
|
|
? 'user-trash-full-symbolic' : 'user-trash-symbolic';
|
|
|
|
}]],
|
|
|
|
}),
|
|
|
|
],
|
2023-09-15 13:51:03 -04:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
2023-09-11 13:59:51 -04:00
|
|
|
|
|
|
|
const Header = () => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'header',
|
|
|
|
children: [
|
|
|
|
Label({
|
|
|
|
label: 'Notifications',
|
|
|
|
hexpand: true,
|
|
|
|
xalign: 0,
|
|
|
|
}),
|
|
|
|
ClearButton(),
|
|
|
|
],
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
const NotificationList = () => Box({
|
2023-09-14 01:15:33 -04:00
|
|
|
vertical: true,
|
|
|
|
vexpand: true,
|
2023-11-03 15:28:08 -04:00
|
|
|
valign: 'start',
|
|
|
|
binds: [['visible', HasNotifs]],
|
2023-10-20 23:11:21 -04:00
|
|
|
connections: [
|
|
|
|
[Notifications, (box, id) => {
|
|
|
|
if (box.children.length == 0) {
|
2023-11-03 00:03:14 -04:00
|
|
|
for (const notif of Notifications.notifications) {
|
2023-11-03 15:28:08 -04:00
|
|
|
if (!notif)
|
|
|
|
return;
|
|
|
|
|
2023-11-03 00:03:14 -04:00
|
|
|
const NewNotif = Notification({
|
|
|
|
notif,
|
2023-11-03 15:28:08 -04:00
|
|
|
slideIn: 'Right',
|
2023-11-03 00:03:14 -04:00
|
|
|
command: () => notif.close(),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (NewNotif) {
|
|
|
|
box.pack_end(NewNotif, false, false, 0);
|
|
|
|
box.show_all();
|
|
|
|
}
|
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
|
|
|
else if (id) {
|
|
|
|
const notif = Notifications.getNotification(id);
|
|
|
|
|
|
|
|
const NewNotif = Notification({
|
|
|
|
notif,
|
2023-11-03 15:28:08 -04:00
|
|
|
slideIn: 'Right',
|
2023-10-20 23:11:21 -04:00
|
|
|
command: () => notif.close(),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (NewNotif) {
|
2023-11-03 00:03:14 -04:00
|
|
|
box.pack_end(NewNotif, false, false, 0);
|
2023-10-20 23:11:21 -04:00
|
|
|
box.show_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'notified'],
|
|
|
|
|
|
|
|
[Notifications, (box, id) => {
|
|
|
|
for (const ch of box.children) {
|
|
|
|
if (ch._id == id) {
|
2023-11-03 15:28:08 -04:00
|
|
|
ch.slideAway('Right');
|
2023-10-20 23:11:21 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'closed'],
|
2023-09-14 01:15:33 -04:00
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const Placeholder = () => Revealer({
|
|
|
|
transition: 'crossfade',
|
2023-11-03 15:28:08 -04:00
|
|
|
binds: [['revealChild', HasNotifs, 'value', value => !value]],
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
|
|
|
className: 'placeholder',
|
|
|
|
vertical: true,
|
|
|
|
valign: 'center',
|
|
|
|
halign: 'center',
|
|
|
|
vexpand: true,
|
|
|
|
hexpand: true,
|
|
|
|
children: [
|
|
|
|
Icon('notification-disabled-symbolic'),
|
|
|
|
Label('Your inbox is empty'),
|
|
|
|
],
|
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
const NotificationCenterWidget = () => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'notification-center',
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
Header(),
|
|
|
|
Box({
|
|
|
|
className: 'notification-wallpaper-box',
|
2023-10-17 13:47:02 -04:00
|
|
|
children: [
|
2023-10-20 23:11:21 -04:00
|
|
|
Scrollable({
|
|
|
|
className: 'notification-list-box',
|
|
|
|
hscroll: 'never',
|
|
|
|
child: Box({
|
|
|
|
className: 'notification-list',
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
2023-11-03 15:28:08 -04:00
|
|
|
NotificationList(),
|
2023-10-20 23:11:21 -04:00
|
|
|
Placeholder(),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}),
|
2023-10-17 13:47:02 -04:00
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
],
|
2023-09-21 20:01:14 -04:00
|
|
|
});
|
|
|
|
|
2023-10-16 18:11:19 -04:00
|
|
|
export default () => PopupWindow({
|
2023-10-20 23:11:21 -04:00
|
|
|
name: 'notification-center',
|
|
|
|
anchor: ['top', 'right'],
|
2023-10-22 14:15:12 -04:00
|
|
|
margin: [6, 60, 0, 0],
|
2023-10-20 23:11:21 -04:00
|
|
|
child: NotificationCenterWidget(),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|