Name = "nsfw"
NamePretty = "Wallpaper switcher"
Icon = "applications-other"
Cache = true
Action = "swww img %VALUE%"
HideFromProviderlist = false
Description = "Wallpaper change menu"
SearchName = true
Parent = "wallpaper"
refresh_on_change = "/home/arch/Pictures/Wallpapers/NSFW"

function GetEntries()
    local entries = {}
    local wallpaper_dir = "/home/arch/Pictures/Wallpapers/NSFW"

    local handle = io.popen("find '" ..
        wallpaper_dir ..
        "' -maxdepth 1 -type f -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' -o -name '*.gif' -o -name '*.bmp' -o -name '*.webp' 2>/dev/null")
    if handle then
        for line in handle:lines() do
            local filename = line:match("([^/]+)$")
            if filename then
                table.insert(entries, {
                    Text = filename,
                    Subtext = "wallpaper",
                    Value = line,
                    Preview = line,
                    PreviewType = "file",
                    Icon = line
                })
            end
        end
        handle:close()
    end
    return entries
end
