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
@@ -125,8 +125,12 @@ Singleton {
|
|||||||
if (!p || !isEnabled(id))
|
if (!p || !isEnabled(id))
|
||||||
return false;
|
return false;
|
||||||
const moduleId = "plugin:" + id;
|
const moduleId = "plugin:" + id;
|
||||||
if (ConfigService.data.bar.modules.some(m => m.id === moduleId))
|
const existing = ConfigService.data.bar.modules.find(m => m.id === moduleId);
|
||||||
return false;
|
// A switched-off entry may hold options set on the Plugins page: turn it on.
|
||||||
|
if (existing)
|
||||||
|
return existing.enabled === false
|
||||||
|
? ConfigService.setValue("bar.modules", ConfigService.data.bar.modules.map(m => m.id === moduleId ? Object.assign({}, m, {enabled: true}) : m))
|
||||||
|
: false;
|
||||||
const section = (p.manifest.barWidget || {}).defaultSection;
|
const section = (p.manifest.barWidget || {}).defaultSection;
|
||||||
return ConfigService.setValue("bar.modules", ConfigService.data.bar.modules.concat([
|
return ConfigService.setValue("bar.modules", ConfigService.data.bar.modules.concat([
|
||||||
{
|
{
|
||||||
@@ -452,6 +456,12 @@ Singleton {
|
|||||||
function toggle(id: string, payload: string): bool {
|
function toggle(id: string, payload: string): bool {
|
||||||
return root.toggle(id, payload);
|
return root.toggle(id, payload);
|
||||||
}
|
}
|
||||||
|
// Settings → Plugins with this plugin's settings open.
|
||||||
|
function settings(id: string): void {
|
||||||
|
root.focusedSettings = "";
|
||||||
|
root.focusedSettings = id;
|
||||||
|
ShellState.openSettings("plugins");
|
||||||
|
}
|
||||||
// Marketplace search, as in the Browse tab.
|
// Marketplace search, as in the Browse tab.
|
||||||
function browse(query: string): void {
|
function browse(query: string): void {
|
||||||
root.marketQuery = query;
|
root.marketQuery = query;
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,23 @@ SettingsPage {
|
|||||||
onTabChanged: if (tab === "browse" && PluginService.market.items.length === 0)
|
onTabChanged: if (tab === "browse" && PluginService.market.items.length === 0)
|
||||||
PluginService.browse(false)
|
PluginService.browse(false)
|
||||||
Component.onCompleted: PluginService.refresh()
|
Component.onCompleted: PluginService.refresh()
|
||||||
|
// Scroll a plugin row to the top once the page has laid out.
|
||||||
|
function reveal(item) {
|
||||||
|
revealTimer.item = item;
|
||||||
|
revealTimer.restart();
|
||||||
|
}
|
||||||
|
Timer {
|
||||||
|
id: revealTimer
|
||||||
|
property Item item: null
|
||||||
|
interval: 120
|
||||||
|
onTriggered: {
|
||||||
|
const flick = root.contentItem;
|
||||||
|
if (!item || !flick || flick.contentY === undefined)
|
||||||
|
return;
|
||||||
|
const y = item.mapToItem(flick.contentItem, 0, 0).y;
|
||||||
|
flick.contentY = Math.max(0, Math.min(y - 12, flick.contentHeight - flick.height));
|
||||||
|
}
|
||||||
|
}
|
||||||
readonly property var capabilityLabels: ({
|
readonly property var capabilityLabels: ({
|
||||||
"privilege": "Uses sudo",
|
"privilege": "Uses sudo",
|
||||||
"package-manager": "Installs packages",
|
"package-manager": "Installs packages",
|
||||||
@@ -111,7 +128,7 @@ SettingsPage {
|
|||||||
SettingsSection {
|
SettingsSection {
|
||||||
visible: root.tab === "installed"
|
visible: root.tab === "installed"
|
||||||
title: "Installed"
|
title: "Installed"
|
||||||
description: PluginService.plugins.length ? "Turn a plugin on to load it. Bar widgets then appear under Bar → Modules (and can go on a single screen); their options are on the module's cog." : ""
|
description: PluginService.plugins.length ? "Turn a plugin on to load it. Bar widgets then appear under Bar → Modules (and can go on a single screen); their options are under Settings here and on the module's cog." : ""
|
||||||
Text {
|
Text {
|
||||||
visible: PluginService.loaded && PluginService.plugins.length === 0
|
visible: PluginService.loaded && PluginService.plugins.length === 0
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
@@ -127,7 +144,9 @@ SettingsPage {
|
|||||||
required property var modelData
|
required property var modelData
|
||||||
readonly property var manifest: modelData.manifest || {}
|
readonly property var manifest: modelData.manifest || {}
|
||||||
readonly property bool enabledNow: PluginService.isEnabled(modelData.id)
|
readonly property bool enabledNow: PluginService.isEnabled(modelData.id)
|
||||||
readonly property bool inBar: ConfigService.data.bar.modules.some(m => m.id === "plugin:" + modelData.id)
|
readonly property bool inBar: ConfigService.data.bar.modules.some(m => m.id === "plugin:" + modelData.id && m.enabled !== false)
|
||||||
|
// Omarchy plugins: a form from their manifest schema (Noctalia ones bring Settings.qml).
|
||||||
|
readonly property bool schemaSettings: modelData.ecosystem !== "noctalia" && PluginService.schema(modelData.id).length > 0
|
||||||
objectName: "plugin-" + modelData.id
|
objectName: "plugin-" + modelData.id
|
||||||
title: manifest.name || modelData.id
|
title: manifest.name || modelData.id
|
||||||
description: [manifest.description || "", [manifest.version ? "v" + manifest.version : "", manifest.author || ""].filter(x => x).join(" · ")].filter(x => x).join("\n")
|
description: [manifest.description || "", [manifest.version ? "v" + manifest.version : "", manifest.author || ""].filter(x => x).join(" · ")].filter(x => x).join("\n")
|
||||||
@@ -140,7 +159,7 @@ SettingsPage {
|
|||||||
}
|
}
|
||||||
GlassButton {
|
GlassButton {
|
||||||
objectName: "plugin-settings-" + row.modelData.id
|
objectName: "plugin-settings-" + row.modelData.id
|
||||||
visible: row.enabledNow && (row.modelData.kinds || []).includes("settings")
|
visible: row.enabledNow && ((row.modelData.kinds || []).includes("settings") || row.schemaSettings)
|
||||||
text: root.openSettings === row.modelData.id ? "Close settings" : "Settings"
|
text: root.openSettings === row.modelData.id ? "Close settings" : "Settings"
|
||||||
accented: root.openSettings === row.modelData.id
|
accented: root.openSettings === row.modelData.id
|
||||||
onClicked: root.openSettings = root.openSettings === row.modelData.id ? "" : row.modelData.id
|
onClicked: root.openSettings = root.openSettings === row.modelData.id ? "" : row.modelData.id
|
||||||
@@ -233,11 +252,17 @@ SettingsPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The plugin's own settings screen (Noctalia Settings.qml), with
|
// The plugin's own settings screen (Noctalia Settings.qml), with
|
||||||
// its pluginApi; Save calls the plugin's saveSettings().
|
// its pluginApi; Save calls the plugin's saveSettings(). Omarchy
|
||||||
|
// plugins get a form from their schema that applies as you edit.
|
||||||
Rectangle {
|
Rectangle {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
visible: root.openSettings === row.modelData.id
|
visible: root.openSettings === row.modelData.id
|
||||||
implicitHeight: visible ? settingsColumn.implicitHeight + 24 : 0
|
implicitHeight: visible ? settingsColumn.implicitHeight + 24 : 0
|
||||||
|
// Bring the plugin and its settings into view once laid out.
|
||||||
|
onVisibleChanged: if (visible)
|
||||||
|
root.reveal(row)
|
||||||
|
Component.onCompleted: if (visible)
|
||||||
|
root.reveal(row)
|
||||||
radius: 12
|
radius: 12
|
||||||
color: Theme.fill
|
color: Theme.fill
|
||||||
border.width: 1
|
border.width: 1
|
||||||
@@ -249,10 +274,15 @@ SettingsPage {
|
|||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.margins: 12
|
anchors.margins: 12
|
||||||
spacing: 10
|
spacing: 10
|
||||||
|
PluginOptions {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
visible: row.schemaSettings
|
||||||
|
pluginId: row.modelData.id
|
||||||
|
}
|
||||||
Loader {
|
Loader {
|
||||||
id: pluginSettings
|
id: pluginSettings
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
active: root.openSettings === row.modelData.id
|
active: !row.schemaSettings && root.openSettings === row.modelData.id
|
||||||
onActiveChanged: if (active)
|
onActiveChanged: if (active)
|
||||||
setSource(row.modelData.entryUrls.settings, {
|
setSource(row.modelData.entryUrls.settings, {
|
||||||
pluginApi: PluginService.noctaliaApi(row.modelData.id)
|
pluginApi: PluginService.noctaliaApi(row.modelData.id)
|
||||||
@@ -264,10 +294,18 @@ SettingsPage {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
}
|
}
|
||||||
GlassButton {
|
GlassButton {
|
||||||
|
visible: row.schemaSettings
|
||||||
|
text: "Done"
|
||||||
|
accented: true
|
||||||
|
onClicked: root.openSettings = ""
|
||||||
|
}
|
||||||
|
GlassButton {
|
||||||
|
visible: !row.schemaSettings
|
||||||
text: "Cancel"
|
text: "Cancel"
|
||||||
onClicked: root.openSettings = ""
|
onClicked: root.openSettings = ""
|
||||||
}
|
}
|
||||||
GlassButton {
|
GlassButton {
|
||||||
|
visible: !row.schemaSettings
|
||||||
objectName: "plugin-settings-save-" + row.modelData.id
|
objectName: "plugin-settings-save-" + row.modelData.id
|
||||||
text: "Save"
|
text: "Save"
|
||||||
accented: true
|
accented: true
|
||||||
|
|||||||
Reference in new issue
Block a user