From beefae7350573ddd825394a109e2d153b571eb84 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Thu, 23 Oct 2025 00:01:31 +0800 Subject: [PATCH 1/8] feat: Add custom button collapse condition --- Assets/Translations/en.json | 5 +++++ Modules/Bar/Widgets/CustomButton.qml | 16 ++++++++++++++-- .../Bar/WidgetSettings/CustomButtonSettings.qml | 11 +++++++++++ Services/BarWidgetRegistry.qml | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) 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, From 272bb5077068603e51663aab5f84b99d545e7cf2 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Thu, 23 Oct 2025 00:35:37 +0800 Subject: [PATCH 2/8] feat: Implement automatic regex interpretation for custom button collapse condition --- Assets/Translations/en.json | 2 +- Modules/Bar/Widgets/CustomButton.qml | 30 +++++++++++++++++-- .../WidgetSettings/CustomButtonSettings.qml | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index 7ece8ee3..7e1778c7 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -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...", diff --git a/Modules/Bar/Widgets/CustomButton.qml b/Modules/Bar/Widgets/CustomButton.qml index 0f6f70e5..bea0a3b8 100644 --- a/Modules/Bar/Widgets/CustomButton.qml +++ b/Modules/Bar/Widgets/CustomButton.qml @@ -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 diff --git a/Modules/Settings/Bar/WidgetSettings/CustomButtonSettings.qml b/Modules/Settings/Bar/WidgetSettings/CustomButtonSettings.qml index ae0c242b..f87ba209 100644 --- a/Modules/Settings/Bar/WidgetSettings/CustomButtonSettings.qml +++ b/Modules/Settings/Bar/WidgetSettings/CustomButtonSettings.qml @@ -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 } From 1d5eb91803ca3919f0970e1dc5d7c317d3664c8d Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Thu, 23 Oct 2025 00:42:50 +0800 Subject: [PATCH 3/8] feat: Revert regex interpretation to require // delimiters and update en.json placeholder --- Assets/Translations/en.json | 2 +- Modules/Bar/Widgets/CustomButton.qml | 34 ++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index 7e1778c7..f34f59b3 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -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-to-collapse": "Enter text or regex to collapse (e.g., 'nothing is playing' or '^nothing is playing')", + "enter-text-to-collapse": "e.g., 'nothing is playing'. Use /regex/ for patterns.", "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 bea0a3b8..dd1c6cc1 100644 --- a/Modules/Bar/Widgets/CustomButton.qml +++ b/Modules/Bar/Widgets/CustomButton.qml @@ -104,11 +104,18 @@ Item { 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 + if (textCollapse.startsWith("/") && textCollapse.endsWith("/") && textCollapse.length > 1) { + // Treat as regex + var pattern = textCollapse.substring(1, textCollapse.length - 1) + try { + var regex = new RegExp(pattern) + shouldCollapse = regex.test(lineStr) + } catch (e) { + Logger.w("CustomButton", `Invalid regex for textCollapse: ${textCollapse} - ${e.message}`) + shouldCollapse = (textCollapse === lineStr) // Fallback to exact match on invalid regex + } + } else { + // Treat as plain string shouldCollapse = (textCollapse === lineStr) } } @@ -131,11 +138,18 @@ Item { 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 + if (textCollapse.startsWith("/") && textCollapse.endsWith("/") && textCollapse.length > 1) { + // Treat as regex + var pattern = textCollapse.substring(1, textCollapse.length - 1) + try { + var regex = new RegExp(pattern) + shouldCollapse = regex.test(out) + } catch (e) { + Logger.w("CustomButton", `Invalid regex for textCollapse: ${textCollapse} - ${e.message}`) + shouldCollapse = (textCollapse === out) // Fallback to exact match on invalid regex + } + } else { + // Treat as plain string shouldCollapse = (textCollapse === out) } } From f4b38741122e0797000ea2cc3f681a2417f1f1ad Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Thu, 23 Oct 2025 00:55:48 +0800 Subject: [PATCH 4/8] feat: Update de.json for collapse condition --- Assets/Translations/de.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Assets/Translations/de.json b/Assets/Translations/de.json index 5579f765..e869f6f9 100644 --- a/Assets/Translations/de.json +++ b/Assets/Translations/de.json @@ -1106,8 +1106,12 @@ "description": "Intervall in Millisekunden." }, "text-stream": { - "description": "Gestreamte Zeilen aus dem Befehl werden als Text auf der Schaltfläche angezeigt.", - "label": "Strom" + "label": "Strom", + "description": "Gestreamte Zeilen aus dem Befehl werden als Text auf der Schaltfläche angezeigt." + }, + "collapse-condition": { + "label": "Collapse condition", + "description": "If the output text matches this value, the button will collapse." } }, "media-mini": { @@ -1352,6 +1356,7 @@ "enter-width-pixels": "Breite in Pixeln eingeben", "enter-command": "Befehl eingeben (App oder benutzerdefiniertes Skript)", "command-example": "echo \"Hallo Welt\"", + "enter-text-to-collapse": "z.B. 'nothing is playing'. Verwenden Sie /regex/ für Muster.", "search-wallpapers": "Zum Filtern von Hintergrundbildern eingeben...", "search-launcher": "Einträge suchen... oder > für Befehle verwenden", "search": "Suchen...", From 471a42aa35459a540d6624fdd3c04ddec8063a83 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Thu, 23 Oct 2025 01:03:07 +0800 Subject: [PATCH 5/8] feat: Update es.json for collapse condition --- Assets/Translations/es.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Assets/Translations/es.json b/Assets/Translations/es.json index aaae9d49..29c055ec 100644 --- a/Assets/Translations/es.json +++ b/Assets/Translations/es.json @@ -1089,8 +1089,12 @@ "description": "Intervalo en milisegundos." }, "text-stream": { - "description": "Las líneas transmitidas desde el comando se mostrarán como texto en el botón.", - "label": "Transmisión" + "label": "Transmisión", + "description": "Las líneas transmitidas desde el comando se mostrarán como texto en el botón." + }, + "collapse-condition": { + "label": "Condición de colapso", + "description": "Si el texto de salida coincide con este valor, el botón se colapsará." } }, "media-mini": { @@ -1335,6 +1339,7 @@ "enter-width-pixels": "Ingresa el ancho en píxeles", "enter-command": "Ingresa el comando a ejecutar (aplicación o script personalizado)", "command-example": "echo \"Hola Mundo\"", + "enter-text-to-collapse": "por ejemplo, 'no se está reproduciendo nada'. Usa /regex/ para patrones.", "search-wallpapers": "Escribe para filtrar fondos de pantalla...", "search-launcher": "Buscar entradas... o usa > para comandos", "search": "Buscar...", From 7a6419c3b3734d3b08f3bdabb188990cca051c94 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Thu, 23 Oct 2025 01:08:16 +0800 Subject: [PATCH 6/8] feat: Update fr.json for collapse condition --- Assets/Translations/fr.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Assets/Translations/fr.json b/Assets/Translations/fr.json index f2304dcb..d367abd5 100644 --- a/Assets/Translations/fr.json +++ b/Assets/Translations/fr.json @@ -1089,8 +1089,12 @@ "description": "Intervalle en millisecondes." }, "text-stream": { - "description": "Les lignes diffusées depuis la commande seront affichées sous forme de texte sur le bouton.", - "label": "Flux" + "label": "Flux", + "description": "Les lignes diffusées depuis la commande seront affichées sous forme de texte sur le bouton." + }, + "collapse-condition": { + "label": "Condition d’effondrement", + "description": "Si le texte de sortie correspond à cette valeur, le bouton se repliera." } }, "media-mini": { @@ -1335,6 +1339,7 @@ "enter-width-pixels": "Entrez la largeur en pixels", "enter-command": "Entrez la commande à exécuter (application ou script personnalisé)", "command-example": "echo \"Bonjour le monde\"", + "enter-text-to-collapse": "par ex., 'rien n’est en lecture'. Utilisez /regex/ pour les modèles.", "search-wallpapers": "Tapez pour filtrer les fonds d'écran...", "search-launcher": "Rechercher des entrées... ou utilisez > pour les commandes", "search": "Rechercher...", From 6a7bccfcb21ce0cdb9cfcf45e4c4add23323e141 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Thu, 23 Oct 2025 01:23:19 +0800 Subject: [PATCH 7/8] feat: Update pt.json for collapse condition --- Assets/Translations/pt.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Assets/Translations/pt.json b/Assets/Translations/pt.json index 8dfe9ab7..addddd36 100644 --- a/Assets/Translations/pt.json +++ b/Assets/Translations/pt.json @@ -1089,8 +1089,12 @@ "description": "Intervalo em milissegundos." }, "text-stream": { - "description": "As linhas transmitidas do comando serão exibidas como texto no botão.", - "label": "Transmissão" + "label": "Transmissão", + "description": "As linhas transmitidas do comando serão exibidas como texto no botão." + }, + "collapse-condition": { + "label": "Condição de recolhimento", + "description": "Se o texto de saída corresponder a este valor, o botão será recolhido." } }, "media-mini": { @@ -1335,6 +1339,7 @@ "enter-width-pixels": "Digite a largura em pixels", "enter-command": "Digite o comando para executar (app ou script personalizado)", "command-example": "echo \"Olá Mundo\"", + "enter-text-to-collapse": "por exemplo, 'nada está sendo reproduzido'. Use /regex/ para padrões.", "search-wallpapers": "Digite para filtrar papéis de parede...", "search-launcher": "Pesquisar entradas... ou use > para comandos", "search": "Pesquisar...", From c063f8dafbcc93b91985d6fc5e271ad5d624945a Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Thu, 23 Oct 2025 01:27:04 +0800 Subject: [PATCH 8/8] feat: Update zh-CN.json for collapse condition --- Assets/Translations/zh-CN.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Assets/Translations/zh-CN.json b/Assets/Translations/zh-CN.json index a7d6556d..35c52c51 100644 --- a/Assets/Translations/zh-CN.json +++ b/Assets/Translations/zh-CN.json @@ -1089,8 +1089,12 @@ "description": "间隔时间(毫秒)。" }, "text-stream": { - "description": "来自命令的流式输出行将作为文本显示在按钮上。", "label": "流" + "description": "来自命令的流式输出行将作为文本显示在按钮上。", + }, + "collapse-condition": { + "label": "折叠条件", + "description": "如果输出文本与此值匹配,按钮的文本将会折叠不去显示。" } }, "media-mini": { @@ -1335,6 +1339,7 @@ "enter-width-pixels": "输入宽度(像素)", "enter-command": "输入要执行的命令(应用程序或自定义脚本)", "command-example": "echo \"Hello World\"", + "enter-text-to-collapse": "例如,“nothing is playing”。使用 /regex/ 表示匹配模式。", "search-wallpapers": "输入以筛选壁纸...", "search-launcher": "搜索条目...或使用 > 执行命令", "search": "搜索...",