2024-01-30 11:29:07 -05:00
|
|
|
const Applications = await Service.import('applications');
|
|
|
|
const Hyprland = await Service.import('hyprland');
|
|
|
|
const Notifications = await Service.import('notifications');
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-01-30 11:29:07 -05:00
|
|
|
const { Box, Icon, Label, Button } = Widget;
|
|
|
|
const { lookUpIcon } = Utils;
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-12-20 03:45:05 -05:00
|
|
|
const { GLib } = imports.gi;
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2024-01-13 23:38:31 -05:00
|
|
|
import Gesture from './gesture.ts';
|
|
|
|
import CursorBox from '../misc/cursorbox.ts';
|
2024-01-13 11:15:08 -05:00
|
|
|
|
|
|
|
// Types
|
2024-01-13 23:38:31 -05:00
|
|
|
import { Notification as NotifObj } from 'types/service/notifications.ts';
|
|
|
|
import { Client } from 'types/service/hyprland.ts';
|
2024-01-13 11:15:08 -05:00
|
|
|
type NotificationWidget = {
|
|
|
|
notif: NotifObj
|
|
|
|
slideIn?: 'Left' | 'Right'
|
|
|
|
command?(): void
|
|
|
|
};
|
2024-01-29 18:54:07 -05:00
|
|
|
import {
|
|
|
|
CursorBox as CBox,
|
2024-01-29 20:56:56 -05:00
|
|
|
EventBoxGeneric,
|
|
|
|
NotifGesture,
|
2024-01-29 18:54:07 -05:00
|
|
|
} from 'global-types';
|
|
|
|
|
2023-12-20 17:14:07 -05:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
const setTime = (time: number) => {
|
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
|
|
|
};
|
|
|
|
|
2024-01-29 18:54:07 -05:00
|
|
|
const getDragState = (box: EventBoxGeneric) => (box
|
|
|
|
.get_parent()
|
|
|
|
?.get_parent()
|
|
|
|
?.get_parent()
|
|
|
|
?.get_parent()
|
2024-01-29 20:56:56 -05:00
|
|
|
?.get_parent() as NotifGesture)
|
2024-01-13 11:15:08 -05:00
|
|
|
?.attribute.dragging;
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-09-11 13:59:51 -04:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
const NotificationIcon = (notif: NotifObj) => {
|
2024-01-29 18:54:07 -05:00
|
|
|
let iconCmd = (box: CBox):void => {
|
2024-01-29 21:00:56 -05:00
|
|
|
if (!box) {
|
|
|
|
console.log();
|
|
|
|
}
|
2024-01-13 11:15:08 -05:00
|
|
|
};
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2024-01-14 20:52:30 -05:00
|
|
|
if (notif.app_entry && Applications.query(notif.app_entry).length > 0) {
|
|
|
|
const app = Applications.query(notif.app_entry)[0];
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
let wmClass = app.app.get_string('StartupWMClass');
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-20 17:14:07 -05:00
|
|
|
if (app.app?.get_filename()?.includes('discord')) {
|
2023-10-20 23:11:21 -04:00
|
|
|
wmClass = 'discord';
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
if (wmClass != null) {
|
2023-11-21 01:29:46 -05:00
|
|
|
iconCmd = (box) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
if (!getDragState(box)) {
|
2023-11-13 13:19:14 -05:00
|
|
|
if (wmClass === 'thunderbird') {
|
2023-11-21 01:29:46 -05:00
|
|
|
Hyprland.sendMessage('dispatch ' +
|
|
|
|
'togglespecialworkspace thunder');
|
2023-11-13 13:19:14 -05:00
|
|
|
}
|
|
|
|
else if (wmClass === 'Spotify') {
|
2023-11-21 01:29:46 -05:00
|
|
|
Hyprland.sendMessage('dispatch ' +
|
|
|
|
'togglespecialworkspace spot');
|
2023-11-13 13:19:14 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-12-20 17:14:07 -05:00
|
|
|
Hyprland.sendMessage('j/clients').then((msg) => {
|
2024-01-13 11:15:08 -05:00
|
|
|
const clients = JSON.parse(msg) as Array<Client>;
|
|
|
|
const classes = [] as Array<string>;
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-20 17:14:07 -05:00
|
|
|
for (const key of clients) {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (key.class) {
|
2023-11-13 13:19:14 -05:00
|
|
|
classes.push(key.class);
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-13 13:19:14 -05:00
|
|
|
}
|
|
|
|
|
2023-12-20 17:14:07 -05:00
|
|
|
if (wmClass && classes.includes(wmClass)) {
|
2023-11-21 01:29:46 -05:00
|
|
|
Hyprland.sendMessage('dispatch ' +
|
|
|
|
`focuswindow ^(${wmClass})`);
|
2023-11-13 13:19:14 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-12-21 01:25:59 -05:00
|
|
|
Hyprland.sendMessage('dispatch workspace empty')
|
|
|
|
.then(() => {
|
|
|
|
app.launch();
|
|
|
|
});
|
2023-11-13 13:19:14 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
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) {
|
2023-12-18 23:20:32 -05:00
|
|
|
return CursorBox({
|
2024-01-29 18:54:07 -05:00
|
|
|
on_primary_click_release: (self) => {
|
|
|
|
iconCmd(self);
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'start',
|
2023-10-20 23:11:21 -04:00
|
|
|
hexpand: false,
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: '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';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-01-14 20:52:30 -05:00
|
|
|
if (lookUpIcon(notif.app_icon)) {
|
|
|
|
icon = notif.app_icon;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-17 13:47:02 -04:00
|
|
|
|
|
|
|
|
2024-01-14 20:52:30 -05:00
|
|
|
if (notif.app_entry && lookUpIcon(notif.app_entry)) {
|
|
|
|
icon = notif.app_entry;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-09-15 15:49:43 -04:00
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
return CursorBox({
|
2024-01-29 18:54:07 -05:00
|
|
|
on_primary_click_release: (self) => {
|
|
|
|
iconCmd(self);
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'start',
|
2023-10-20 23:11:21 -04:00
|
|
|
hexpand: false,
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'icon',
|
2023-11-21 01:29:46 -05:00
|
|
|
css: `
|
|
|
|
min-width: 78px;
|
|
|
|
min-height: 78px;
|
|
|
|
`,
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [Icon({
|
2024-01-22 10:23:32 -05:00
|
|
|
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',
|
2024-01-13 11:15:08 -05:00
|
|
|
command = () => {/**/},
|
|
|
|
}: NotificationWidget) => {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (!notif) {
|
2023-11-03 15:28:08 -04:00
|
|
|
return;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-03 15:28:08 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
const BlockedApps = [
|
|
|
|
'Spotify',
|
|
|
|
];
|
|
|
|
|
2024-01-14 20:52:30 -05:00
|
|
|
if (BlockedApps.find((app) => app === notif.app_name)) {
|
2023-10-20 23:11:21 -04:00
|
|
|
notif.close();
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
HasNotifs.value = Notifications.notifications.length > 0;
|
|
|
|
|
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
|
2024-01-29 18:54:07 -05:00
|
|
|
(notifWidget.child as EventBoxGeneric).add(Box({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: `notification ${notif.urgency}`,
|
2023-11-03 15:28:08 -04:00
|
|
|
vexpand: false,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
// Notification
|
2023-10-20 23:11:21 -04:00
|
|
|
child: Box({
|
2023-11-03 15:28:08 -04:00
|
|
|
vertical: true,
|
|
|
|
children: [
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
// Content
|
|
|
|
Box({
|
|
|
|
children: [
|
|
|
|
NotificationIcon(notif),
|
2023-12-20 17:14:07 -05:00
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
Box({
|
|
|
|
hexpand: true,
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
// Top of Content
|
|
|
|
Box({
|
|
|
|
children: [
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
// Title
|
2023-11-03 15:28:08 -04:00
|
|
|
Label({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'title',
|
2023-11-03 15:28:08 -04:00
|
|
|
xalign: 0,
|
|
|
|
justification: 'left',
|
|
|
|
hexpand: true,
|
2023-12-20 17:14:07 -05:00
|
|
|
max_width_chars: 24,
|
2023-11-03 15:28:08 -04:00
|
|
|
truncate: 'end',
|
|
|
|
wrap: true,
|
|
|
|
label: notif.summary,
|
2023-12-20 17:14:07 -05:00
|
|
|
use_markup: notif.summary
|
2023-11-21 01:29:46 -05:00
|
|
|
.startsWith('<'),
|
2023-11-03 15:28:08 -04:00
|
|
|
}),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
// Time
|
2023-11-03 15:28:08 -04:00
|
|
|
Label({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'time',
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'start',
|
2023-11-03 15:28:08 -04:00
|
|
|
label: setTime(notif.time),
|
|
|
|
}),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
// Close button
|
2023-12-18 23:20:32 -05:00
|
|
|
CursorBox({
|
2023-11-03 15:28:08 -04:00
|
|
|
child: Button({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'close-button',
|
2023-11-06 20:10:12 -05:00
|
|
|
vpack: 'start',
|
2023-12-20 17:14:07 -05:00
|
|
|
|
|
|
|
on_primary_click_release: () =>
|
|
|
|
notif.close(),
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
child: Icon('window-close' +
|
|
|
|
'-symbolic'),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-11-03 15:28:08 -04:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
// Description
|
2023-11-03 15:28:08 -04:00
|
|
|
Label({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'description',
|
2023-11-03 15:28:08 -04:00
|
|
|
hexpand: true,
|
2023-12-20 17:14:07 -05:00
|
|
|
use_markup: true,
|
2023-11-03 15:28:08 -04:00
|
|
|
xalign: 0,
|
|
|
|
justification: 'left',
|
|
|
|
label: notif.body,
|
|
|
|
wrap: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
// Actions
|
|
|
|
Box({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'actions',
|
2023-11-21 01:29:46 -05:00
|
|
|
children: notif.actions.map((action) => Button({
|
2023-12-20 17:14:07 -05:00
|
|
|
class_name: 'action-button',
|
2023-11-03 15:28:08 -04:00
|
|
|
hexpand: true,
|
2023-12-20 17:14:07 -05:00
|
|
|
|
|
|
|
on_primary_click_release: () => notif.invoke(action.id),
|
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
child: Label(action.label),
|
|
|
|
})),
|
|
|
|
}),
|
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-11-03 15:28:08 -04:00
|
|
|
}));
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-03 15:28:08 -04:00
|
|
|
return notifWidget;
|
2023-09-19 10:22:08 -04:00
|
|
|
};
|