Reset to defaults: bundle builtin defaults as a guaranteed fallback

Reset previously could zero the bar out when defaultConfig was empty —
either because bar-defaults.json hadn't finished loading or because the
resolved path was wrong. The shell now carries an inline builtinBarConfig
that mirrors bar-defaults.json, and Reset uses it whenever the on-disk
defaults aren't yet populated.

Also: log the resolved omarchyPath / defaultsPath / userConfigPath at
startup, and route FileView load failures through console.warn so the
next time a user hits this they can see why.
This commit is contained in:
Ryan Hughes
2026-05-14 02:21:47 -04:00
parent 66155fff84
commit e9806b093b
+24 -11
View File
@@ -109,17 +109,22 @@ ShellRoot {
} }
function resetToDefaults() { function resetToDefaults() {
// Write the merged defaults explicitly so the GUI and bar.json agree on // Always fall back to the bundled builtin if defaultConfig wound up empty
// the full widget list. Adding/removing afterwards operates on that // (path resolution failed or defaultsFile hasn't finished loading), so
// explicit list rather than on an implicit fallback that the diff would // Reset never zeroes the bar out.
// unintentionally collapse on the next save. var source = defaultConfig
var fallback = { position: "top", centerAnchor: "", fontFamily: "JetBrainsMono Nerd Font", layout: { left: [], center: [], right: [] } } if (!isPlainObject(source) || !isPlainObject(source.layout)) {
var defaults = mergeConfig(fallback, defaultConfig) source = builtinBarConfig
} else {
var l = source.layout
var anyEntries = (l.left && l.left.length) || (l.center && l.center.length) || (l.right && l.right.length)
if (!anyEntries) source = builtinBarConfig
}
var payload = { var payload = {
position: String(defaults.position || "top"), position: String(source.position || "top"),
centerAnchor: String(defaults.centerAnchor || ""), centerAnchor: String(source.centerAnchor || ""),
fontFamily: String(defaults.fontFamily || "JetBrainsMono Nerd Font"), fontFamily: String(source.fontFamily || "JetBrainsMono Nerd Font"),
layout: normalizeLayout(defaults.layout || {}) layout: normalizeLayout(source.layout || {})
} }
userFile.setText(JSON.stringify(payload, null, 2) + "\n") userFile.setText(JSON.stringify(payload, null, 2) + "\n")
} }
@@ -260,12 +265,20 @@ ShellRoot {
return result return result
} }
Component.onCompleted: {
console.log("bar-settings paths",
"omarchyPath=" + root.omarchyPath,
"defaultsPath=" + root.defaultsPath,
"userConfigPath=" + root.userConfigPath)
}
FileView { FileView {
id: defaultsFile id: defaultsFile
path: root.defaultsPath path: root.defaultsPath
watchChanges: true watchChanges: true
printErrors: false printErrors: true
onLoaded: root.loadConfig() onLoaded: root.loadConfig()
onLoadFailed: function(error) { console.warn("defaults load failed:", error, "path=" + root.defaultsPath) }
onFileChanged: reload() onFileChanged: reload()
} }