Skip to content
Merged
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
7 changes: 7 additions & 0 deletions shell/shell.qml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ ShellRoot {

property var defaultsConfig: builtinShellConfig
property var shellConfig: builtinShellConfig
// shell.json has text the shell could not use; persisting would replace it with defaults.
property bool userConfigUnreadable: false
property bool pluginReloading: false
property bool pluginReloadPending: false

Expand Down Expand Up @@ -91,6 +93,7 @@ ShellRoot {
console.warn("shell.json parse failed, using defaults:", e)
}
}
userConfigUnreadable = !!userText.trim() && !user
shellConfig = user || defaults
}

Expand All @@ -116,6 +119,10 @@ ShellRoot {
var payload = JSON.parse(JSON.stringify(nextConfig))
payload.version = 1
shellConfig = payload
if (userConfigUnreadable) {
console.warn("shell.json is unreadable, not overwriting it; fix it to save bar changes")
return
}
userConfigFile.setText(JSON.stringify(payload, null, 2) + "\n")
}

Expand Down
46 changes: 46 additions & 0 deletions test/shell.d/runtime-smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,52 @@ jq -e 'all(.bar.layout.right[]; (.id // .) != "omarchy.microphone")' \
fail_with_log "bar put added a second copy of a widget already on the bar"
pass "bar put leaves a widget already on the bar alone"

# A hand edit that drops the closing brace puts the shell on the defaults,
# which have no omarchy.microphone. A bar change then applies for the session
# only, leaving the file as the user left it until they fix it.
config="$test_home/.config/omarchy/shell.json"
# Elsewhen saves its first-run cities once its probe returns. Landing between
# the edit and the shell's reload, that save would write valid JSON back.
for _ in {1..80}; do
jq -e 'any(.bar.layout[][]; .id? == "omarchy.elsewhen" and .cities? != null)' "$config" >/dev/null 2>&1 && break
kill -0 "$QS_PID" 2>/dev/null || fail_with_log "test shell exited before Elsewhen saved its cities"
sleep 0.1
done
jq -e 'any(.bar.layout[][]; .id? == "omarchy.elsewhen" and .cities? != null)' "$config" >/dev/null ||
fail_with_log "Elsewhen saves its first-run cities before shell.json is edited"
sed -i '$ d' "$config"
cp "$config" "$TMPDIR/broken.json"
for _ in {1..80}; do
[[ $(center_ids) != *omarchy.microphone* ]] && break
kill -0 "$QS_PID" 2>/dev/null || fail_with_log "test shell exited while reading an unreadable shell.json"
sleep 0.1
done
[[ $(center_ids) != *omarchy.microphone* ]] || fail_with_log "shell falls back to defaults on an unreadable shell.json"
[[ $(shell_ipc shell setBarWidget omarchy.clock format '"HH:mm"' '{}') == "ok" ]] ||
fail_with_log "bar widget setting is applied while shell.json is unreadable"
jq -e 'any(.bar.layout[][]; .id? == "omarchy.clock" and .format? == "HH:mm")' \
<<<"$(shell_ipc shell listShellConfig)" >/dev/null ||
fail_with_log "a bar change still applies in memory while shell.json is unreadable"
sleep 0.5
cmp -s "$config" "$TMPDIR/broken.json" || fail "a bar change leaves an unreadable shell.json as the user left it" "$(cat "$config")"
pass "a bar change leaves an unreadable shell.json as the user left it"

printf '}\n' >>"$config"
for _ in {1..80}; do
[[ $(center_ids) == *omarchy.microphone* ]] && break
kill -0 "$QS_PID" 2>/dev/null || fail_with_log "test shell exited while reading a fixed shell.json"
sleep 0.1
done
[[ $(shell_ipc shell setBarWidget omarchy.clock format '"H:mm"' '{}') == "ok" ]] ||
fail_with_log "bar widget setting is applied once shell.json is fixed"
saved='any(.bar.layout[][]; (.id? // .) == "omarchy.microphone") and any(.bar.layout[][]; .id? == "omarchy.clock" and .format? == "H:mm")'
for _ in {1..40}; do
jq -e "$saved" "$config" >/dev/null 2>&1 && break
sleep 0.1
done
jq -e "$saved" "$config" >/dev/null || fail "a bar change is saved again once shell.json is fixed" "$(cat "$config")"
pass "a bar change is saved again once shell.json is fixed"

# Run the replacement-bar probes last: switching bar loaders can transiently
# leave bar-aware panels without a visual host, which should not add noise to
# the default-bar assertions above.
Expand Down
Loading