From 2713c1fda4e60cebd14349f9a02262d8c6cf39d9 Mon Sep 17 00:00:00 2001 From: Pascal Thuma Date: Tue, 24 Mar 2026 23:37:38 +0100 Subject: [PATCH] fixed color file loading --- app.ts | 4 ++- colors.scss | 1 - style.scss | 2 +- theme.ts | 86 +++++++++++++++++++++++++++++++---------------------- 4 files changed, 54 insertions(+), 39 deletions(-) delete mode 120000 colors.scss diff --git a/app.ts b/app.ts index c6b304d..08ab46f 100644 --- a/app.ts +++ b/app.ts @@ -2,7 +2,9 @@ import app from "ags/gtk4/app" import style from "./style.scss" import Bar from "./widget/Bar" import PowerMenu from "./widget/PowerMenu" -import { restoreTheme } from "./theme" +import { initThemeSync, restoreTheme } from "./theme" + +initThemeSync() app.start({ css: style, diff --git a/colors.scss b/colors.scss deleted file mode 120000 index bc2d54d..0000000 --- a/colors.scss +++ /dev/null @@ -1 +0,0 @@ -/home/pascal/.cache/wal/colors.scss \ No newline at end of file diff --git a/style.scss b/style.scss index 5970ab5..e133afb 100644 --- a/style.scss +++ b/style.scss @@ -1,4 +1,4 @@ -@use "./colors.scss" as wal; +@use "/tmp/ags-colors.scss" as wal; $fg-color: wal.$foreground; $bg-color: rgba(wal.$background, 0.8); diff --git a/theme.ts b/theme.ts index a795d8e..67fdf96 100644 --- a/theme.ts +++ b/theme.ts @@ -33,6 +33,52 @@ export async function getWallpapers(): Promise { } } +/** + * Synchronously ensure that a pywal colors file exists in /tmp + * before AGS loads the initial SCSS file. + */ +export function initThemeSync() { + const walCache = `${HOME}/.cache/wal/colors.scss` + const tmpColors = `/tmp/ags-colors.scss` + + if (GLib.file_test(walCache, GLib.FileTest.EXISTS)) { + // If Pywal has run before, copy its colors.scss to our safe /tmp location + try { + const [ok, content] = GLib.file_get_contents(walCache) + if (ok) { + GLib.file_set_contents(tmpColors, content) + } + } catch {} + } else { + // If Pywal hasn't run yet, provide a safe fallback so Sass compiles + const fallback = ` +$wallpaper: ""; +$background: #1e1e1e; +$foreground: #d4d4d4; +$cursor: #d4d4d4; +$color0: #1e1e1e; +$color1: #f44747; +$color2: #6a9955; +$color3: #d7ba7d; +$color4: #569cd6; +$color5: #c586c0; +$color6: #4ec9b0; +$color7: #d4d4d4; +$color8: #808080; +$color9: #f44747; +$color10: #6a9955; +$color11: #d7ba7d; +$color12: #569cd6; +$color13: #c586c0; +$color14: #4ec9b0; +$color15: #d4d4d4; +` + try { + GLib.file_set_contents(tmpColors, fallback) + } catch {} + } +} + /** * Restore the last set wallpaper. */ @@ -91,45 +137,13 @@ export async function setTheme(wallpaperPath: string) { const scss = `${agsDir}/style.scss` const css = `/tmp/ags-compiled-style.css` - // Create a symlink to the pywal colors file so SCSS can always find it - // even if the user moves their dotfiles, and provide a fallback if Pywal hasn't run yet. + // Copy the newly generated Pywal colors to the /tmp directory try { const walCache = `${HOME}/.cache/wal/colors.scss` - const walLocal = `${agsDir}/colors.scss` - - // Check if pywal cache exists, if not create a fallback - try { - await execAsync(`cat ${walCache}`) - } catch { - const fallback = ` - $wallpaper: ""; - $background: #1e1e1e; - $foreground: #d4d4d4; - $cursor: #d4d4d4; - $color0: #1e1e1e; - $color1: #f44747; - $color2: #6a9955; - $color3: #d7ba7d; - $color4: #569cd6; - $color5: #c586c0; - $color6: #4ec9b0; - $color7: #d4d4d4; - $color8: #808080; - $color9: #f44747; - $color10: #6a9955; - $color11: #d7ba7d; - $color12: #569cd6; - $color13: #c586c0; - $color14: #4ec9b0; - $color15: #d4d4d4; - ` - await execAsync(`mkdir -p ${HOME}/.cache/wal`) - await execAsync(["bash", "-c", `echo "${fallback}" > ${walCache}`]) - } - - await execAsync(`ln -sf ${walCache} ${walLocal}`) + const tmpColors = `/tmp/ags-colors.scss` + await execAsync(["cp", walCache, tmpColors]) } catch (e) { - console.error("Failed to setup pywal colors symlink:", e) + console.error("Failed to copy pywal colors to /tmp:", e) } // Compile SCSS to CSS using the sass CLI