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:
co-authored by
Copilot
David Heinemeier Hansson
parent
4223cd9922
commit
fc258fa8b2
@@ -28,6 +28,15 @@ local function first_image_in_dir(dir)
|
|||||||
return nil
|
return nil
|
||||||
end
|
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
|
-- The main function elephant will call
|
||||||
function GetEntries()
|
function GetEntries()
|
||||||
local entries = {}
|
local entries = {}
|
||||||
@@ -51,19 +60,10 @@ function GetEntries()
|
|||||||
if theme_name and not seen_themes[theme_name] then
|
if theme_name and not seen_themes[theme_name] then
|
||||||
seen_themes[theme_name] = true
|
seen_themes[theme_name] = true
|
||||||
|
|
||||||
-- Check for preview images directly (no subprocess)
|
-- Check the theme dir, then fall back to the default theme dir
|
||||||
local preview_path = nil
|
-- (for partial user customizations that don't ship a preview)
|
||||||
local preview_png = theme_path .. "/preview.png"
|
local preview_path = find_preview_path(theme_path)
|
||||||
local preview_jpg = theme_path .. "/preview.jpg"
|
or find_preview_path(default_theme_dir .. "/" .. theme_name)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if preview_path and preview_path ~= "" then
|
if preview_path and preview_path ~= "" then
|
||||||
local display_name = theme_name:gsub("_", " "):gsub("%-", " ")
|
local display_name = theme_name:gsub("_", " "):gsub("%-", " ")
|
||||||
|
|||||||
Reference in New Issue
Block a user