diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 21:55:22 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 21:55:22 +1100 |
| commit | c14db315f64b041b3e87c2997777f1ef2da83905 (patch) | |
| tree | 328573ee758e979225e35929f165d0e7cd1428d8 /services | |
| parent | nmcli: use Map-based lookups for network deduplication (diff) | |
| download | caelestia-shell-c14db315f64b041b3e87c2997777f1ef2da83905.tar.gz caelestia-shell-c14db315f64b041b3e87c2997777f1ef2da83905.tar.bz2 caelestia-shell-c14db315f64b041b3e87c2997777f1ef2da83905.zip | |
audio: replace reactive reduce with imperative node categorisation
Diffstat (limited to 'services')
| -rw-r--r-- | services/Audio.qml | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/services/Audio.qml b/services/Audio.qml index 908d156..14d0a4e 100644 --- a/services/Audio.qml +++ b/services/Audio.qml @@ -13,26 +13,9 @@ Singleton { property string previousSinkName: "" property string previousSourceName: "" - readonly property var nodes: Pipewire.nodes.values.reduce((acc, node) => { - if (!node.isStream) { - if (node.isSink) - acc.sinks.push(node); - else if (node.audio) - acc.sources.push(node); - } else if (node.isStream && node.audio) { - // Application streams (output streams) - acc.streams.push(node); - } - return acc; - }, { - sources: [], - sinks: [], - streams: [] - }) - - readonly property list<PwNode> sinks: nodes.sinks - readonly property list<PwNode> sources: nodes.sources - readonly property list<PwNode> streams: nodes.streams + property list<PwNode> sinks: [] + property list<PwNode> sources: [] + property list<PwNode> streams: [] readonly property PwNode sink: Pipewire.defaultAudioSink readonly property PwNode source: Pipewire.defaultAudioSource @@ -141,6 +124,31 @@ Singleton { previousSourceName = source?.description || source?.name || qsTr("Unknown Device"); } + Connections { + target: Pipewire.nodes + + function onValuesChanged(): void { + const newSinks = []; + const newSources = []; + const newStreams = []; + + for (const node of Pipewire.nodes.values) { + if (!node.isStream) { + if (node.isSink) + newSinks.push(node); + else if (node.audio) + newSources.push(node); + } else if (node.audio) { + newStreams.push(node); + } + } + + root.sinks = newSinks; + root.sources = newSources; + root.streams = newStreams; + } + } + PwObjectTracker { objects: [...root.sinks, ...root.sources, ...root.streams] } |