pragma Singleton import QtQuick import Quickshell import Quickshell.Io Singleton { id: root property int consumers: 0 // Desktop visualizer widgets request Cava regardless of the media card's toggle. property int widgetConsumers: 0 property var bars: Array(24).fill(0) property string error: "" property int frames: 0 property bool failed: false readonly property bool wanted: ConfigService.ready && MediaService.playing && ((ConfigService.data.media.showCava && consumers > 0) || widgetConsumers > 0) onWantedChanged: { if (!wanted) { failed = false; error = ""; bars = Array(24).fill(0); } } Process { id: process command: ["python3", Quickshell.shellPath("helpers/cava.py"), Quickshell.shellPath("config/cava.conf")] running: root.wanted && !root.failed stdout: SplitParser { onRead: data => { const values = data.trim().split(";").filter(v => v.length).map(Number); if (values.length === 24 && values.every(v => Number.isFinite(v) && v >= 0 && v <= 1000)) { root.bars = values.map(v => v / 1000); root.frames++; } } } stderr: StdioCollector { id: errors } // Quickshell 0.3.1 metadata omits QProcess::ExitStatus. // qmllint disable signal-handler-parameters onExited: code => { if (root.wanted) { root.failed = true; root.error = errors.text.trim().slice(0, 300) || "Cava stopped (" + code + ")"; } } } IpcHandler { target: "cava" function status(): string { return JSON.stringify({ running: process.running, error: root.error, bars: root.bars, frames: root.frames, consumers: root.consumers }); } } }