colours: update for scheme refactor

This commit is contained in:
2 * r + 2 * t 2025-06-11 23:02:42 +10:00
parent 2b368a5310
commit 2136b8c153

View file

@ -36,12 +36,14 @@ Singleton {
function load(data: string, isPreview: bool): void { function load(data: string, isPreview: bool): void {
const colours = isPreview ? preview : current; const colours = isPreview ? preview : current;
for (const line of data.trim().split("\n")) { const scheme = JSON.parse(data);
let [name, colour] = line.split(" ");
name = name.trim(); light = scheme.mode === "light";
name = colourNames.includes(name) ? name : `m3${name}`;
if (colours.hasOwnProperty(name)) for (const [name, colour] of Object.entries(scheme.colours)) {
colours[name] = `#${colour.trim()}`; const propName = colourNames.includes(name) ? name : `m3${name}`;
if (colours.hasOwnProperty(propName))
colours[propName] = `#${colour}`;
} }
if (!isPreview || (isPreview && endPreviewOnNextChange)) { if (!isPreview || (isPreview && endPreviewOnNextChange)) {
@ -60,14 +62,7 @@ Singleton {
} }
FileView { FileView {
path: `${Paths.state}/scheme/current-mode.txt` path: `${Paths.state}/scheme.json`
watchChanges: true
onFileChanged: reload()
onLoaded: root.light = text() === "light"
}
FileView {
path: `${Paths.state}/scheme/current.txt`
watchChanges: true watchChanges: true
onFileChanged: reload() onFileChanged: reload()
onLoaded: root.load(text(), false) onLoaded: root.load(text(), false)