diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index 79d95ab4..7ece8ee3 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -1091,6 +1091,10 @@ "refresh-interval": { "label": "Refresh interval", "description": "Interval in milliseconds." + }, + "collapse-condition": { + "label": "Collapse condition", + "description": "If the output text matches this value, the button will collapse." } }, "media-mini": { @@ -1335,6 +1339,7 @@ "enter-width-pixels": "Enter width in pixels", "enter-command": "Enter command to execute (app or custom script)", "command-example": "echo \"Hello World\"", + "enter-text": "Enter text to collapse (e.g., 'nothing is playing')", "search-wallpapers": "Type to filter wallpapers...", "search-launcher": "Search entries... or use > for commands", "search": "Search...", diff --git a/Modules/Bar/Widgets/CustomButton.qml b/Modules/Bar/Widgets/CustomButton.qml index b9973957..0f6f70e5 100644 --- a/Modules/Bar/Widgets/CustomButton.qml +++ b/Modules/Bar/Widgets/CustomButton.qml @@ -38,6 +38,7 @@ Item { readonly property string textCommand: widgetSettings.textCommand !== undefined ? widgetSettings.textCommand : (widgetMetadata.textCommand || "") readonly property bool textStream: widgetSettings.textStream !== undefined ? widgetSettings.textStream : (widgetMetadata.textStream || false) readonly property int textIntervalMs: widgetSettings.textIntervalMs !== undefined ? widgetSettings.textIntervalMs : (widgetMetadata.textIntervalMs || 3000) + readonly property string textCollapse: widgetSettings.textCollapse || widgetMetadata.textCollapse || "" readonly property bool hasExec: (leftClickExec || rightClickExec || middleClickExec) implicitWidth: pill.width @@ -98,7 +99,14 @@ Item { SplitParser { id: textStdoutSplit - onRead: line => _dynamicText = String(line || "").trim() + onRead: function(line) { + var lineStr = String(line || "").trim() + if (textCollapse && textCollapse === lineStr) { + _dynamicText = "" + } else { + _dynamicText = lineStr + } + } } StdioCollector { @@ -108,7 +116,11 @@ Item { if (out.indexOf("\n") !== -1) { out = out.split("\n")[0] } - _dynamicText = out + if (textCollapse && textCollapse === out) { + _dynamicText = "" + } else { + _dynamicText = out + } } } diff --git a/Modules/Settings/Bar/WidgetSettings/CustomButtonSettings.qml b/Modules/Settings/Bar/WidgetSettings/CustomButtonSettings.qml index 1520561e..ae0c242b 100644 --- a/Modules/Settings/Bar/WidgetSettings/CustomButtonSettings.qml +++ b/Modules/Settings/Bar/WidgetSettings/CustomButtonSettings.qml @@ -23,6 +23,7 @@ ColumnLayout { settings.rightClickExec = rightClickExecInput.text settings.middleClickExec = middleClickExecInput.text settings.textCommand = textCommandInput.text + settings.textCollapse = textCollapseInput.text settings.textStream = valueTextStream settings.textIntervalMs = parseInt(textIntervalInput.text || textIntervalInput.placeholderText, 10) return settings @@ -109,6 +110,16 @@ ColumnLayout { text: widgetData?.textCommand || widgetMetadata.textCommand } + NTextInput { + id: textCollapseInput + Layout.fillWidth: true + visible: valueTextStream + label: I18n.tr("bar.widget-settings.custom-button.collapse-condition.label") + description: I18n.tr("bar.widget-settings.custom-button.collapse-condition.description") + placeholderText: I18n.tr("placeholders.enter-text") + text: widgetData?.textCollapse || widgetMetadata.textCollapse + } + NTextInput { id: textIntervalInput Layout.fillWidth: true diff --git a/Services/BarWidgetRegistry.qml b/Services/BarWidgetRegistry.qml index 00eef68e..821db640 100644 --- a/Services/BarWidgetRegistry.qml +++ b/Services/BarWidgetRegistry.qml @@ -84,7 +84,8 @@ Singleton { "middleClickExec": "", "textCommand": "", "textStream": false, - "textIntervalMs": 3000 + "textIntervalMs": 3000, + "textCollapse": "" }, "KeyboardLayout": { "allowUserSettings": true,