Merge pull request #680 from kurrycat2004/main

feat(custom button): Add option to refresh CustomButton text on click
This commit is contained in:
Lemmy
2025-11-12 12:05:16 -05:00
committed by GitHub
5 changed files with 93 additions and 25 deletions
+6 -3
View File
@@ -133,11 +133,13 @@
},
"left-click": {
"description": "Command to execute when the button is left-clicked.",
"label": "Left click"
"label": "Left click",
"update-text": "Update displayed text on left-click"
},
"middle-click": {
"description": "Command to execute when the button is middle-clicked.",
"label": "Middle click"
"label": "Middle click",
"update-text": "Update displayed text on middle-click"
},
"parse-json": {
"description": "Parse the command output as a JSON object to dynamically set text and icon.",
@@ -149,7 +151,8 @@
},
"right-click": {
"description": "Command to execute when the button is right-clicked.",
"label": "Right click"
"label": "Right click",
"update-text": "Update displayed text on right-click"
},
"text-stream": {
"description": "Streamed lines from the command will be displayed as text on the button.",
+13 -1
View File
@@ -34,8 +34,11 @@ Item {
readonly property string customIcon: widgetSettings.icon || widgetMetadata.icon
readonly property string leftClickExec: widgetSettings.leftClickExec || widgetMetadata.leftClickExec
readonly property bool leftClickUpdateText: widgetSettings.leftClickUpdateText ?? widgetMetadata.leftClickUpdateText
readonly property string rightClickExec: widgetSettings.rightClickExec || widgetMetadata.rightClickExec
readonly property bool rightClickUpdateText: widgetSettings.rightClickUpdateText ?? widgetMetadata.rightClickUpdateText
readonly property string middleClickExec: widgetSettings.middleClickExec || widgetMetadata.middleClickExec
readonly property bool middleClickUpdateText: widgetSettings.middleClickUpdateText ?? widgetMetadata.middleClickUpdateText
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)
@@ -210,12 +213,15 @@ Item {
if (leftClickExec) {
Quickshell.execDetached(["sh", "-c", leftClickExec])
Logger.i("CustomButton", `Executing command: ${leftClickExec}`)
} else if (!hasExec) {
} else if (!hasExec && !leftClickUpdateText) {
// No script was defined, open settings
var settingsPanel = PanelService.getPanel("settingsPanel", screen)
settingsPanel.requestedTab = SettingsPanel.Tab.Bar
settingsPanel.open()
}
if (!textStream && leftClickUpdateText) {
runTextCommand()
}
}
function onRightClicked() {
@@ -223,6 +229,9 @@ Item {
Quickshell.execDetached(["sh", "-c", rightClickExec])
Logger.i("CustomButton", `Executing command: ${rightClickExec}`)
}
if (!textStream && rightClickUpdateText) {
runTextCommand()
}
}
function onMiddleClicked() {
@@ -230,6 +239,9 @@ Item {
Quickshell.execDetached(["sh", "-c", middleClickExec])
Logger.i("CustomButton", `Executing command: ${middleClickExec}`)
}
if (!textStream && middleClickUpdateText) {
runTextCommand()
}
}
function runTextCommand() {
@@ -3,6 +3,7 @@ import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window
import qs.Commons
import qs.Services.UI
import qs.Widgets
ColumnLayout {
@@ -21,8 +22,11 @@ ColumnLayout {
var settings = Object.assign({}, widgetData || {})
settings.icon = valueIcon
settings.leftClickExec = leftClickExecInput.text
settings.leftClickUpdateText = leftClickUpdateText.checked
settings.rightClickExec = rightClickExecInput.text
settings.rightClickUpdateText = rightClickUpdateText.checked
settings.middleClickExec = middleClickExecInput.text
settings.middleClickUpdateText = middleClickUpdateText.checked
settings.textCommand = textCommandInput.text
settings.textCollapse = textCollapseInput.text
settings.textStream = valueTextStream
@@ -61,31 +65,76 @@ ColumnLayout {
}
}
NTextInput {
id: leftClickExecInput
Layout.fillWidth: true
label: I18n.tr("bar.widget-settings.custom-button.left-click.label")
description: I18n.tr("bar.widget-settings.custom-button.left-click.description")
placeholderText: I18n.tr("placeholders.enter-command")
text: widgetData?.leftClickExec || widgetMetadata.leftClickExec
RowLayout {
spacing: Style.marginM
NTextInput {
id: leftClickExecInput
Layout.fillWidth: true
label: I18n.tr("bar.widget-settings.custom-button.left-click.label")
description: I18n.tr("bar.widget-settings.custom-button.left-click.description")
placeholderText: I18n.tr("placeholders.enter-command")
text: widgetData?.leftClickExec || widgetMetadata.leftClickExec
}
NToggle {
id: leftClickUpdateText
enabled: !valueTextStream
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
Layout.bottomMargin: Style.marginS
onEntered: TooltipService.show(Screen, leftClickUpdateText, I18n.tr("bar.widget-settings.custom-button.left-click.update-text"), "auto")
onExited: TooltipService.hide()
checked: widgetData?.leftClickUpdateText ?? widgetMetadata.leftClickUpdateText
onToggled: isChecked => checked = isChecked
}
}
NTextInput {
id: rightClickExecInput
Layout.fillWidth: true
label: I18n.tr("bar.widget-settings.custom-button.right-click.label")
description: I18n.tr("bar.widget-settings.custom-button.right-click.description")
placeholderText: I18n.tr("placeholders.enter-command")
text: widgetData?.rightClickExec || widgetMetadata.rightClickExec
RowLayout {
spacing: Style.marginM
NTextInput {
id: rightClickExecInput
Layout.fillWidth: true
label: I18n.tr("bar.widget-settings.custom-button.right-click.label")
description: I18n.tr("bar.widget-settings.custom-button.right-click.description")
placeholderText: I18n.tr("placeholders.enter-command")
text: widgetData?.rightClickExec || widgetMetadata.rightClickExec
}
NToggle {
id: rightClickUpdateText
enabled: !valueTextStream
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
Layout.bottomMargin: Style.marginS
onEntered: TooltipService.show(Screen, rightClickUpdateText, I18n.tr("bar.widget-settings.custom-button.right-click.update-text"), "auto")
onExited: TooltipService.hide()
checked: widgetData?.rightClickUpdateText ?? widgetMetadata.rightClickUpdateText
onToggled: isChecked => checked = isChecked
}
}
NTextInput {
id: middleClickExecInput
Layout.fillWidth: true
label: I18n.tr("bar.widget-settings.custom-button.middle-click.label")
description: I18n.tr("bar.widget-settings.custom-button.middle-click.description")
placeholderText: I18n.tr("placeholders.enter-command")
text: widgetData.middleClickExec || widgetMetadata.middleClickExec
RowLayout {
spacing: Style.marginM
NTextInput {
id: middleClickExecInput
Layout.fillWidth: true
label: I18n.tr("bar.widget-settings.custom-button.middle-click.label")
description: I18n.tr("bar.widget-settings.custom-button.middle-click.description")
placeholderText: I18n.tr("placeholders.enter-command")
text: widgetData.middleClickExec || widgetMetadata.middleClickExec
}
NToggle {
id: middleClickUpdateText
enabled: !valueTextStream
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
Layout.bottomMargin: Style.marginS
onEntered: TooltipService.show(Screen, middleClickUpdateText, I18n.tr("bar.widget-settings.custom-button.middle-click.update-text"), "auto")
onExited: TooltipService.hide()
checked: widgetData?.middleClickUpdateText ?? widgetMetadata.middleClickUpdateText
onToggled: isChecked => checked = isChecked
}
}
NDivider {
+3
View File
@@ -93,8 +93,11 @@ Singleton {
"allowUserSettings": true,
"icon": "heart",
"leftClickExec": "",
"leftClickUpdateText": false,
"rightClickExec": "",
"rightClickUpdateText": false,
"middleClickExec": "",
"middleClickUpdateText": false,
"textCommand": "",
"textStream": false,
"textIntervalMs": 3000,
+1
View File
@@ -25,6 +25,7 @@ RowLayout {
NLabel {
label: root.label
description: root.description
visible: root.label !== "" || root.description !== ""
}
Rectangle {