[fix] DocumentRegistry: only add provider once (#5947)

Fixes <https://github.com/koreader/koreader/issues/5946>.
reviewable/pr5957/r1
Frans de Jonge 4 years ago committed by GitHub
parent d65f2c8367
commit c2aac0f71e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -121,13 +121,23 @@ function DocumentRegistry:getProviders(file)
--- @todo some implementation based on mime types?
for _, provider in ipairs(self.providers) do
local added = false
local suffix = string.sub(file, -string.len(provider.extension) - 1)
if string.lower(suffix) == "."..provider.extension then
for i, prov_prev in ipairs(providers) do
if prov_prev.provider == provider.provider then
if prov_prev.weight >= provider.weight then
added = true
else
table.remove(providers, i)
end
end
end
-- if extension == provider.extension then
-- stick highest weighted provider at the front
if #providers >= 1 and provider.weight > providers[1].weight then
if not added and #providers >= 1 and provider.weight > providers[1].weight then
table.insert(providers, 1, provider)
else
elseif not added then
table.insert(providers, provider)
end
end

Loading…
Cancel
Save