From 9baf3f7f792176c495bcbe60160e653f14c27d69 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 20 May 2026 19:46:47 +0200 Subject: [PATCH] Fix parseModuleJson undefined call in custom command modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CustomCommandModule.update() in Bar.qml called root.parseModuleJson(raw) but the function was removed in 3b970068 (the indicator split). Any custom command module emitting waybar-style JSON would have crashed on first poll. Hoist the helper into Util so both call sites — the bar's custom command module and BarIndicator.extractData — share one definition. --- shell/Commons/Util.qml | 14 ++++++++++++++ shell/Ui/BarIndicator.qml | 10 +--------- shell/plugins/bar/Bar.qml | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/shell/Commons/Util.qml b/shell/Commons/Util.qml index 9ba8b42b..b5c0cf93 100644 --- a/shell/Commons/Util.qml +++ b/shell/Commons/Util.qml @@ -54,6 +54,20 @@ QtObject { return JSON.parse(JSON.stringify(value === undefined ? null : value)) } + // Parse the last line of a custom-module / indicator process output as + // waybar-style JSON ({text, class, tooltip, ...}). Falls back to {text: raw} + // when the output isn't JSON, and {} for empty output. + function parseModuleJson(raw) { + var text = String(raw || "").trim() + if (!text) return {} + var lines = text.split("\n") + try { + return JSON.parse(lines[lines.length - 1]) + } catch (e) { + return { text: text } + } + } + // Layout normalization shared by the bar host and the bar settings panel // so the two never drift. Entries are deep-cloned to decouple from the // input config; consumers can mutate without leaking back to shell.json. diff --git a/shell/Ui/BarIndicator.qml b/shell/Ui/BarIndicator.qml index 57299280..81b45a29 100644 --- a/shell/Ui/BarIndicator.qml +++ b/shell/Ui/BarIndicator.qml @@ -18,15 +18,7 @@ WidgetButton { readonly property bool inactiveRevealed: !effectiveActive && !!indicatorHost && indicatorHost.revealInactiveIndicators function extractData(raw) { - var text = String(raw || "").trim() - if (text === "") return {} - - var lines = text.split("\n") - try { - return JSON.parse(lines[lines.length - 1]) - } catch (error) { - return { text: text } - } + return Util.parseModuleJson(raw) } function syncIndicatorOpacity() { diff --git a/shell/plugins/bar/Bar.qml b/shell/plugins/bar/Bar.qml index acb6adfd..0373bbe4 100644 --- a/shell/plugins/bar/Bar.qml +++ b/shell/plugins/bar/Bar.qml @@ -751,7 +751,7 @@ Item { } function update(raw) { - var data = root.parseModuleJson(raw) + var data = Util.parseModuleJson(raw) var klass = data.class || data.alt || "" outputText = data.text || String(raw || "").trim()