import app from "ags/gtk3/app" import { Astal, Gtk } from "ags/gtk3" import { createPoll } from "ags/time" import { For } from "ags" import { sh, shell } from "../lib/utils" export const THEMEPICKER_WINDOW = "theme-picker" const COLUMNS = 3 type Theme = { slug: string; name: string; swatches: string[] } const listCommand = "{ find \"$HOME/.config/omarchy/themes\" -mindepth 1 -maxdepth 1 -type d 2>/dev/null; " + "find \"$OMARCHY_PATH/themes\" -mindepth 1 -maxdepth 1 -type d 2>/dev/null; } | " + "while read -r d; do " + "[ -f \"$d/colors.toml\" ] || continue; " + "n=$(basename \"$d\"); " + "[ \"$n\" = blob-dynamic ] && continue; " + "c=$(grep -E '^color[1-6] *=' \"$d/colors.toml\" | sed -E 's/^color[0-9]+ *= *\"?([^\"]*)\"?.*/\\1/' | paste -sd,); " + "p=$(echo \"$n\" | sed -E 's/(^|-)([a-z])/\\1\\u\\2/g; s/-/ /g'); " + "echo \"$n|$p|$c\"; " + "done | awk -F'|' '!seen[$1]++' | sort -t'|' -k2,2" const themes = createPoll( [], 5000, shell(listCommand), (stdout) => stdout .split("\n") .filter((line) => line.length > 0) .map((line) => { const [slug, name, swatchStr] = line.split("|") return { slug, name: name ?? slug, swatches: (swatchStr ?? "").split(",").filter(Boolean) } }), ) const currentThemeName = createPoll( "", 2000, shell("cat \"$HOME/.config/omarchy/current/theme.name\" 2>/dev/null"), (stdout) => stdout.trim(), ) const isDynamic = currentThemeName.as((name) => name === "blob-dynamic") const rows = themes.as((list) => { const chunks: Theme[][] = [] for (let index = 0; index < list.length; index += COLUMNS) { chunks.push(list.slice(index, index + COLUMNS)) } return chunks }) const applyTheme = (slug: string) => { app.toggle_window(THEMEPICKER_WINDOW) sh(`"$HOME/scripts/blob_theme.sh" "${slug}"`) } const applyDynamic = () => { app.toggle_window(THEMEPICKER_WINDOW) sh(`"$HOME/scripts/blob_theme.sh" --dynamic`) } function Swatches({ colors }: { colors: string[] }) { return ( {colors.map((color) => ( ))} ) } function ThemeChip({ theme }: { theme: Theme }) { const active = currentThemeName.as((name) => name === theme.slug) return ( ) } function DynamicChip() { return ( ) } export default function ThemePicker() { const hasThemes = themes.as((list) => list.length > 0) const isEmpty = themes.as((list) => list.length === 0) return ( row.map((t) => t.slug).join("|")}> {(row: Theme[]) => ( {row.map((theme) => ( ))} )} ) }