feat(theme): sync shell palette with greetd greeter

- Export compiled greeter CSS and wallpaper to /var/tmp for the greeter user.

- Serialize theme changes so rapid switches cannot race wal and sass.

- Avoid duplicate greeter export on startup and disable sass source maps.

- Pass command arguments as arrays and use forEach when creating windows.
This commit is contained in:
pascalyazid committed 2026-11-27 18:55:33 +01:00
1 parent 628ebb13ba
commit 8aea20ea9f
2 files changed
+71 -10

No files matched your search

+4 -4
View File
@@ -12,18 +12,18 @@ const colorsPath = `${HOME}/.cache/wal/colors.scss`
if (!GLib.file_test(colorsPath, GLib.FileTest.EXISTS)) {
const agsDir = `${HOME}/.config/ags`
exec(`wal -q -n -i ${agsDir}/pywal.jpg`)
exec(["wal", "-q", "-n", "-i", `${agsDir}/pywal.jpg`])
}
const scss = `${HOME}/.config/ags/style.scss`
const css = `/tmp/ags-compiled-style.css`
exec(`sass ${scss} ${css}`)
exec(["sass", "--no-source-map", scss, css])
app.start({
css: css,
main() {
restoreTheme()
app.get_monitors().map(Bar)
app.get_monitors().map(PowerMenu)
app.get_monitors().forEach(Bar)
app.get_monitors().forEach(PowerMenu)
},
})
+67 -6
View File
@@ -5,6 +5,39 @@ import Gio from "gi://Gio?version=2.0"
const HOME = GLib.getenv("HOME") || ""
const WALLPAPER_DIR = `${HOME}/wallpapers`
const GREETER_DIR = "/var/tmp/ags-greeter"
/**
* Export the current palette and wallpaper for the greetd greeter.
* The greeter runs as the `greeter` user, which cannot read the user's home
* directory, and /tmp is empty at boot. /var/tmp persists across reboots and
* is world-readable, so it works for both.
*/
export async function exportGreeterTheme() {
try {
await execAsync(["mkdir", "-p", GREETER_DIR])
const walCache = `${HOME}/.cache/wal/colors.scss`
const tmpColors = `/tmp/ags-colors.scss`
if (GLib.file_test(walCache, GLib.FileTest.EXISTS)) {
await execAsync(["cp", walCache, tmpColors])
}
await execAsync([
"sass",
"--no-source-map",
`${HOME}/.config/ags/greeter/style.scss`,
`${GREETER_DIR}/greeter.css`,
])
const wallpaper = `${HOME}/.cache/current_wallpaper.jpg`
if (GLib.file_test(wallpaper, GLib.FileTest.EXISTS)) {
await execAsync(["cp", wallpaper, `${GREETER_DIR}/wallpaper.jpg`])
}
} catch (error) {
console.error("Failed to export greeter theme:", error)
}
}
/**
* Get a list of all wallpapers in the default wallpapers directory.
@@ -83,20 +116,25 @@ $color15: #d4d4d4;
* Restore the last set wallpaper.
*/
export async function restoreTheme() {
let themed = false
try {
const out = await execAsync(["cat", `${HOME}/.cache/wal/wal`])
const wallpaperPath = out.trim()
if (wallpaperPath) {
// setTheme() exports the greeter theme as its last step.
await setTheme(wallpaperPath)
themed = true
}
} catch {}
if (!themed) await exportGreeterTheme()
}
/**
* Set the wallpaper using hyprpaper, generate colors with pywal,
* Apply the wallpaper using hyprpaper, generate colors with pywal,
* and reload the AGS theme.
*/
export async function setTheme(wallpaperPath: string) {
async function applyTheme(wallpaperPath: string) {
// 1. Set wallpaper with hyprpaper
try {
// Preload the wallpaper first
@@ -121,7 +159,15 @@ export async function setTheme(wallpaperPath: string) {
// 2. Generate colors with pywal16
try {
// -q: quiet, -i: image, -n: skip setting wallpaper (hyprpaper does it)
await execAsync(`wal --contrast 21.0 -q -n -i "${wallpaperPath}"`)
await execAsync([
"wal",
"--contrast",
"21.0",
"-q",
"-n",
"-i",
wallpaperPath,
])
// Add this line so hyprlock always knows the current wallpaper:
await execAsync([
@@ -149,7 +195,7 @@ export async function setTheme(wallpaperPath: string) {
}
// Compile SCSS to CSS using the sass CLI
await execAsync(`sass ${scss} ${css}`)
await execAsync(["sass", "--no-source-map", scss, css])
// Reset any previously applied CSS and apply the new one
app.reset_css()
@@ -158,11 +204,26 @@ export async function setTheme(wallpaperPath: string) {
console.error("Failed to recompile and apply AGS styles:", error)
}
// 4. Run update script
// 4. Keep the greetd greeter in sync with the current palette/wallpaper
await exportGreeterTheme()
// 5. Run update script
try {
const agsDir = `${HOME}/.config/ags`
await execAsync(`${agsDir}/update_script.sh`)
await execAsync([`${agsDir}/update_script.sh`])
} catch (error) {
console.error("Failed to run update script:", error)
}
}
let themeQueue: Promise<void> = Promise.resolve()
/**
* Set the wallpaper and palette. Calls are serialized so rapid theme switches
* cannot run wal/sass concurrently and race on the same output files.
*/
export function setTheme(wallpaperPath: string): Promise<void> {
const run = () => applyTheme(wallpaperPath)
themeQueue = themeQueue.then(run, run)
return themeQueue
}