2023-09-11 13:59:51 -04:00
|
|
|
const { GLib } = imports.gi;
|
2023-09-15 15:49:43 -04:00
|
|
|
const { Notifications, Applications } = ags.Service;
|
|
|
|
const { lookUpIcon, timeout, exec } = ags.Utils;
|
2023-09-11 19:28:22 -04:00
|
|
|
const { Box, Icon, Label, Button } = ags.Widget;
|
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
|
|
|
|
|
|
|
const NotificationIcon = ({ appEntry, appIcon, image }) => {
|
2023-09-15 15:49:43 -04:00
|
|
|
let iconCmd = () => {};
|
|
|
|
|
|
|
|
if (Applications.query(appEntry).length > 0) {
|
|
|
|
let app = Applications.query(appEntry)[0];
|
|
|
|
|
|
|
|
if (app.app.get_string('StartupWMClass') != null) {
|
|
|
|
iconCmd = box => {
|
|
|
|
if (!box.get_parent().get_parent().get_parent().get_parent().get_parent()._dragging) {
|
|
|
|
exec('bash -c "$AGS_PATH/launch-app.sh ' + app.app.get_string('StartupWMClass') +
|
|
|
|
' ' + app.app.get_string('Exec') + '"');
|
|
|
|
closeAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-11 13:59:51 -04:00
|
|
|
if (image) {
|
2023-09-15 15:49:43 -04:00
|
|
|
return EventBox({
|
|
|
|
onPrimaryClickRelease: iconCmd,
|
|
|
|
child: Box({
|
|
|
|
valign: 'start',
|
|
|
|
hexpand: false,
|
|
|
|
className: 'icon img',
|
|
|
|
style: `
|
|
|
|
background-image: url("${image}");
|
|
|
|
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';
|
|
|
|
if (lookUpIcon(appIcon)) {
|
|
|
|
icon = appIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lookUpIcon(appEntry)) {
|
|
|
|
icon = appEntry;
|
|
|
|
}
|
|
|
|
|
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-09-14 17:24:02 -04:00
|
|
|
export default ({ id, summary, body, actions, urgency, time, command = i => {}, ...icon }) => Draggable({
|
2023-09-11 13:59:51 -04:00
|
|
|
maxOffset: 200,
|
2023-09-14 17:24:02 -04:00
|
|
|
command: () => command(id),
|
2023-09-15 12:32:30 -04:00
|
|
|
properties: [
|
|
|
|
['hovered', false],
|
|
|
|
['id', id],
|
|
|
|
],
|
2023-09-14 13:26:42 -04:00
|
|
|
onHover: w => {
|
2023-09-14 14:04:10 -04:00
|
|
|
if (!w._hovered) {
|
|
|
|
w._hovered = true;
|
|
|
|
}
|
2023-09-14 13:26:42 -04:00
|
|
|
},
|
|
|
|
onHoverLost: w => {
|
2023-09-14 14:04:10 -04:00
|
|
|
if (w._hovered) {
|
|
|
|
w._hovered = false;
|
|
|
|
}
|
2023-09-14 13:26:42 -04:00
|
|
|
},
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-09-11 18:23:47 -04:00
|
|
|
child: Box({
|
2023-09-11 13:59:51 -04:00
|
|
|
className: `notification ${urgency}`,
|
|
|
|
vexpand: false,
|
|
|
|
// Notification
|
|
|
|
child: Box({
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
// Content
|
|
|
|
Box({
|
|
|
|
children: [
|
|
|
|
NotificationIcon(icon),
|
|
|
|
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,
|
|
|
|
label: summary,
|
|
|
|
useMarkup: summary.startsWith('<'),
|
|
|
|
}),
|
|
|
|
Label({
|
|
|
|
className: 'time',
|
|
|
|
valign: 'start',
|
|
|
|
label: GLib.DateTime.new_from_unix_local(time).format('%H:%M'),
|
|
|
|
}),
|
2023-09-11 19:28:22 -04:00
|
|
|
EventBox({
|
|
|
|
reset: false,
|
|
|
|
child: Button({
|
|
|
|
className: 'close-button',
|
|
|
|
valign: 'start',
|
|
|
|
onClicked: () => Notifications.close(id),
|
|
|
|
child: Icon('window-close-symbolic'),
|
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
Label({
|
|
|
|
className: 'description',
|
|
|
|
hexpand: true,
|
|
|
|
useMarkup: true,
|
|
|
|
xalign: 0,
|
|
|
|
justification: 'left',
|
|
|
|
label: body,
|
|
|
|
wrap: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
// Actions
|
|
|
|
Box({
|
|
|
|
className: 'actions',
|
|
|
|
children: actions.map(action => Button({
|
|
|
|
className: 'action-button',
|
|
|
|
onClicked: () => Notifications.invoke(id, action.id),
|
|
|
|
hexpand: true,
|
|
|
|
child: Label(action.label),
|
|
|
|
})),
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|