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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user