Skip to content

Commit

Permalink
[fix] DocumentRegistry: only add provider once
Browse files Browse the repository at this point in the history
Fixes <koreader#5946>.
  • Loading branch information
Frenzie committed Mar 13, 2020
1 parent d65f2c8 commit bc8c58f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions frontend/document/documentregistry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc8c58f

Please sign in to comment.