Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bin/omarchy-plugin-disable
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ id="${1:-}"
[[ -n $id ]] || fail "plugin id is required"

result=$(omarchy-shell shell setPluginEnabled "$id" false)
[[ $result == "ok" ]] ||
if [[ $result == "unknown" ]]; then
fail "plugin '$id' is not known; run: omarchy-shell shell rescanPlugins"
elif [[ $result != "ok" ]]; then
fail "$result"
fi

echo "Disabled $id"
3 changes: 2 additions & 1 deletion bin/omarchy-plugin-remove
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ else
fi

if [[ $was_enabled == "true" ]]; then
omarchy-shell shell setPluginEnabled "$id" false >/dev/null
result=$(omarchy-shell shell setPluginEnabled "$id" false)
[[ $result == "ok" ]] || fail "$result"
fi

if [[ -L $target ]]; then
Expand Down
2 changes: 2 additions & 0 deletions docs/omarchy-shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ The bar's sections run along it in the order `left`, `centerBegin`, `center`, `c
user `shell.json` exists, defaults are used verbatim. Once the user
customizes, `shell.json` is canonical — there is no deep-merge.

Shell-side mutations synchronously read the current user file rather than the asynchronously watched config. An existing file that is empty, invalid JSON or not `version: 1` is never written: the change applies to the running shell only, until the file is usable again. A file that cannot be read is refused, and only a missing file is initialized from defaults. Inline settings still replace the targeted entry with the caller's supplied settings; other entries and top-level keys are retained. The shell checks for edits made during the mutation and, for a usable file, publishes its new in-memory config only after a successful atomic write. This prevents stale-cache overwrites, but does not serialize independent writers: a writer replacing the file after the final comparison can still race the shell write. CLI writers and manual editors do not currently participate in a shared lock protocol.

