✨ ags(bar, notifications, control-center): add status icons to bar, notification history fixed, notification history below control-center
This commit is contained in:
+21
-2
@@ -1,4 +1,6 @@
|
||||
import { Astal } from "astal/gtk3";
|
||||
import AstalApps from "gi://AstalApps";
|
||||
import AstalHyprland from "gi://AstalHyprland";
|
||||
|
||||
const astalApps: AstalApps.Apps = new AstalApps.Apps();
|
||||
let appsList: Array<AstalApps.Application> = astalApps.get_list();
|
||||
@@ -16,6 +18,10 @@ export function getAstalApps(): AstalApps.Apps {
|
||||
return astalApps;
|
||||
}
|
||||
|
||||
export function cleanExec(app: AstalApps.Application): void {
|
||||
AstalHyprland.get_default().dispatch("exec", app.executable.replace(/(%f|%F|%u|%U|%i|%c|%k)/g, ""));
|
||||
}
|
||||
|
||||
export function getAppsByName(appName: string): (Array<AstalApps.Application>|undefined) {
|
||||
let found: Array<AstalApps.Application> = [];
|
||||
|
||||
@@ -29,6 +35,19 @@ export function getAppsByName(appName: string): (Array<AstalApps.Application>|un
|
||||
}
|
||||
|
||||
export function getAppIcon(appName: string): (string|undefined) {
|
||||
const found: (Array<AstalApps.Application>|undefined) = getAppsByName(appName);
|
||||
return found ? found[0]?.iconName : undefined;
|
||||
if(Astal.Icon.lookup_icon(appName))
|
||||
return appName;
|
||||
|
||||
if(Astal.Icon.lookup_icon(appName.toLowerCase()))
|
||||
return appName.toLowerCase();
|
||||
|
||||
const nameReverseDNS = appName.split('.');
|
||||
if(Astal.Icon.lookup_icon(nameReverseDNS[nameReverseDNS.length - 1]))
|
||||
return nameReverseDNS[nameReverseDNS.length - 1];
|
||||
|
||||
const found: (AstalApps.Application|undefined) = getAppsByName(appName)?.[0];
|
||||
if(Boolean(found))
|
||||
return found?.iconName;
|
||||
|
||||
return "application-x-executable-symbolic";
|
||||
}
|
||||
|
||||
@@ -6,13 +6,24 @@ export const
|
||||
NOTIFICATION_TIMEOUT_NORMAL: number = 4000,
|
||||
NOTIFICATION_TIMEOUT_LOW: number = 2000;
|
||||
|
||||
export interface HistoryNotification {
|
||||
id: number;
|
||||
appName: string;
|
||||
body: string;
|
||||
summary: string;
|
||||
urgency: AstalNotifd.Urgency;
|
||||
time: number;
|
||||
image?: string;
|
||||
}
|
||||
|
||||
@register({ GTypeName: "Notifications" })
|
||||
class Notifications extends GObject.Object {
|
||||
private static instance: (Notifications|null) = null;
|
||||
|
||||
#notifications: Array<AstalNotifd.Notification> = [];
|
||||
#history: Array<AstalNotifd.Notification> = [];
|
||||
#history: Array<HistoryNotification> = [];
|
||||
#connections: Array<number>;
|
||||
#historyLimit: number = 10;
|
||||
|
||||
|
||||
@property()
|
||||
@@ -21,6 +32,14 @@ class Notifications extends GObject.Object {
|
||||
@property()
|
||||
public get history() { return this.#history };
|
||||
|
||||
@property()
|
||||
public get historyLimit() { return this.#historyLimit };
|
||||
|
||||
public set historyLimit(newValue: number) {
|
||||
this.#historyLimit = newValue;
|
||||
this.notify("historyLimit");
|
||||
}
|
||||
|
||||
|
||||
@signal(AstalNotifd.Notification)
|
||||
declare notificationAdded: (notification: AstalNotifd.Notification) => void;
|
||||
@@ -28,7 +47,7 @@ class Notifications extends GObject.Object {
|
||||
@signal(Number)
|
||||
declare notificationRemoved: (id: number) => void;
|
||||
|
||||
@signal(AstalNotifd.Notification)
|
||||
@signal(Object)
|
||||
declare historyAdded: (notification: AstalNotifd.Notification) => void;
|
||||
|
||||
@signal(Number)
|
||||
@@ -42,7 +61,7 @@ class Notifications extends GObject.Object {
|
||||
super();
|
||||
|
||||
this.#connections = [
|
||||
AstalNotifd.get_default().connect("notified", (notifd, id, _replaced) => {
|
||||
AstalNotifd.get_default().connect("notified", (notifd, id) => {
|
||||
const notification = notifd.get_notification(id);
|
||||
const notifTimeout = notification.urgency === AstalNotifd.Urgency.LOW ?
|
||||
NOTIFICATION_TIMEOUT_LOW
|
||||
@@ -50,29 +69,39 @@ class Notifications extends GObject.Object {
|
||||
NOTIFICATION_TIMEOUT_URGENT
|
||||
: NOTIFICATION_TIMEOUT_NORMAL);
|
||||
|
||||
if(this.getNotifd().dontDisturb) {
|
||||
this.addHistory(notification, () => notification.dismiss());
|
||||
return;
|
||||
}
|
||||
|
||||
this.addNotification(notification, () => {
|
||||
if(notification.urgency !== AstalNotifd.Urgency.CRITICAL ||
|
||||
(notification.urgency === AstalNotifd.Urgency.CRITICAL &&
|
||||
NOTIFICATION_TIMEOUT_URGENT > 0)) {
|
||||
|
||||
let notifTimer: AstalIO.Time;
|
||||
let notifTimer: (AstalIO.Time|undefined) = undefined;
|
||||
let replacedConnectionId: number;
|
||||
|
||||
const removeFun = () => { // Funny name haha lmao remove fun :skull:
|
||||
this.removeNotification(id);
|
||||
replacedConnectionId && this.disconnect(replacedConnectionId);
|
||||
notifTimer = undefined;
|
||||
this.addHistory(notification, () => {
|
||||
replacedConnectionId && this.disconnect(replacedConnectionId);
|
||||
this.removeNotification(id);
|
||||
});
|
||||
}
|
||||
|
||||
notifTimer = timeout(notifTimeout, removeFun);
|
||||
|
||||
replacedConnectionId = this.connect("notification-replaced", (_, id: number) => {
|
||||
if(notification.id === id) {
|
||||
notifTimer.cancel();
|
||||
notifTimer?.cancel();
|
||||
notifTimer = timeout(notifTimeout, removeFun);
|
||||
}
|
||||
});
|
||||
|
||||
notifTimer = timeout(notifTimeout, removeFun);
|
||||
}
|
||||
});
|
||||
}),
|
||||
|
||||
AstalNotifd.get_default().connect("resolved", (notifd, id, _reason) => {
|
||||
this.removeNotification(id);
|
||||
this.addHistory(notifd.get_notification(id));
|
||||
@@ -94,17 +123,41 @@ class Notifications extends GObject.Object {
|
||||
}
|
||||
|
||||
private addHistory(notif: AstalNotifd.Notification, onAdded?: (notif: AstalNotifd.Notification) => void): void {
|
||||
const newArray = this.#history.reverse().filter((item) => item.id !== notif.id);
|
||||
newArray.push(notif);
|
||||
if(!notif) return;
|
||||
|
||||
this.#history.length === this.#historyLimit &&
|
||||
this.removeHistory(this.#history[this.#history.length - 1]);
|
||||
|
||||
const newArray = this.#history.length > 0 ? this.#history.reverse().filter((item) => item.id !== notif.id) : [];
|
||||
newArray.push({
|
||||
id: notif.id,
|
||||
appName: notif.appName,
|
||||
body: notif.body,
|
||||
summary: notif.summary,
|
||||
urgency: notif.urgency,
|
||||
time: notif.time,
|
||||
image: notif.image ? notif.image : undefined
|
||||
} as HistoryNotification);
|
||||
this.#history = newArray.reverse();
|
||||
this.notify("history");
|
||||
this.emit("history-added", notif);
|
||||
this.emit("history-added", this.#history[0]);
|
||||
onAdded && onAdded(notif);
|
||||
}
|
||||
|
||||
public removeHistory(notif: (AstalNotifd.Notification|number)): void {
|
||||
const notifId = (notif instanceof AstalNotifd.Notification) ? notif.id : notif;
|
||||
this.#history = this.#history.filter((item: AstalNotifd.Notification) =>
|
||||
public clearHistory(): void {
|
||||
for(let i = 0; i < this.history.length; i++) {
|
||||
const notif = this.history[this.history.length-1];
|
||||
|
||||
if(this.#history.pop()) {
|
||||
this.emit("history-removed", notif.id);
|
||||
this.notify("history");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public removeHistory(notif: (HistoryNotification|number)): void {
|
||||
const notifId = (typeof notif === "number") ? notif : notif.id;
|
||||
this.#history = this.#history.filter((item: HistoryNotification) =>
|
||||
item.id !== notifId);
|
||||
|
||||
this.notify("history");
|
||||
@@ -125,21 +178,27 @@ class Notifications extends GObject.Object {
|
||||
}
|
||||
|
||||
public removeNotification(notif: (AstalNotifd.Notification|number)): void {
|
||||
const notification = (notif instanceof AstalNotifd.Notification) ? notif : AstalNotifd.get_default().get_notification(notif);
|
||||
const notificationId = (notif instanceof AstalNotifd.Notification) ? notif.id : notif;
|
||||
this.#notifications = this.#notifications.filter((item: AstalNotifd.Notification) =>
|
||||
item.id !== notification.id);
|
||||
item.id !== notificationId);
|
||||
|
||||
notification.dismiss();
|
||||
AstalNotifd.get_default().get_notification(notificationId)?.dismiss();
|
||||
this.notify("notifications");
|
||||
this.emit("notification-removed", notification.id);
|
||||
this.emit("notification-removed", notificationId);
|
||||
}
|
||||
|
||||
public toggleDoNotDisturb(): boolean {
|
||||
if(AstalNotifd.get_default().dontDisturb) {
|
||||
|
||||
AstalNotifd.get_default().dontDisturb = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
AstalNotifd.get_default().dontDisturb = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public getNotifd(): AstalNotifd.Notifd { return AstalNotifd.get_default(); }
|
||||
|
||||
connect(signal: string, callback: (...args: any[]) => void): number {
|
||||
return super.connect(signal, callback);
|
||||
}
|
||||
|
||||
+21
-21
@@ -71,42 +71,42 @@ class WireplumberClass extends GObject.Object {
|
||||
);
|
||||
}
|
||||
|
||||
public increaseSinkVolume(volumeIncrease: number): void {
|
||||
if((this.getSinkVolume() + volumeIncrease) > this.maxSinkVolume) {
|
||||
this.setSinkVolume(this.maxSinkVolume);
|
||||
public increaseEndpointVolume(endpoint: AstalWp.Endpoint, volumeIncrease: number): void {
|
||||
volumeIncrease = Math.abs(volumeIncrease) / 100;
|
||||
|
||||
if((endpoint.get_volume() + volumeIncrease) > this.maxSinkVolume) {
|
||||
endpoint.set_volume(1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
this.setSinkVolume(this.getSinkVolume() + volumeIncrease);
|
||||
endpoint.set_volume(endpoint.get_volume() + volumeIncrease);
|
||||
}
|
||||
|
||||
public increaseSinkVolume(volumeIncrease: number): void {
|
||||
this.increaseEndpointVolume(this.getDefaultSink(), volumeIncrease);
|
||||
}
|
||||
|
||||
public increaseSourceVolume(volumeIncrease: number): void {
|
||||
if((this.getSourceVolume() + volumeIncrease) > this.maxSourceVolume) {
|
||||
this.setSourceVolume(this.maxSourceVolume);
|
||||
this.increaseEndpointVolume(this.getDefaultSource(), volumeIncrease);
|
||||
}
|
||||
|
||||
public decreaseEndpointVolume(endpoint: AstalWp.Endpoint, volumeDecrease: number): void {
|
||||
volumeDecrease = Math.abs(volumeDecrease) / 100;
|
||||
|
||||
if((endpoint.get_volume() - volumeDecrease) < 0) {
|
||||
endpoint.set_volume(0);
|
||||
return;
|
||||
}
|
||||
|
||||
this.setSourceVolume(this.getSourceVolume() + volumeIncrease);
|
||||
endpoint.set_volume(endpoint.get_volume() - volumeDecrease);
|
||||
}
|
||||
|
||||
public decreaseSinkVolume(volumeDecrease: number): void {
|
||||
const absDecrease = Math.abs(volumeDecrease);
|
||||
|
||||
if((this.getSinkVolume() - absDecrease) < 0) {
|
||||
this.setSinkVolume(0);
|
||||
return;
|
||||
}
|
||||
|
||||
this.setSinkVolume(this.getSinkVolume() - absDecrease);
|
||||
this.decreaseEndpointVolume(this.getDefaultSink(), volumeDecrease);
|
||||
}
|
||||
|
||||
public decreaseSourceVolume(volumeDecrease: number): void {
|
||||
const absDecrease = Math.abs(volumeDecrease);
|
||||
|
||||
if((this.getSourceVolume() - absDecrease) < 0)
|
||||
return this.setSourceVolume(0);
|
||||
|
||||
this.setSourceVolume(this.getSourceVolume() - absDecrease);
|
||||
this.decreaseEndpointVolume(this.getDefaultSource(), volumeDecrease);
|
||||
}
|
||||
|
||||
public muteSink(): void {
|
||||
|
||||
Reference in New Issue
Block a user