nixos-configs/devices/wim/config/ags/js/bar/buttons/notif-button.js

61 lines
1.8 KiB
JavaScript
Raw Normal View History

import App from 'resource:///com/github/Aylur/ags/app.js';
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
2023-11-27 15:15:02 -05:00
import { Box, CenterBox, Icon, Label } from 'resource:///com/github/Aylur/ags/widget.js';
2023-09-05 15:10:25 -04:00
import EventBox from '../../misc/cursorbox.js';
2023-11-27 15:15:02 -05:00
import Separator from '../../misc/separator.js';
const SPACING = 4;
export default () => EventBox({
className: 'toggle-off',
onPrimaryClickRelease: (self) => {
App.getWindow('notification-center')
.setXPos(self.get_allocation(), 'right');
App.toggleWindow('notification-center');
},
setup: (self) => {
self.hook(App, (_, windowName, visible) => {
if (windowName === 'notification-center') {
self.toggleClassName('toggle-on', visible);
}
});
},
2023-11-27 15:15:02 -05:00
child: CenterBox({
className: 'notif-panel',
2023-11-27 15:15:02 -05:00
center_widget: Box({
children: [
Icon({
setup: (self) => {
self.hook(Notifications, () => {
if (Notifications.dnd) {
self.icon = 'notification-disabled-symbolic';
}
else if (Notifications.notifications.length > 0) {
self.icon = 'notification-new-symbolic';
}
else {
self.icon = 'notification-symbolic';
}
});
},
2023-11-27 15:15:02 -05:00
}),
Separator(SPACING),
Label({
binds: [['label', Notifications, 'notifications',
(n) => String(n.length)]],
}),
],
}),
}),
2023-09-05 15:10:25 -04:00
});