Show Omarchy plugin settings on the Plugins page
Omarchy plugins with a manifest schema get a Settings button like Noctalia ones: a full form (label, description, control) that edits the same bar.modules options as the bar cog and applies as you go. A plugin not in the bar keeps its options on a switched-off entry, which Add to bar turns on. `plugins settings <id>` over IPC opens it, scrolled into view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
660fa69be6
commit
3f0e31b116
3 files changed
+198
-7
No files matched your search
@@ -0,0 +1,143 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import "../../components"
|
||||
import "../../services"
|
||||
import "../../theme"
|
||||
|
||||
// Settings form for an Omarchy plugin, built from its manifest schema
|
||||
// (boolean / integer / number / string / choices). Values are the widget's
|
||||
// options on its bar.modules entry, the same ones the bar cog edits, so the
|
||||
// bar and the notch both use them. Changes apply as they are made.
|
||||
ColumnLayout {
|
||||
id: root
|
||||
required property string pluginId
|
||||
readonly property string moduleId: "plugin:" + pluginId
|
||||
readonly property var entry: ConfigService.ready ? (ConfigService.data.bar.modules.find(m => m.id === moduleId) || null) : null
|
||||
readonly property var values: PluginService.widgetSettings(pluginId, entry ? entry.options : {})
|
||||
readonly property var fields: PluginService.schema(pluginId).filter(f => f && f.key).map(f => {
|
||||
const choices = Array.isArray(f.choices) ? f.choices : Array.isArray(f.options) ? f.options.map(o => typeof o === "object" ? o.value : o) : null;
|
||||
return Object.assign({}, f, {
|
||||
label: f.label || f.key,
|
||||
type: choices ? "choice" : (f.type || "string"),
|
||||
choices: choices || []
|
||||
});
|
||||
})
|
||||
spacing: 14
|
||||
|
||||
function set(key, value) {
|
||||
const modules = ConfigService.data.bar.modules;
|
||||
if (modules.some(m => m.id === moduleId))
|
||||
return ConfigService.setValue("bar.modules", modules.map(m => m.id === moduleId ? Object.assign({}, m, {
|
||||
options: Object.assign({}, m.options || {}, {[key]: value})
|
||||
}) : m));
|
||||
// Not in the bar: keep the options on a switched-off entry (the notch reads it too).
|
||||
const section = ((PluginService.plugin(pluginId) || {}).manifest || {}).barWidget || {};
|
||||
return ConfigService.setValue("bar.modules", modules.concat([
|
||||
{
|
||||
id: moduleId,
|
||||
position: ["left", "center", "right"].includes(section.defaultSection) ? section.defaultSection : "right",
|
||||
enabled: false,
|
||||
options: {[key]: value}
|
||||
}
|
||||
]));
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: root.fields
|
||||
RowLayout {
|
||||
id: field
|
||||
required property var modelData
|
||||
required property int index
|
||||
readonly property var value: root.values[modelData.key]
|
||||
readonly property bool numeric: modelData.type === "integer" || modelData.type === "number"
|
||||
Layout.fillWidth: true
|
||||
spacing: 16
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 3
|
||||
Text {
|
||||
Layout.fillWidth: true
|
||||
text: field.modelData.label
|
||||
color: Theme.text
|
||||
font.pixelSize: 13
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
Text {
|
||||
Layout.fillWidth: true
|
||||
visible: !!field.modelData.description
|
||||
text: field.modelData.description || ""
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 11
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
}
|
||||
// Every control sits in the same right-hand column.
|
||||
Item {
|
||||
Layout.preferredWidth: 300
|
||||
Layout.preferredHeight: 34
|
||||
GlassComboBox {
|
||||
objectName: "plugin-option-" + root.pluginId + "-" + field.modelData.key
|
||||
visible: field.modelData.type === "choice"
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 190
|
||||
height: 32
|
||||
model: (field.modelData.choices || []).map((c, i) => ({
|
||||
text: field.modelData.choiceLabels ? field.modelData.choiceLabels[i] : String(c).charAt(0).toUpperCase() + String(c).slice(1),
|
||||
value: c
|
||||
}))
|
||||
textRole: "text"
|
||||
valueRole: "value"
|
||||
currentIndex: (field.modelData.choices || []).indexOf(field.value)
|
||||
onActivated: root.set(field.modelData.key, currentValue)
|
||||
}
|
||||
GlassToggle {
|
||||
objectName: "plugin-option-" + root.pluginId + "-" + field.modelData.key
|
||||
visible: field.modelData.type === "boolean"
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
checked: field.value === true
|
||||
onToggled: root.set(field.modelData.key, checked)
|
||||
}
|
||||
Text {
|
||||
visible: field.numeric
|
||||
anchors.right: slider.left
|
||||
anchors.rightMargin: 12
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: field.value === undefined ? "" : String(field.value) + (field.modelData.unit ? " " + field.modelData.unit : "")
|
||||
color: Theme.text
|
||||
font.pixelSize: 12
|
||||
}
|
||||
GlassSlider {
|
||||
id: slider
|
||||
objectName: "plugin-option-" + root.pluginId + "-" + field.modelData.key
|
||||
visible: field.numeric
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 220
|
||||
height: 26
|
||||
from: Number(field.modelData.min !== undefined ? field.modelData.min : 0)
|
||||
to: Number(field.modelData.max !== undefined ? field.modelData.max : 100)
|
||||
stepSize: Number(field.modelData.step || (field.modelData.type === "integer" ? 1 : 0.1))
|
||||
value: Number(field.value || 0)
|
||||
onMoved: root.set(field.modelData.key, field.modelData.type === "integer" ? Math.round(value) : value)
|
||||
}
|
||||
GlassTextField {
|
||||
objectName: "plugin-option-" + root.pluginId + "-" + field.modelData.key
|
||||
visible: field.modelData.type === "string"
|
||||
anchors.fill: parent
|
||||
topPadding: 0
|
||||
bottomPadding: 0
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
font.pixelSize: 13
|
||||
text: field.value === undefined ? "" : String(field.value)
|
||||
placeholderText: field.modelData.placeholder || ""
|
||||
onEditingFinished: if (text !== String(field.value === undefined ? "" : field.value))
|
||||
root.set(field.modelData.key, text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user