From 650fd4b58f708c185d252f854a5770a957cb2f86 Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Sat, 31 May 2025 20:28:30 -0300 Subject: [PATCH] :boom: fix(control-center/pages): sound and microphone pages using old astalwp methods --- ags/widget/control-center/pages/Microphone.ts | 18 +++---- ags/widget/control-center/pages/Sound.ts | 48 +++++++++++-------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/ags/widget/control-center/pages/Microphone.ts b/ags/widget/control-center/pages/Microphone.ts index a3e2b73..8444612 100644 --- a/ags/widget/control-center/pages/Microphone.ts +++ b/ags/widget/control-center/pages/Microphone.ts @@ -1,6 +1,5 @@ import { bind } from "astal"; import { Page, PageButton, PageProps } from "./Page"; -import AstalWp from "gi://AstalWp?version=0.1"; import { Wireplumber } from "../../../scripts/volume"; import { Astal, Widget } from "astal/gtk3"; import { tr } from "../../../i18n/intl"; @@ -11,21 +10,22 @@ export function PageMicrophone(): Page { id: "microphone", title: tr("control_center.pages.microphone.title"), description: tr("control_center.pages.microphone.description"), - children: bind(Wireplumber.getWireplumber(), "endpoints").as((endpoints) => [ + children: bind(Wireplumber.getWireplumber().get_audio()!, "microphones").as((microphones) => [ new Widget.Label({ className: "sub-header", label: tr("devices"), - setup: (self) => self.set_alignment(0, .5) + xalign: 0 } as Widget.LabelProps), - ...endpoints.filter(ep => ep.mediaClass === AstalWp.MediaClass.AUDIO_MICROPHONE).map((ep) => + ...microphones.map((microphone) => PageButton({ - className: bind(ep, "isDefault").as(isDefault => isDefault ? "default" : ""), - icon: Astal.Icon.lookup_icon(ep.icon) ? ep.icon : "audio-input-microphone-symbolic", - title: ep.name ?? "Microphone", - onClick: () => ep.set_is_default(true), + className: bind(microphone, "isDefault").as(isDefault => isDefault ? "default" : ""), + icon: bind(microphone, "icon").as(icon => + Astal.Icon.lookup_icon(icon) ? icon : "audio-input-microphone-symbolic"), + title: bind(microphone, "name").as(name => name ?? "Microphone"), + onClick: () => microphone.set_is_default(true), endWidget: new Widget.Icon({ icon: "object-select-symbolic", - visible: bind(ep, "isDefault"), + visible: bind(microphone, "isDefault"), css: "font-size: 18px;" } as Widget.IconProps) }) diff --git a/ags/widget/control-center/pages/Sound.ts b/ags/widget/control-center/pages/Sound.ts index dc4aa84..17b8a8d 100644 --- a/ags/widget/control-center/pages/Sound.ts +++ b/ags/widget/control-center/pages/Sound.ts @@ -1,31 +1,37 @@ import { Page, PageButton, PageProps } from "./Page"; -import { bind } from "astal"; +import { bind, Variable } from "astal"; import { Astal, Gtk, Widget } from "astal/gtk3"; -import AstalWp from "gi://AstalWp"; import { getAppIcon } from "../../../scripts/apps"; import { Wireplumber } from "../../../scripts/volume"; import { tr } from "../../../i18n/intl"; export function PageSound(): Page { + const endpoints = Variable.derive([ + bind(Wireplumber.getWireplumber().get_audio()!, "speakers"), + bind(Wireplumber.getWireplumber().get_audio()!, "streams") + ]); + return new Page({ id: "sound", title: tr("control_center.pages.sound.title"), description: tr("control_center.pages.sound.description"), - children: bind(Wireplumber.getWireplumber(), "endpoints").as((endpoints) => [ + onClose: endpoints.drop, + children: endpoints(([speakers, streams]) => [ new Widget.Label({ className: "sub-header", label: tr("devices"), - setup: (self) => self.set_alignment(0, .5) + xalign: 0 } as Widget.LabelProps), - ...endpoints.filter(ep => ep.mediaClass === AstalWp.MediaClass.AUDIO_SPEAKER).map((ep) => + ...speakers.map((speaker) => PageButton({ - className: bind(ep, "isDefault").as(isDefault => isDefault ? "default" : ""), - icon: Astal.Icon.lookup_icon(ep.icon) ? ep.icon : "audio-card-symbolic", - title: ep.name ?? "Speaker", - onClick: () => ep.set_is_default(true), + className: bind(speaker, "isDefault").as(isDefault => isDefault ? "default" : ""), + icon: bind(speaker, "icon").as(icon => + Astal.Icon.lookup_icon(icon)? icon : "audio-card-symbolic"), + title: speaker.name ?? "Speaker", + onClick: () => speaker.set_is_default(true), endWidget: new Widget.Icon({ icon: "object-select-symbolic", - visible: bind(ep, "isDefault"), + visible: bind(speaker, "isDefault"), css: "font-size: 18px;" } as Widget.IconProps) }) @@ -33,21 +39,21 @@ export function PageSound(): Page { new Widget.Label({ className: "sub-header", label: tr("apps"), - visible: endpoints.filter((ep) => ep.mediaClass === AstalWp.MediaClass.AUDIO_STREAM || - ep.mediaClass === AstalWp.MediaClass.VIDEO_STREAM).length > 0, - setup: (self) => self.set_alignment(0, .5) + visible: streams.length > 0, + xalign: 0 } as Widget.LabelProps), - ...endpoints.filter((ep) => ep.mediaClass === AstalWp.MediaClass.AUDIO_STREAM || - ep.mediaClass === AstalWp.MediaClass.VIDEO_STREAM).map((ep) => + ...streams.map((stream) => new Widget.EventBox({ hexpand: true, setup: (eventbox) => { const connections: Array = []; + eventbox.add(new Widget.Box({ orientation: Gtk.Orientation.HORIZONTAL, children: [ new Widget.Icon({ - icon: getAppIcon(ep.name.split(' ')[0]) || "application-x-executable-symbolic", + icon: bind(stream, "name").as(name => + getAppIcon(name.split(' ')[0]) ?? "application-x-executable-symbolic"), css: "font-size: 18px; margin-right: 6px;" } as Widget.IconProps), new Widget.Box({ @@ -63,9 +69,9 @@ export function PageSound(): Page { ), onDestroy: () => connections.map(id => eventbox.disconnect(id)), child: new Widget.Label({ - label: ep.name || "Unknown", + label: bind(stream, "name").as(name => name || "Unknown"), truncate: true, - tooltipText: ep.name, + tooltipText: bind(stream, "name"), className: "name", xalign: 0 } as Widget.LabelProps) @@ -74,9 +80,9 @@ export function PageSound(): Page { min: 0, drawValue: false, max: 100, - setup: (self) => self.value = Math.floor(ep.volume * 100), - value: bind(ep, "volume").as((vol) => Math.floor(vol * 100)), - onDragged: (self) => ep.volume = self.value / 100 + setup: (self) => self.value = Math.floor(stream.volume * 100), + value: bind(stream, "volume").as((vol) => Math.floor(vol * 100)), + onDragged: (self) => stream.volume = self.value / 100 } as Widget.SliderProps) ] } as Widget.BoxProps)