From 7925455b6808bbc8dd17f2d633c5039b97c3c635 Mon Sep 17 00:00:00 2001 From: ziz57 Date: Sat, 25 May 2024 22:38:44 +0100 Subject: [PATCH] Add ReaderLink::registerScheme for plugins handling non-http(s) links (#11889) Currently, links with a scheme other than http or https are rejected. But plugins may want to handle them. This allows them to, by registering the scheme with self.ui.link:registerScheme("example") during the plugin's init. --- frontend/apps/reader/modules/readerlink.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/apps/reader/modules/readerlink.lua b/frontend/apps/reader/modules/readerlink.lua index a7b1abe4b..cdb466cdc 100644 --- a/frontend/apps/reader/modules/readerlink.lua +++ b/frontend/apps/reader/modules/readerlink.lua @@ -67,6 +67,7 @@ local ReaderLink = InputContainer:extend{ location_stack = nil, -- table, per-instance forward_location_stack = nil, -- table, per-instance _external_link_buttons = nil, + handledSchemes = {"http", "https"}, } function ReaderLink:init() @@ -225,6 +226,10 @@ function ReaderLink:init() end end +function ReaderLink:registerScheme(scheme) + table.insert(self.handledSchemes, scheme) +end + function ReaderLink:onGesture() end function ReaderLink:registerKeyEvents() @@ -824,8 +829,9 @@ function ReaderLink:onGotoLink(link, neglect_current_location, allow_footnote_po end logger.dbg("ReaderLink:onGotoLink: External link:", link_url) - local is_http_link = link_url:find("^https?://") ~= nil - if is_http_link and self:onGoToExternalLink(link_url) then + local scheme = link_url:match("^(%w+)://") + local is_handled_external_link = scheme and util.arrayContains(self.handledSchemes, scheme) + if is_handled_external_link and self:onGoToExternalLink(link_url) then return true end