`shell.json` is shell configuration; theme tokens live in `shell.toml`
(next section). Both are current — they answer different questions. A
machine-level `~/.config/omarchy/shell.toml` is watched live by the
Expand Down
30 changes: 19 additions & 11 deletions shell/plugins/bar/Bar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Item {
// The keys each section showed as the drag started (layoutWidgets). They
// hold while no widget moves about.
property string barDragKeys: ""
property string barDragLayout: ""
// The spacers a drag has put in the sections, where a released widget can
// land (DragSpacer).
property var dragSpacers: []
Expand Down Expand Up @@ -594,6 +595,7 @@ Item {
barDragRoom = null
barDragExtent = 0
barDragKeys = ""
barDragLayout = ""
barDragRemoveArmed = false
barDragRegrab.stop()
barSettle = null
Expand Down Expand Up @@ -676,7 +678,7 @@ Item {
function setBarPosition(value) {
var next = normalizePosition(value)
if (root.shell && typeof root.shell.mutateShellConfig === "function") {
root.shell.mutateShellConfig(function(config) {
return root.shell.mutateShellConfig(function(config) {
if (!Util.isPlainObject(config.bar)) config.bar = {}
config.bar.position = next
})
Expand Down Expand Up @@ -1162,6 +1164,7 @@ Item {
// the room moves away.
function startDragRoom(sourceSlot) {
barDragKeys = JSON.stringify(layoutWidgets.sections)
barDragLayout = JSON.stringify(layoutConfig)
barDragRoom = BarModel.dropRoom(null, { key: sourceSlot.widgetKey, region: sourceSlot.region }, layoutWidgets.sections, drawnKeys(barDragWindow))
barDragHome = dragShareKey(barDragRoom)
var shares = {}
Expand Down Expand Up @@ -1262,7 +1265,8 @@ Item {
key: source.widgetKey,
from: { region: source.region, index: (sections[source.region] || []).indexOf(source.widgetKey), id: entryId(source.entry) },
to: { region: room.region, index: room.index < count ? room.index : -1 },
keys: barDragKeys
keys: barDragKeys,
layout: barDragLayout
}
}

Expand Down Expand Up @@ -1328,24 +1332,25 @@ Item {
// whatever else shares its id (BarModel.layoutWidgets).
function landBarDrag(move) {
clearBarDrag()
if (!move || JSON.stringify(layoutWidgets.sections) !== move.keys) return
if (!move || JSON.stringify(layoutWidgets.sections) !== move.keys) return false
var expected = JSON.parse(move.keys)
var into = expected[move.to.region]
var before = move.to.index >= 0 ? into[move.to.index] : null
expected[move.from.region].splice(move.from.index, 1)
into.splice(before ? into.indexOf(before) : into.length, 0, move.key)
writeLayout(expected, function(config) {
BarModel.moveEntry(config, move, function(entry) { return Util.normalizeLayoutEntry(entry) })
return writeLayout(expected, function(config) {
if (JSON.stringify(normalizeLayout(config.bar ? config.bar.layout : null)) !== move.layout) return false
return BarModel.moveEntry(config, move, function(entry) { return Util.normalizeLayoutEntry(entry) })
})
}

// Writes a layout edit to shell.json. Widgets keep their instances through
// the write as long as the sections come out as `expected`.
function writeLayout(expected, edit) {
if (!root.shell || typeof root.shell.mutateShellConfig !== "function") return
if (!root.shell || typeof root.shell.mutateShellConfig !== "function") return false
widgetMemo.expected = expected
try {
root.shell.mutateShellConfig(edit)
return root.shell.mutateShellConfig(edit)
} finally {
widgetMemo.expected = null
}
Expand Down Expand Up @@ -1395,14 +1400,17 @@ Item {
function commitBarRemoval() {
var removal = barRemoval
barRemoval = null
if (!removal) return
if (!removal) return false
var expected = JSON.parse(JSON.stringify(layoutWidgets.sections))
var list = expected[removal.region] || []
var index = list.indexOf(removal.key)
if (index < 0) return
if (index < 0) return false
list.splice(index, 1)
writeLayout(expected, function(config) {
BarModel.removeEntry(config, { region: removal.region, index: index, id: removal.id }, function(entry) { return Util.normalizeLayoutEntry(entry) })
var layout = JSON.stringify(layoutConfig)
return writeLayout(expected, function(config) {
// An index can name the wrong one of two same-id widgets once the layout on disk has moved.
if (JSON.stringify(normalizeLayout(config.bar ? config.bar.layout : null)) !== layout) return false
return BarModel.removeEntry(config, { region: removal.region, index: index, id: removal.id }, function(entry) { return Util.normalizeLayoutEntry(entry) })
})
}

Expand Down
23 changes: 17 additions & 6 deletions shell/services/PluginRegistry.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ QtObject {
// Wired by shell.qml so the registry can read the canonical shell.json
// without owning file IO itself. shellConfigProvider returns the current
// effective shell config; shellConfigMutator takes a function that receives
// a deep-cloned config it can mutate in place and persists the result.
// a fresh disk config it can mutate in place and persists the result,
// returning false if the mutation cannot be saved.
property var shellConfigProvider: null
property var shellConfigMutator: null

Expand Down Expand Up @@ -324,11 +325,12 @@ QtObject {

function moveBarWidget(id, placement) {
var error = ""
shellConfigMutator(function(config) {
var persisted = shellConfigMutator(function(config) {
ensureConfigShape(config)
error = moveBarEntry(config, id, placement || {})
})
if (error) return error
if (persisted === false) return "could not update shell config"
registryRevision++
pluginsChanged()
return ""
Expand All @@ -353,13 +355,13 @@ QtObject {
delete target.after
}
}
if (setEnabled(id, true, target)) return ""
if (setEnabled(id, true, target, true)) return ""
return lastEnableError || "unknown"
}

function setBarWidget(id, key, value, selector) {
var error = ""
shellConfigMutator(function(config) {
var persisted = shellConfigMutator(function(config) {
ensureConfigShape(config)
var location
var requested = selector || {}
Expand Down Expand Up @@ -397,6 +399,7 @@ QtObject {
entry[String(key)] = value
})
if (error) return error
if (persisted === false) return "could not update shell config"
registryRevision++
pluginsChanged()
return ""
Expand Down Expand Up @@ -494,7 +497,7 @@ QtObject {
setCloneShouldRestoreSource(config, cloneId, false)
}

function setEnabled(id, value, placement) {
function setEnabled(id, value, placement, keepExisting) {
var key = Util.canonicalWidgetId(String(id))
lastEnableError = ""
if (!shellConfigMutator) {
Expand All @@ -512,9 +515,13 @@ QtObject {
&& manifest.kinds.some(function(kind) { return kind !== "bar-widget" })
var metadata = manifest && Util.isPlainObject(manifest.omarchy) ? manifest.omarchy : null
var clonedFrom = metadata ? Util.canonicalWidgetId(String(metadata.clonedFrom || "")) : ""
shellConfigMutator(function(config) {
var persisted = shellConfigMutator(function(config) {
Comment thread
sprajs marked this conversation as resolved.
Resolved
ensureConfigShape(config)

// put leaves a widget, or the clone standing in for it, where it is. Its
// own check read the cached config; this reads the file being changed.
if (value && keepExisting && findRelativeBarLocation(config, key, "").found) return

// A placement that cannot be honoured is refused before anything
// changes: a missing neighbour, or the tray asked into its own drawer.
if (value && isBarWidget && placement && Object.keys(placement).length) {
Expand Down Expand Up @@ -593,6 +600,10 @@ QtObject {
if (isFirstParty && !isBarWidget) addDisabled(config, key)
})
if (lastEnableError) return false
if (persisted === false) {
lastEnableError = "could not update shell config"
return false
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
}
registryRevision++
pluginsChanged()
return true
Expand Down
84 changes: 84 additions & 0 deletions shell/services/ShellConfigStore.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import QtQml
import Quickshell.Io

// Mutation reads are independent of the asynchronous FileView used to watch
// the running config. Never turn an unreadable/invalid file into defaults.
QtObject {
id: store

property string path
property string lastError: ""
// The last mutate() found shell.json present but not a usable config, before running the mutator.
property bool unusable: false
property int loadError: 0
property int saveError: 0
property FileView file: FileView {
path: store.path
preload: false
blockAllReads: true
blockWrites: true
atomicWrites: true
printErrors: false
onLoadFailed: function(error) { store.loadError = error }
onSaveFailed: function(error) { store.saveError = error }
}

function read() {
loadError = 0
// text() alone returns cached contents. With preload disabled and
// blockAllReads, reload() invalidates them and text() reads synchronously.
file.reload()
var text = file.text()
return { text: text, error: loadError }
}

function reject(message) {
lastError = message
console.warn("shell.json mutation refused: " + message + " path=" + path)
return null
}

function mutate(mutator, defaults) {
lastError = ""
unusable = false
var source = read()
var config
if (source.error === FileViewError.FileNotFound) {
config = JSON.parse(JSON.stringify(defaults))
} else if (source.error) {
return reject("read failed: " + source.error)
} else {
try {
config = JSON.parse(source.text)
} catch (e) {
unusable = true
return reject("invalid JSON: " + e)
}
if (!config || typeof config !== "object" || Array.isArray(config) || config.version !== 1) {
unusable = true
return reject("expected a config object with version: 1")
}
}

try {
// Returning false cancels a no-op mutation without writing the file.
if (mutator(config) === false) return null
config.version = 1
var text = JSON.stringify(config, null, 2) + "\n"
} catch (e) {
return reject("mutation failed: " + e)
}

var current = read()
if (current.error !== source.error || current.text !== source.text)
return reject("file changed during mutation; retry the action")
if (text !== current.text) {
saveError = 0
file.setText(text)
if (saveError) return reject("write failed: " + saveError)
}
// Atomic writes protect against partial output, not other writers after
// the comparison above. Writers do not currently share a config lock.
return config
}
}
Loading
Loading