Cava: Now only runs when a visualizer is in sight.

This commit is contained in:
ItsLemmy
2025-09-23 08:37:16 -04:00
parent 120ed36deb
commit 640a4339db
3 changed files with 32 additions and 5 deletions
+24
View File
@@ -1,11 +1,32 @@
pragma Singleton
import QtQuick
import Quickshell
import qs.Commons
Singleton {
id: root
property bool hasAudioVisualizer: false
// Simple timer that run once when the widget structure has changed
// and determine if any MediaMini widget has the visualizer on
Timer {
id: timerCheckVisualizer
interval: 100
repeat: false
onTriggered: {
hasAudioVisualizer = false
const widgets = getAllWidgetInstances("MediaMini")
for(var i=0; i<widgets.length; i++) {
const widget = widgets[i]
if (widget.showVisualizer) {
hasAudioVisualizer = true
}
}
}
}
// Registry to store actual widget instances
// Key format: "screenName|section|widgetId|index"
property var widgetInstances: ({})
@@ -20,6 +41,9 @@ Singleton {
"index": index,
"instance": instance
}
timerCheckVisualizer.restart()
Logger.log("BarService", "Registered widget:", key)
}
+2 -2
View File
@@ -15,6 +15,7 @@ Singleton {
"Bluetooth": bluetoothComponent,
"Brightness": brightnessComponent,
"Clock": clockComponent,
"ControlCenter": controlCenterComponent,
"CustomButton": customButtonComponent,
"DarkMode": darkMode,
"KeepAwake": keepAwakeComponent,
@@ -24,9 +25,8 @@ Singleton {
"NightLight": nightLightComponent,
"NotificationHistory": notificationHistoryComponent,
"PowerProfile": powerProfileComponent,
"SessionMenu": sessionMenuComponent,
"ScreenRecorder": screenRecorderComponent,
"ControlCenter": controlCenterComponent,
"SessionMenu": sessionMenuComponent,
"Spacer": spacerComponent,
"SystemMonitor": systemMonitorComponent,
"Taskbar": taskbarComponent,
+6 -3
View File
@@ -8,9 +8,9 @@ import qs.Commons
Singleton {
id: root
property bool shouldRun: BarService.hasAudioVisualizer || (PanelService.getPanel("controlCenterPanel") === PanelService.openedPanel)
property var values: Array(barsCount).fill(0)
property int barsCount: 24
property var config: ({
"general": {
"bars": barsCount,
@@ -37,8 +37,11 @@ Singleton {
Process {
id: process
stdinEnabled: true
running: true // Yes, cava should run at all times! Even if no mpris is available.
running: root.shouldRun
command: ["cava", "-p", "/dev/stdin"]
onRunningChanged: {
Logger.log("Cava", "Process running:", running)
}
onExited: {
stdinEnabled = true
values = Array(barsCount).fill(0)
@@ -64,4 +67,4 @@ Singleton {
}
}
}
}
}