From 7ff6a59c6cd876083bdd4dca3d87738ba36eb528 Mon Sep 17 00:00:00 2001 From: Lemmy Date: Thu, 5 Feb 2026 23:08:45 -0500 Subject: [PATCH] cava: implemented restart on crash --- Services/Media/CavaService.qml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Services/Media/CavaService.qml b/Services/Media/CavaService.qml index e1a9e88cb..36fa265aa 100644 --- a/Services/Media/CavaService.qml +++ b/Services/Media/CavaService.qml @@ -42,6 +42,10 @@ Singleton { property int idleFrameCount: 0 readonly property int idleThreshold: 30 // Frames of silence before considered idle (0.5s at 60fps) + // Crash tracking for auto-restart + property int _crashCount: 0 + property int _maxCrashes: 5 + // Pre-allocated array for quick parsing property var _parseBuffer: new Array(barsCount) @@ -70,6 +74,18 @@ Singleton { } }) + Timer { + id: restartTimer + interval: 2000 + repeat: false + onTriggered: { + if (root.shouldRun && !process.running) { + Logger.w("Cava", "Restarting after crash..."); + process.running = true; + } + } + } + Process { id: process stdinEnabled: true @@ -79,9 +95,20 @@ Singleton { Logger.d("Cava", "Process running:", running); } onExited: { - Logger.d("Cava", "Process exited"); stdinEnabled = true; values = Array(barsCount).fill(0); + if (root.shouldRun) { + root._crashCount++; + if (root._crashCount <= root._maxCrashes) { + Logger.w("Cava", "Process exited unexpectedly, restarting in 2s... (attempt " + root._crashCount + "/" + root._maxCrashes + ")"); + restartTimer.start(); + } else { + Logger.e("Cava", "Process crashed too many times (" + root._maxCrashes + "), giving up"); + } + } else { + Logger.d("Cava", "Process exited (no longer needed)"); + root._crashCount = 0; + } } onStarted: { Logger.d("Cava", "Process started"); @@ -101,6 +128,9 @@ Singleton { } stdout: SplitParser { onRead: data => { + if (root._crashCount > 0) + root._crashCount = 0; + // Optimized parsing directly into pre-allocated buffer const buffer = root._parseBuffer; let idx = 0;