diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-25 12:12:29 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-25 12:12:29 +1100 |
| commit | e39900b77ea6d492f72584dd12701004cab847e4 (patch) | |
| tree | 4ca787241fde8580b658f5733a33eba7d0d3764f | |
| parent | schemes: fix updating taking ages (diff) | |
| download | caelestia-shell-e39900b77ea6d492f72584dd12701004cab847e4.tar.gz caelestia-shell-e39900b77ea6d492f72584dd12701004cab847e4.tar.bz2 caelestia-shell-e39900b77ea6d492f72584dd12701004cab847e4.zip | |
style: ensure loading correct order
Cause async, older requests could load slower and therefore override newer requests
Also reduce the number of loads when spam
And add light scss var
| -rw-r--r-- | app.tsx | 36 |
1 files changed, 29 insertions, 7 deletions
@@ -26,13 +26,34 @@ const applyTransparency = (name: string, hex: string) => { const applyVibrancy = (hex: string) => (style.vibrant.get() ? `color.scale(${hex}, $saturation: 40%)` : hex); -export const loadStyleAsync = async () => { - const schemeColours = Object.entries(Palette.get_default().colours) - .map(([name, hex]) => `$${name}: ${applyVibrancy(applyTransparency(name, hex))};`) - .join("\n"); - await writeFileAsync(`${SRC}/scss/scheme/_index.scss`, `@use "sass:color";\n${schemeColours}`); - App.apply_css(await execAsync(`sass ${SRC}/style.scss`), true); -}; +const styleLoader = new (class { + #running = false; + #dirty = false; + + async run() { + this.#dirty = true; + if (this.#running) return; + this.#running = true; + while (this.#dirty) { + this.#dirty = false; + await this.#run(); + } + this.#running = false; + } + + async #run() { + const schemeColours = Object.entries(Palette.get_default().colours) + .map(([name, hex]) => `$${name}: ${applyVibrancy(applyTransparency(name, hex))};`) + .join("\n"); + await writeFileAsync( + `${SRC}/scss/scheme/_index.scss`, + `@use "sass:color";\n$light: ${Palette.get_default().mode === "light"};\n${schemeColours}` + ); + App.apply_css(await execAsync(`sass ${SRC}/style.scss`), true); + } +})(); + +export const loadStyleAsync = () => styleLoader.run(); App.start({ instanceName: "caelestia", @@ -43,6 +64,7 @@ App.start({ loadStyleAsync().catch(console.error); style.transparency.subscribe(() => loadStyleAsync().catch(console.error)); Palette.get_default().connect("notify::colours", () => loadStyleAsync().catch(console.error)); + Palette.get_default().connect("notify::mode", () => loadStyleAsync().catch(console.error)); initConfig(); |