Elephant menu fix when using customized default themes (#4953)

* Adds a check to see if the default theme has a preview if the user customized default theme lacks one.

* Update default/elephant/omarchy_themes.lua

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Reduce duplication

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: David Heinemeier Hansson <david@hey.com>
This commit is contained in:
Stitch
2026-04-22 15:52:49 +02:00
committed by GitHub
co-authored by Copilot David Heinemeier Hansson
parent 4223cd9922
commit fc258fa8b2
+13 -13
View File
@@ -28,6 +28,15 @@ local function first_image_in_dir(dir)
return nil
end
-- Find preview.png, preview.jpg, or first backgrounds/ image in a theme dir
local function find_preview_path(dir)
local png = dir .. "/preview.png"
local jpg = dir .. "/preview.jpg"
if file_exists(png) then return png end
if file_exists(jpg) then return jpg end
return first_image_in_dir(dir .. "/backgrounds")
end
-- The main function elephant will call
function GetEntries()
local entries = {}
@@ -51,19 +60,10 @@ function GetEntries()
if theme_name and not seen_themes[theme_name] then
seen_themes[theme_name] = true
-- Check for preview images directly (no subprocess)
local preview_path = nil
local preview_png = theme_path .. "/preview.png"
local preview_jpg = theme_path .. "/preview.jpg"
if file_exists(preview_png) then
preview_path = preview_png
elseif file_exists(preview_jpg) then
preview_path = preview_jpg
else
-- Fallback: get first image from backgrounds (one ls call)
preview_path = first_image_in_dir(theme_path .. "/backgrounds")
end
-- Check the theme dir, then fall back to the default theme dir
-- (for partial user customizations that don't ship a preview)
local preview_path = find_preview_path(theme_path)
or find_preview_path(default_theme_dir .. "/" .. theme_name)
if preview_path and preview_path ~= "" then
local display_name = theme_name:gsub("_", " "):gsub("%-", " ")