mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Merge pull request #556 from lonerOrz/feature/custom-button-collapse
feat: Add custom button collapse condition
This commit is contained in:
@@ -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...",
|
||||
|
||||
@@ -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-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...",
|
||||
|
||||
@@ -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...",
|
||||
|
||||
@@ -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...",
|
||||
|
||||
@@ -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...",
|
||||
|
||||
@@ -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": "搜索...",
|
||||
|
||||
@@ -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 !== undefined ? widgetSettings.textCollapse : (widgetMetadata.textCollapse || "")
|
||||
readonly property bool hasExec: (leftClickExec || rightClickExec || middleClickExec)
|
||||
|
||||
implicitWidth: pill.width
|
||||
@@ -98,7 +99,33 @@ Item {
|
||||
|
||||
SplitParser {
|
||||
id: textStdoutSplit
|
||||
onRead: line => _dynamicText = String(line || "").trim()
|
||||
onRead: function(line) {
|
||||
var lineStr = String(line || "").trim()
|
||||
var shouldCollapse = false
|
||||
|
||||
if (textCollapse && textCollapse.length > 0) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldCollapse) {
|
||||
_dynamicText = ""
|
||||
} else {
|
||||
_dynamicText = lineStr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StdioCollector {
|
||||
@@ -108,7 +135,30 @@ Item {
|
||||
if (out.indexOf("\n") !== -1) {
|
||||
out = out.split("\n")[0]
|
||||
}
|
||||
_dynamicText = out
|
||||
var shouldCollapse = false
|
||||
|
||||
if (textCollapse && textCollapse.length > 0) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldCollapse) {
|
||||
_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-to-collapse")
|
||||
text: widgetData?.textCollapse || widgetMetadata.textCollapse
|
||||
}
|
||||
|
||||
NTextInput {
|
||||
id: textIntervalInput
|
||||
Layout.fillWidth: true
|
||||
|
||||
@@ -84,7 +84,8 @@ Singleton {
|
||||
"middleClickExec": "",
|
||||
"textCommand": "",
|
||||
"textStream": false,
|
||||
"textIntervalMs": 3000
|
||||
"textIntervalMs": 3000,
|
||||
"textCollapse": ""
|
||||
},
|
||||
"KeyboardLayout": {
|
||||
"allowUserSettings": true,
|
||||
|
||||
Reference in New Issue
Block a user