feat: Add custom button collapse condition

This commit is contained in:
loner
2025-10-23 00:01:31 +08:00
parent c832d7b2da
commit beefae7350
4 changed files with 32 additions and 3 deletions
+5
View File
@@ -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...",
+14 -2
View File
@@ -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
}
}
}
@@ -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
+2 -1
View File
@@ -84,7 +84,8 @@ Singleton {
"middleClickExec": "",
"textCommand": "",
"textStream": false,
"textIntervalMs": 3000
"textIntervalMs": 3000,
"textCollapse": ""
},
"KeyboardLayout": {
"allowUserSettings": true,