2023-10-31 08:32:40 -04:00
|
|
|
import Applications from 'resource:///com/github/Aylur/ags/service/applications.js';
|
2023-11-13 13:19:14 -05:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-11-03 15:28:08 -04:00
|
|
|
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
|
|
|
|
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
|
2023-10-31 08:32:40 -04:00
|
|
|
import { Box, Icon, Label, Button } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-11-13 13:19:14 -05:00
|
|
|
import { lookUpIcon } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
|
|
|
import GLib from 'gi://GLib';
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
const setTime = time => {
|
2023-10-20 23:11:21 -04:00
|
|
|
return GLib.DateTime
|
|
|
|
.new_from_unix_local(time)
|
|
|
|
.format('%H:%M');
|
2023-10-17 13:47:02 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const getDragState = box => box.get_parent().get_parent()
|
2023-10-20 23:11:21 -04:00
|
|
|
.get_parent().get_parent().get_parent()._dragging;
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-10-16 18:43:12 -04:00
|
|
|
import Gesture from './gesture.js';
|
2023-10-20 23:11:21 -04:00
|
|
|
import EventBox from '../misc/cursorbox.js';
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
|
|
|
const NotificationIcon = notif => {
|
2023-10-20 23:11:21 -04:00
|
|
|
let iconCmd = () => {};
|
|
|
|
|
|
|
|
if (Applications.query(notif.appEntry).length > 0) {
|
|
|
|
const app = Applications.query(notif.appEntry)[0];
|
|
|
|
|
|
|
|
let wmClass = app.app.get_string('StartupWMClass');
|
|
|
|
if (app.app.get_filename().includes('discord'))
|
|
|
|
wmClass = 'discord';
|
|
|
|
|
|
|
|
if (wmClass != null) {
|
|
|
|
iconCmd = box => {
|
|
|
|
if (!getDragState(box)) {
|
2023-11-13 13:19:14 -05:00
|
|
|
if (wmClass === 'thunderbird') {
|
|
|
|
Hyprland.sendMessage('dispatch togglespecialworkspace thunder');
|
|
|
|
}
|
|
|
|
else if (wmClass === 'Spotify') {
|
|
|
|
Hyprland.sendMessage('dispatch togglespecialworkspace spot');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Hyprland.sendMessage('j/clients').then(out => {
|
|
|
|
out = JSON.parse(out);
|
|
|
|
const classes = [];
|
|
|
|
for (const key of out) {
|
|
|
|
if (key.class)
|
|
|
|
classes.push(key.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (classes.includes(wmClass)) {
|
|
|
|
Hyprland.sendMessage(`dispatch focuswindow ^(${wmClass})`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Hyprland.sendMessage('[[BATCH]] ' +
|
|
|
|
'dispatch workspace empty; ' +
|
|
|
|
`dispatch exec sh -c ${app.executable}
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
globalThis.closeAll();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2023-09-15 15:49:43 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
if (notif.image) {
|
|
|
|
return EventBox({
|
|
|
|
onPrimaryClickRelease: iconCmd,
|
|
|
|
child: Box({
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'start',
|
2023-10-20 23:11:21 -04:00
|
|
|
hexpand: false,
|
|
|
|
className: 'icon img',
|
2023-11-06 20:10:12 -05:00
|
|
|
css: `
|
|
|
|
background-image: url("${notif.image}");
|
|
|
|
background-size: contain;
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
background-position: center;
|
|
|
|
min-width: 78px;
|
|
|
|
min-height: 78px;
|
|
|
|
`,
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
2023-09-15 15:49:43 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
let icon = 'dialog-information-symbolic';
|
|
|
|
if (lookUpIcon(notif.appIcon))
|
|
|
|
icon = notif.appIcon;
|
2023-10-17 13:47:02 -04:00
|
|
|
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
if (lookUpIcon(notif.appEntry))
|
|
|
|
icon = notif.appEntry;
|
|
|
|
|
2023-09-15 15:49:43 -04:00
|
|
|
|
|
|
|
return EventBox({
|
2023-10-20 23:11:21 -04:00
|
|
|
onPrimaryClickRelease: iconCmd,
|
|
|
|
child: Box({
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'start',
|
2023-10-20 23:11:21 -04:00
|
|
|
hexpand: false,
|
|
|
|
className: 'icon',
|
2023-11-06 20:10:12 -05:00
|
|
|
css: `min-width: 78px;
|
|
|
|
min-height: 78px;`,
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [Icon({
|
|
|
|
icon, size: 58,
|
2023-11-06 20:10:12 -05:00
|
|
|
hpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
hexpand: true,
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
vexpand: true,
|
|
|
|
})],
|
|
|
|
}),
|
2023-09-11 13:59:51 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
// Make a variable to connect to for Widgets
|
|
|
|
// to know when there are notifs or not
|
|
|
|
export const HasNotifs = Variable(false);
|
|
|
|
|
|
|
|
export const Notification = ({
|
2023-10-28 13:04:35 -04:00
|
|
|
notif,
|
2023-11-03 15:28:08 -04:00
|
|
|
slideIn = 'Left',
|
2023-10-28 13:04:35 -04:00
|
|
|
command = () => {},
|
|
|
|
} = {}) => {
|
2023-11-03 15:28:08 -04:00
|
|
|
if (!notif)
|
|
|
|
return;
|
|
|
|
|
|
|
|
HasNotifs.value = Notifications.notifications.length > 0;
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
const BlockedApps = [
|
|
|
|
'Spotify',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (BlockedApps.find(app => app == notif.appName)) {
|
|
|
|
notif.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
// Init notif
|
|
|
|
const notifWidget = Gesture({
|
2023-11-06 20:10:12 -05:00
|
|
|
command,
|
2023-11-03 15:28:08 -04:00
|
|
|
slideIn,
|
2023-11-06 20:10:12 -05:00
|
|
|
id: notif.id,
|
2023-11-03 15:28:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add body to notif
|
|
|
|
notifWidget.child.add(Box({
|
|
|
|
className: `notification ${notif.urgency}`,
|
|
|
|
vexpand: false,
|
|
|
|
// Notification
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
2023-11-03 15:28:08 -04:00
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
// Content
|
|
|
|
Box({
|
|
|
|
children: [
|
|
|
|
NotificationIcon(notif),
|
|
|
|
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: notif.summary,
|
|
|
|
useMarkup: notif.summary.startsWith('<'),
|
|
|
|
}),
|
|
|
|
Label({
|
|
|
|
className: 'time',
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'start',
|
2023-11-03 15:28:08 -04:00
|
|
|
label: setTime(notif.time),
|
|
|
|
}),
|
|
|
|
EventBox({
|
|
|
|
child: Button({
|
|
|
|
className: 'close-button',
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'start',
|
2023-11-03 15:28:08 -04:00
|
|
|
onClicked: () => notif.close(),
|
|
|
|
child: Icon('window-close-symbolic'),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-11-03 15:28:08 -04:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
Label({
|
|
|
|
className: 'description',
|
|
|
|
hexpand: true,
|
|
|
|
useMarkup: true,
|
|
|
|
xalign: 0,
|
|
|
|
justification: 'left',
|
|
|
|
label: notif.body,
|
|
|
|
wrap: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
// Actions
|
|
|
|
Box({
|
|
|
|
className: 'actions',
|
|
|
|
children: notif.actions.map(action => Button({
|
|
|
|
className: 'action-button',
|
|
|
|
onClicked: () => notif.invoke(action.id),
|
|
|
|
hexpand: true,
|
|
|
|
child: Label(action.label),
|
|
|
|
})),
|
|
|
|
}),
|
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-11-03 15:28:08 -04:00
|
|
|
}));
|
|
|
|
return notifWidget;
|
2023-09-19 10:22:08 -04:00
|
|
|
};
|