fixed color file loading
This commit is contained in:
1 parent
03308b50c1
commit
2713c1fda4
4 files changed
+54
-39
No files matched your search
@@ -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,
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
/home/pascal/.cache/wal/colors.scss
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -33,6 +33,52 @@ export async function getWallpapers(): Promise<string[]> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
Reference in new issue
Block a user