ags: finish center-window widget with big-media and calendar

This commit is contained in:
retrozinndev
2025-02-16 19:29:03 -03:00
parent 1e6b3bcbe3
commit 23d3b271b4
19 changed files with 394 additions and 181 deletions
+51 -44
View File
@@ -1,29 +1,30 @@
import AstalNotifd from "gi://AstalNotifd";
import { timeout } from "astal/time";
import { Connectable } from "astal/binding";
import { GObject, register, signal } from "astal";
import { Subscribable } from "astal/binding";
import { GObject, property, register, Variable } from "astal";
import { Windows } from "../windows";
import { FloatingNotifications } from "../window/FloatingNotifications";
@register({ GTypeName: "Notifications" })
class NotificationsClass extends GObject.Object implements Connectable {
class NotificationsClass extends GObject.Object implements Subscribable {
private static instance: NotificationsClass;
@property(AstalNotifd.Notifd)
private notifd: AstalNotifd.Notifd;
public notifications: Array<AstalNotifd.Notification> = [];
@property(Boolean)
private doNotDisturb: boolean = false;
@property()
public notificationHistory: Array<AstalNotifd.Notification> = [];
@signal(AstalNotifd.Notification)
declare notificationAdded: (added: AstalNotifd.Notification) => void;
@signal(Number)
declare notificationRemoved: (id: number) => void;
@property()
public notifications: Variable<Array<AstalNotifd.Notification>> = new Variable<Array<AstalNotifd.Notification>>([]);
public static getDefault(): NotificationsClass {
if(!NotificationsClass.instance) {
NotificationsClass.instance = new NotificationsClass();
this.instance._init();
}
return NotificationsClass.instance;
@@ -36,13 +37,28 @@ class NotificationsClass extends GObject.Object implements Connectable {
dontDisturb: false
} as AstalNotifd.Notifd.ConstructorProps);
this.getNotifd().connect("notified", (_source: AstalNotifd.Notifd, id: number, _replaced: boolean) => {
this.addNotification(this.getNotifd().get_notification(id));
this.getNotifd().connect("notified", (daemon: AstalNotifd.Notifd, id: number) => {
const notification: (AstalNotifd.Notification|null) = daemon.get_notification(id);
if(!notification) {
console.log("[LOG] Notification is null, ignoring");
return;
}
if(!this.doNotDisturb) {
this.handleNotification(notification);
return;
}
this.addHistory(notification);
});
}
public addNotification(notification: AstalNotifd.Notification) {
this.prependArray(this.notifications, this.getNotifd().get_notification(notification.id));
public handleNotification(notification: AstalNotifd.Notification): void {
Windows.open(FloatingNotifications);
let tmpArray = this.notifications.get().reverse();
tmpArray.push(notification);
this.notifications.set(tmpArray.reverse());
// default timeout if undefined
let notificationTimeout = 4000;
@@ -56,47 +72,38 @@ class NotificationsClass extends GObject.Object implements Connectable {
break;
}
notification.urgency !== AstalNotifd.Urgency.CRITICAL ?
notification.urgency !== AstalNotifd.Urgency.CRITICAL &&
timeout(notificationTimeout, () => {
this.notifications.map((item: AstalNotifd.Notification) =>
item.id === notification.id && (() => {
this.removeNotification(notification.id);
this.addToNotificationHistory(notification);
})())
})
: this.addToNotificationHistory(notification);
notification.dismiss();
this.notifications.set(this.notifications.get().filter((item) => item.id !== notification.id));
this.addHistory(notification);
});
this.emit("notification-added", notification);
}
public removeNotification(notificationId: number) {
if(this.notifications.length === 1)
Windows.close(Windows.getWindow("floating-notifications")!);
this.notifications = this.notifications.filter((notification: AstalNotifd.Notification) =>
notification.id !== notificationId);
this.emit("notification-removed", notificationId);
public addHistory(notification: AstalNotifd.Notification): void {
let tmpArray: Array<AstalNotifd.Notification> = this.notificationHistory.reverse()
.filter((item: AstalNotifd.Notification) => item.id !== notification.id);
tmpArray.push(notification);
this.notificationHistory = tmpArray.reverse();
}
public addToNotificationHistory(notification: AstalNotifd.Notification) {
this.prependArray(this.notificationHistory, notification);
}
public removeFromNotificationHistory(notificationId: number) {
public removeHistory(notification: AstalNotifd.Notification) {
this.notificationHistory = this.notificationHistory.filter((curNotification: AstalNotifd.Notification) =>
curNotification.id !== notificationId);
}
private prependArray(array: Array<any>, item: any): Array<any> {
let tmpArray = array.reverse();
tmpArray.push(item);
return tmpArray.reverse();
curNotification.id !== notification.id);
}
public getNotifd(): AstalNotifd.Notifd {
return this.notifd;
}
get() {
return this.notifications.get();
}
subscribe(callback: (list: Array<AstalNotifd.Notification>) => void) {
return this.notifications.subscribe(callback);
}
}
export const Notifications = new NotificationsClass();
View File
View File