cava: implemented restart on crash

This commit is contained in:
Lemmy
2026-02-05 23:08:45 -05:00
parent c2237baab3
commit 7ff6a59c6c
+31 -1
View File
@@ -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;