audio: replace reactive reduce with imperative node categorisation

This commit is contained in:
2 * r + 2 * t 2026-03-12 21:55:22 +11:00
parent 9464c72f7a
commit c14db315f6

View file

@ -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]
}