Merge pull request #6 from retrozinndev/fix/sound-page

💥 Fix: Sound and Microphone pages not opening
This commit is contained in:
João Dias
2025-05-31 20:59:22 -03:00
committed by GitHub
2 changed files with 36 additions and 30 deletions
@@ -1,6 +1,5 @@
import { bind } from "astal"; import { bind } from "astal";
import { Page, PageButton, PageProps } from "./Page"; import { Page, PageButton, PageProps } from "./Page";
import AstalWp from "gi://AstalWp?version=0.1";
import { Wireplumber } from "../../../scripts/volume"; import { Wireplumber } from "../../../scripts/volume";
import { Astal, Widget } from "astal/gtk3"; import { Astal, Widget } from "astal/gtk3";
import { tr } from "../../../i18n/intl"; import { tr } from "../../../i18n/intl";
@@ -11,21 +10,22 @@ export function PageMicrophone(): Page {
id: "microphone", id: "microphone",
title: tr("control_center.pages.microphone.title"), title: tr("control_center.pages.microphone.title"),
description: tr("control_center.pages.microphone.description"), 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({ new Widget.Label({
className: "sub-header", className: "sub-header",
label: tr("devices"), label: tr("devices"),
setup: (self) => self.set_alignment(0, .5) xalign: 0
} as Widget.LabelProps), } as Widget.LabelProps),
...endpoints.filter(ep => ep.mediaClass === AstalWp.MediaClass.AUDIO_MICROPHONE).map((ep) => ...microphones.map((microphone) =>
PageButton({ PageButton({
className: bind(ep, "isDefault").as(isDefault => isDefault ? "default" : ""), className: bind(microphone, "isDefault").as(isDefault => isDefault ? "default" : ""),
icon: Astal.Icon.lookup_icon(ep.icon) ? ep.icon : "audio-input-microphone-symbolic", icon: bind(microphone, "icon").as(icon =>
title: ep.name ?? "Microphone", Astal.Icon.lookup_icon(icon) ? icon : "audio-input-microphone-symbolic"),
onClick: () => ep.set_is_default(true), title: bind(microphone, "name").as(name => name ?? "Microphone"),
onClick: () => microphone.set_is_default(true),
endWidget: new Widget.Icon({ endWidget: new Widget.Icon({
icon: "object-select-symbolic", icon: "object-select-symbolic",
visible: bind(ep, "isDefault"), visible: bind(microphone, "isDefault"),
css: "font-size: 18px;" css: "font-size: 18px;"
} as Widget.IconProps) } as Widget.IconProps)
}) })
+27 -21
View File
@@ -1,31 +1,37 @@
import { Page, PageButton, PageProps } from "./Page"; import { Page, PageButton, PageProps } from "./Page";
import { bind } from "astal"; import { bind, Variable } from "astal";
import { Astal, Gtk, Widget } from "astal/gtk3"; import { Astal, Gtk, Widget } from "astal/gtk3";
import AstalWp from "gi://AstalWp";
import { getAppIcon } from "../../../scripts/apps"; import { getAppIcon } from "../../../scripts/apps";
import { Wireplumber } from "../../../scripts/volume"; import { Wireplumber } from "../../../scripts/volume";
import { tr } from "../../../i18n/intl"; import { tr } from "../../../i18n/intl";
export function PageSound(): Page { export function PageSound(): Page {
const endpoints = Variable.derive([
bind(Wireplumber.getWireplumber().get_audio()!, "speakers"),
bind(Wireplumber.getWireplumber().get_audio()!, "streams")
]);
return new Page({ return new Page({
id: "sound", id: "sound",
title: tr("control_center.pages.sound.title"), title: tr("control_center.pages.sound.title"),
description: tr("control_center.pages.sound.description"), description: tr("control_center.pages.sound.description"),
children: bind(Wireplumber.getWireplumber(), "endpoints").as((endpoints) => [ onClose: endpoints.drop,
children: endpoints(([speakers, streams]) => [
new Widget.Label({ new Widget.Label({
className: "sub-header", className: "sub-header",
label: tr("devices"), label: tr("devices"),
setup: (self) => self.set_alignment(0, .5) xalign: 0
} as Widget.LabelProps), } as Widget.LabelProps),
...endpoints.filter(ep => ep.mediaClass === AstalWp.MediaClass.AUDIO_SPEAKER).map((ep) => ...speakers.map((speaker) =>
PageButton({ PageButton({
className: bind(ep, "isDefault").as(isDefault => isDefault ? "default" : ""), className: bind(speaker, "isDefault").as(isDefault => isDefault ? "default" : ""),
icon: Astal.Icon.lookup_icon(ep.icon) ? ep.icon : "audio-card-symbolic", icon: bind(speaker, "icon").as(icon =>
title: ep.name ?? "Speaker", Astal.Icon.lookup_icon(icon)? icon : "audio-card-symbolic"),
onClick: () => ep.set_is_default(true), title: speaker.name ?? "Speaker",
onClick: () => speaker.set_is_default(true),
endWidget: new Widget.Icon({ endWidget: new Widget.Icon({
icon: "object-select-symbolic", icon: "object-select-symbolic",
visible: bind(ep, "isDefault"), visible: bind(speaker, "isDefault"),
css: "font-size: 18px;" css: "font-size: 18px;"
} as Widget.IconProps) } as Widget.IconProps)
}) })
@@ -33,21 +39,21 @@ export function PageSound(): Page {
new Widget.Label({ new Widget.Label({
className: "sub-header", className: "sub-header",
label: tr("apps"), label: tr("apps"),
visible: endpoints.filter((ep) => ep.mediaClass === AstalWp.MediaClass.AUDIO_STREAM || visible: streams.length > 0,
ep.mediaClass === AstalWp.MediaClass.VIDEO_STREAM).length > 0, xalign: 0
setup: (self) => self.set_alignment(0, .5)
} as Widget.LabelProps), } as Widget.LabelProps),
...endpoints.filter((ep) => ep.mediaClass === AstalWp.MediaClass.AUDIO_STREAM || ...streams.map((stream) =>
ep.mediaClass === AstalWp.MediaClass.VIDEO_STREAM).map((ep) =>
new Widget.EventBox({ new Widget.EventBox({
hexpand: true, hexpand: true,
setup: (eventbox) => { setup: (eventbox) => {
const connections: Array<number> = []; const connections: Array<number> = [];
eventbox.add(new Widget.Box({ eventbox.add(new Widget.Box({
orientation: Gtk.Orientation.HORIZONTAL, orientation: Gtk.Orientation.HORIZONTAL,
children: [ children: [
new Widget.Icon({ 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;" css: "font-size: 18px; margin-right: 6px;"
} as Widget.IconProps), } as Widget.IconProps),
new Widget.Box({ new Widget.Box({
@@ -63,9 +69,9 @@ export function PageSound(): Page {
), ),
onDestroy: () => connections.map(id => eventbox.disconnect(id)), onDestroy: () => connections.map(id => eventbox.disconnect(id)),
child: new Widget.Label({ child: new Widget.Label({
label: ep.name || "Unknown", label: bind(stream, "name").as(name => name || "Unknown"),
truncate: true, truncate: true,
tooltipText: ep.name, tooltipText: bind(stream, "name"),
className: "name", className: "name",
xalign: 0 xalign: 0
} as Widget.LabelProps) } as Widget.LabelProps)
@@ -74,9 +80,9 @@ export function PageSound(): Page {
min: 0, min: 0,
drawValue: false, drawValue: false,
max: 100, max: 100,
setup: (self) => self.value = Math.floor(ep.volume * 100), setup: (self) => self.value = Math.floor(stream.volume * 100),
value: bind(ep, "volume").as((vol) => Math.floor(vol * 100)), value: bind(stream, "volume").as((vol) => Math.floor(vol * 100)),
onDragged: (self) => ep.volume = self.value / 100 onDragged: (self) => stream.volume = self.value / 100
} as Widget.SliderProps) } as Widget.SliderProps)
] ]
} as Widget.BoxProps) } as Widget.BoxProps)