Write the eight accents down once

They were written down five times: ThemeProfileModel.js for QML,
looks.lua for the compositor, and again in panama-theme-apps and
panama-lock. The GNOME accent-name mapping was a sixth list. Adding a
ninth accent meant editing all of them, and the file most likely to be
missed was the lock screen, which fails silently -- the machine locks
in last season's colour and nothing says why. panama-theme-apps
admitted it in a comment: "there is no shared source between QML and a
shell script".

config/palette.json is that source now. looks.lua reads it through a
new prefs.readJson, which uses the same never-raise parser the settings
store uses, so an unreadable palette costs the accent colours and never
the compositor config. The two shell generators read it through
scripts/panama-palette, which also carries the hex-to-rgb conversion
hyprlock needs and the GNOME member lookup.

QML keeps its table, because a .js module imported into QML cannot read
a file. That is still a copy, so the palette contract compares the two
value by value -- every accent, every field -- and fails on any
disagreement. Verified by planting a wrong hex and watching it name the
exact field.

The adwaita contract used to check the shell's own copy of the GNOME
mapping. It now checks that the shell resolves through the palette, and
fails if that copy ever grows back.
This commit is contained in:
Gabriel Brown
2026-08-22 05:42:53 -04:00
parent 202b5b89ac
commit e1a04d2d70
9 changed files with 378 additions and 87 deletions
+11 -12
View File
@@ -14,18 +14,17 @@
local prefs = require("prefs")
-- Mirrors config/Theme.qml's `accents` map. Lua has no import path into a QML
-- singleton, so the hex pairs are restated here -- just the four hex strings
-- each named accent needs, not the labels, which stay UI-only.
local accents = {
blue = { dark = "82aaff", darkSecondary = "b172b0", light = "2e7de9", lightSecondary = "9854f1" },
orchid = { dark = "c099ff", darkSecondary = "fca7ea", light = "7847bd", lightSecondary = "9854f1" },
teal = { dark = "86e1fc", darkSecondary = "82aaff", light = "007197", lightSecondary = "2e7de9" },
green = { dark = "c3e88d", darkSecondary = "86e1fc", light = "587539", lightSecondary = "007197" },
amber = { dark = "ffc777", darkSecondary = "ff966c", light = "8c6c3e", lightSecondary = "b15c00" },
orange = { dark = "ff966c", darkSecondary = "ff757f", light = "b15c00", lightSecondary = "c64343" },
rose = { dark = "ff757f", darkSecondary = "c099ff", light = "f52a65", lightSecondary = "9854f1" },
slate = { dark = "828bb8", darkSecondary = "82aaff", light = "6172b0", lightSecondary = "2e7de9" },
-- The eight accents, from config/palette.json -- the one place they are
-- written down for everything outside QML. They used to be restated here,
-- which made adding a ninth accent a five-file edit; the file that got
-- forgotten was always the one that fails silently.
--
-- Falls back to the shipped blue pair if the palette cannot be read, for the
-- same reason prefs never raises: a missing file costs the accent colour, not
-- the compositor config.
local palette = prefs.readJson(os.getenv("HOME") .. "/.config/quickshell/config/palette.json")
local accents = palette.accents or {
blue = { dark = "82aaff", darkSecondary = "b172b0", light = "2e7de9", lightSecondary = "9854f1" },
}
-- The accent pair a fresh session or `hyprctl reload` starts from.
+27
View File
@@ -244,6 +244,33 @@ function prefs.getInt(key, fallback)
return math.floor(value + 0.5)
end
-- Read and decode any JSON file, using the same never-raise parser the
-- settings store uses. Returns an empty table for a file that is missing,
-- empty, or malformed, so a caller can index the result without checking.
--
-- Exists so config/palette.json can be read by looks.lua rather than the eight
-- accents being written out a second time in Lua. A bad palette costs the
-- accent colours, never the compositor config.
function prefs.readJson(path)
if type(path) ~= "string" or path == "" then
return {}
end
local file = io.open(path, "r")
if not file then
return {}
end
local text = file:read("*a")
file:close()
if not text or text:match("^%s*$") then
return {}
end
local ok, parsed = pcall(decode, text)
if not ok or type(parsed) ~= "table" then
return {}
end
return parsed
end
-- True when a settings file was actually read. Useful from overrides.lua.
function prefs.loaded()
return next(values) ~= nil