feat: Implement automatic regex interpretation for custom button collapse condition

This commit is contained in:
loner
2025-10-23 00:35:37 +08:00
parent beefae7350
commit 272bb50770
3 changed files with 29 additions and 5 deletions
+1 -1
View File
@@ -1339,7 +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')",
"enter-text-to-collapse": "Enter text or regex to collapse (e.g., 'nothing is playing' or '^nothing is playing')",
"search-wallpapers": "Type to filter wallpapers...",
"search-launcher": "Search entries... or use > for commands",
"search": "Search...",
+27 -3
View File
@@ -38,7 +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 string textCollapse: widgetSettings.textCollapse !== undefined ? widgetSettings.textCollapse : (widgetMetadata.textCollapse || "")
readonly property bool hasExec: (leftClickExec || rightClickExec || middleClickExec)
implicitWidth: pill.width
@@ -101,7 +101,19 @@ Item {
id: textStdoutSplit
onRead: function(line) {
var lineStr = String(line || "").trim()
if (textCollapse && textCollapse === lineStr) {
var shouldCollapse = false
if (textCollapse && textCollapse.length > 0) {
try {
var regex = new RegExp(textCollapse)
shouldCollapse = regex.test(lineStr)
} catch (e) {
// If it's not a valid regex, treat it as a plain string
shouldCollapse = (textCollapse === lineStr)
}
}
if (shouldCollapse) {
_dynamicText = ""
} else {
_dynamicText = lineStr
@@ -116,7 +128,19 @@ Item {
if (out.indexOf("\n") !== -1) {
out = out.split("\n")[0]
}
if (textCollapse && textCollapse === out) {
var shouldCollapse = false
if (textCollapse && textCollapse.length > 0) {
try {
var regex = new RegExp(textCollapse)
shouldCollapse = regex.test(out)
} catch (e) {
// If it's not a valid regex, treat it as a plain string
shouldCollapse = (textCollapse === out)
}
}
if (shouldCollapse) {
_dynamicText = ""
} else {
_dynamicText = out
@@ -116,7 +116,7 @@ ColumnLayout {
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")
placeholderText: I18n.tr("placeholders.enter-text-to-collapse")
text: widgetData?.textCollapse || widgetMetadata.textCollapse
}