2023-10-02 12:06:35 -04:00
|
|
|
import { Applications, Utils, Widget } from '../../imports.js';
|
|
|
|
const { lookUpIcon, execAsync } = Utils;
|
|
|
|
const { Box, Icon, Label, Button } = Widget;
|
|
|
|
|
|
|
|
import GLib from 'gi://GLib';
|
2023-09-11 13:59:51 -04:00
|
|
|
|
|
|
|
import { Draggable } from '../misc/drag.js';
|
2023-09-11 19:57:21 -04:00
|
|
|
import { EventBox } from '../misc/cursorbox.js'
|
2023-09-15 15:49:43 -04:00
|
|
|
import { closeAll } from '../misc/closer.js';
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
|
|
|
const NotificationIcon = notif => {
|
2023-09-15 15:49:43 -04:00
|
|
|
let iconCmd = () => {};
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
if (Applications.query(notif.appEntry).length > 0) {
|
|
|
|
let app = Applications.query(notif.appEntry)[0];
|
2023-09-15 15:49:43 -04:00
|
|
|
|
|
|
|
if (app.app.get_string('StartupWMClass') != null) {
|
|
|
|
iconCmd = box => {
|
|
|
|
if (!box.get_parent().get_parent().get_parent().get_parent().get_parent()._dragging) {
|
2023-09-26 12:36:54 -04:00
|
|
|
execAsync(['bash', '-c', `$AGS_PATH/launch-app.sh ${app.app.get_string('StartupWMClass')} ${app.app.get_string('Exec')}`]).catch(print);
|
|
|
|
closeAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (app.app.get_filename().includes('discord')) {
|
|
|
|
iconCmd = box => {
|
|
|
|
if (!box.get_parent().get_parent().get_parent().get_parent().get_parent()._dragging) {
|
|
|
|
execAsync(['bash', '-c', `$AGS_PATH/launch-app.sh discord ${app.app.get_string('Exec')}`])
|
|
|
|
.catch(print);
|
2023-09-15 15:49:43 -04:00
|
|
|
closeAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
if (notif.image) {
|
2023-09-15 15:49:43 -04:00
|
|
|
return EventBox({
|
|
|
|
onPrimaryClickRelease: iconCmd,
|
|
|
|
child: Box({
|
|
|
|
valign: 'start',
|
|
|
|
hexpand: false,
|
|
|
|
className: 'icon img',
|
|
|
|
style: `
|
2023-10-02 12:06:35 -04:00
|
|
|
background-image: url("${notif.image}");
|
2023-09-15 15:49:43 -04:00
|
|
|
background-size: contain;
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
background-position: center;
|
|
|
|
min-width: 78px;
|
|
|
|
min-height: 78px;
|
|
|
|
`,
|
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let icon = 'dialog-information-symbolic';
|
2023-10-02 12:06:35 -04:00
|
|
|
if (lookUpIcon(notif.appIcon)) {
|
|
|
|
icon = notif.appIcon;
|
2023-09-11 13:59:51 -04:00
|
|
|
}
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
if (lookUpIcon(notif.appEntry)) {
|
|
|
|
icon = notif.appEntry;
|
2023-09-11 13:59:51 -04:00
|
|
|
}
|
|
|
|
|
2023-09-15 15:49:43 -04:00
|
|
|
return EventBox({
|
|
|
|
onPrimaryClickRelease: iconCmd,
|
|
|
|
child: Box({
|
|
|
|
valign: 'start',
|
|
|
|
hexpand: false,
|
|
|
|
className: 'icon',
|
|
|
|
style: `
|
|
|
|
min-width: 78px;
|
|
|
|
min-height: 78px;
|
|
|
|
`,
|
|
|
|
children: [Icon({
|
|
|
|
icon, size: 58,
|
|
|
|
halign: 'center',
|
|
|
|
hexpand: true,
|
|
|
|
valign: 'center',
|
|
|
|
vexpand: true,
|
|
|
|
})],
|
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
export default ({ notif, command = () => {}} = {}) => {
|
2023-09-19 10:22:08 -04:00
|
|
|
const BlockedApps = [
|
|
|
|
'Spotify',
|
|
|
|
];
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
if (BlockedApps.find(app => app == notif.appName)) {
|
|
|
|
notif.close();
|
2023-09-19 10:22:08 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Draggable({
|
|
|
|
maxOffset: 200,
|
2023-10-02 12:06:35 -04:00
|
|
|
command: () => command(),
|
2023-09-19 10:22:08 -04:00
|
|
|
properties: [
|
|
|
|
['hovered', false],
|
2023-10-02 12:06:35 -04:00
|
|
|
['id', notif.id],
|
2023-09-19 10:22:08 -04:00
|
|
|
],
|
|
|
|
onHover: w => {
|
|
|
|
if (!w._hovered) {
|
|
|
|
w._hovered = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onHoverLost: w => {
|
|
|
|
if (w._hovered) {
|
|
|
|
w._hovered = false;
|
|
|
|
}
|
|
|
|
},
|
2023-09-11 13:59:51 -04:00
|
|
|
|
|
|
|
child: Box({
|
2023-10-02 12:06:35 -04:00
|
|
|
className: `notification ${notif.urgency}`,
|
2023-09-19 10:22:08 -04:00
|
|
|
vexpand: false,
|
|
|
|
// Notification
|
|
|
|
child: Box({
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
// Content
|
|
|
|
Box({
|
|
|
|
children: [
|
2023-10-02 12:06:35 -04:00
|
|
|
NotificationIcon(notif),
|
2023-09-19 10:22:08 -04:00
|
|
|
Box({
|
|
|
|
hexpand: true,
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
// Top of Content
|
|
|
|
Box({
|
|
|
|
children: [
|
|
|
|
Label({
|
|
|
|
className: 'title',
|
|
|
|
xalign: 0,
|
|
|
|
justification: 'left',
|
|
|
|
hexpand: true,
|
|
|
|
maxWidthChars: 24,
|
|
|
|
truncate: 'end',
|
|
|
|
wrap: true,
|
2023-10-02 12:06:35 -04:00
|
|
|
label: notif.summary,
|
|
|
|
useMarkup: notif.summary.startsWith('<'),
|
2023-09-19 10:22:08 -04:00
|
|
|
}),
|
|
|
|
Label({
|
|
|
|
className: 'time',
|
2023-09-11 19:28:22 -04:00
|
|
|
valign: 'start',
|
2023-10-02 12:06:35 -04:00
|
|
|
label: GLib.DateTime.new_from_unix_local(notif.time).format('%H:%M'),
|
2023-09-11 19:28:22 -04:00
|
|
|
}),
|
2023-09-19 10:22:08 -04:00
|
|
|
EventBox({
|
|
|
|
reset: false,
|
|
|
|
child: Button({
|
|
|
|
className: 'close-button',
|
|
|
|
valign: 'start',
|
2023-10-02 12:06:35 -04:00
|
|
|
onClicked: () => notif.close(),
|
2023-09-19 10:22:08 -04:00
|
|
|
child: Icon('window-close-symbolic'),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
Label({
|
|
|
|
className: 'description',
|
|
|
|
hexpand: true,
|
|
|
|
useMarkup: true,
|
|
|
|
xalign: 0,
|
|
|
|
justification: 'left',
|
2023-10-02 12:06:35 -04:00
|
|
|
label: notif.body,
|
2023-09-19 10:22:08 -04:00
|
|
|
wrap: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
// Actions
|
|
|
|
Box({
|
|
|
|
className: 'actions',
|
2023-10-02 12:06:35 -04:00
|
|
|
children: notif.actions.map(action => Button({
|
2023-09-19 10:22:08 -04:00
|
|
|
className: 'action-button',
|
2023-10-02 12:06:35 -04:00
|
|
|
onClicked: () => notif.invoke(action.id),
|
2023-09-19 10:22:08 -04:00
|
|
|
hexpand: true,
|
|
|
|
child: Label(action.label),
|
|
|
|
})),
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
}),
|
2023-09-19 10:22:08 -04:00
|
|
|
});
|
|
|
|
};
|