Disable external plugins and user-patches (#15593)

This commit is contained in:
hius07 authored and GitHub committed 2026-06-26 18:32:34 +03:00
1 parent 5549f8ac6c
commit f5579dd5fa
7 files changed
+51 -7

No files matched your search

+4
View File
@@ -76,6 +76,10 @@ function DataStorage:getDocSettingsHashDir()
return self:getDataDir() .. "/hashdocsettings" return self:getDataDir() .. "/hashdocsettings"
end end
function DataStorage:getPatchesDir()
return self:getDataDir() .. "/patches"
end
--- Gets the full configuration/data path. --- Gets the full configuration/data path.
-- @treturn string Directory path (e.g., /mnt/onboard/.adds/koreader) -- @treturn string Directory path (e.g., /mnt/onboard/.adds/koreader)
function DataStorage:getFullDataDir() function DataStorage:getFullDataDir()
+5 -1
View File
@@ -209,7 +209,8 @@ function PluginLoader:_discover()
local metafile = plugin_root.."/_meta.lua" local metafile = plugin_root.."/_meta.lua"
local plugin_name = entry:sub(1, -10) local plugin_name = entry:sub(1, -10)
local disabled = false local disabled = false
if plugins_disabled and plugins_disabled[plugin_name] then if (plugins_disabled and plugins_disabled[plugin_name]) or
(G_reader_settings:isTrue("plugins_disable_external") and not BUILTIN_PLUGINS[plugin_name]) then
mainfile = metafile mainfile = metafile
disabled = true disabled = true
end end
@@ -312,6 +313,9 @@ function PluginLoader:genPluginManagerSubItem()
for _, plugin in ipairs(self.all_plugins) do for _, plugin in ipairs(self.all_plugins) do
local item = { local item = {
text = plugin.fullname, text = plugin.fullname,
enabled_func = function()
return BUILTIN_PLUGINS[plugin.name] or G_reader_settings:nilOrFalse("plugins_disable_external")
end,
checked_func = function() checked_func = function()
return plugin.enable return plugin.enable
end, end,
@@ -1,5 +1,6 @@
local BD = require("ui/bidi") local BD = require("ui/bidi")
local ConfirmBox = require("ui/widget/confirmbox") local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
local Device = require("device") local Device = require("device")
local Event = require("ui/event") local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
@@ -8,6 +9,7 @@ local UIManager = require("ui/uimanager")
local Version = require("version") local Version = require("version")
local dbg = require("dbg") local dbg = require("dbg")
local lfs = require("libs/libkoreader-lfs") local lfs = require("libs/libkoreader-lfs")
local userpatch = require("userpatch")
local _ = require("gettext") local _ = require("gettext")
local T = require("ffi/util").template local T = require("ffi/util").template
@@ -52,7 +54,6 @@ common_info.report_bug = {
end, end,
keep_menu_open = true, keep_menu_open = true,
callback = function(touchmenu_instance) callback = function(touchmenu_instance)
local DataStorage = require("datastorage")
local log_path = string.format("%s/%s", DataStorage:getDataDir(), "crash.log") local log_path = string.format("%s/%s", DataStorage:getDataDir(), "crash.log")
local common_msg = T(_("Please report bugs to \nhttps://github.com/koreader/koreader/issues\n\nVersion:\n%1\n\nDetected device:\n%2"), local common_msg = T(_("Please report bugs to \nhttps://github.com/koreader/koreader/issues\n\nVersion:\n%1\n\nDetected device:\n%2"),
Version:getCurrentRevision(), Device:info()) Version:getCurrentRevision(), Device:info())
@@ -103,6 +104,17 @@ common_info.report_bug = {
}) })
end end
} }
common_info.plugins_disable_external = {
text = _("Disable external plugins and user-patches"),
checked_func = function()
return G_reader_settings:isTrue("plugins_disable_external")
end,
callback = function()
G_reader_settings:flipNilOrFalse("plugins_disable_external")
userpatch.togglePatchesDisabled()
UIManager:askForRestart()
end,
}
common_info.version = { common_info.version = {
text = T(_("Version: %1"), Version:getShortVersion()), text = T(_("Version: %1"), Version:getShortVersion()),
keep_menu_open = true, keep_menu_open = true,
@@ -190,6 +190,7 @@ local order = {
"search_menu", "search_menu",
"----------------------------", "----------------------------",
"report_bug", "report_bug",
"plugins_disable_external",
"----------------------------", "----------------------------",
"system_statistics", -- if enabled (Plugin) "system_statistics", -- if enabled (Plugin)
"version", "version",
+6 -2
View File
@@ -1,7 +1,7 @@
local DataStorage = require("datastorage") local DataStorage = require("datastorage")
local lfs = require("libs/libkoreader-lfs") local lfs = require("libs/libkoreader-lfs")
local patch_dir = DataStorage:getDataDir() .. "/patches" local patch_dir = DataStorage:getPatchesDir()
if lfs.attributes(patch_dir, "mode") ~= "directory" then return end if lfs.attributes(patch_dir, "mode") ~= "directory" then return end
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
@@ -50,6 +50,7 @@ local function done_callback()
end end
local function genSubMenu(priority) local function genSubMenu(priority)
local patches_enabled = not userPatch.arePatchesDisabled()
local sub_menu = {} local sub_menu = {}
for i, patch in ipairs(patches[priority]) do for i, patch in ipairs(patches[priority]) do
local ext = ".lua" local ext = ".lua"
@@ -57,8 +58,11 @@ local function genSubMenu(priority)
local patch_name = patch:sub(1, patch:find(ext, 1, true) + ext:len() - 1) local patch_name = patch:sub(1, patch:find(ext, 1, true) + ext:len() - 1)
sub_menu[i] = { sub_menu[i] = {
text = patch_name:sub(1, -5) .. (userPatch.execution_status[patch_name] == false and " ⚠" or ""), text = patch_name:sub(1, -5) .. (userPatch.execution_status[patch_name] == false and " ⚠" or ""),
enabled_func = function()
return patches_enabled
end,
checked_func = function() checked_func = function()
return patch:find("%.lua$") ~= nil return patches_enabled and patch:find("%.lua$") ~= nil
end, end,
callback = function() callback = function()
local extension_pos = patch:find(ext, 1, true) local extension_pos = patch:find(ext, 1, true)
@@ -250,6 +250,7 @@ local order = {
"search_menu", "search_menu",
"----------------------------", "----------------------------",
"report_bug", "report_bug",
"plugins_disable_external",
"----------------------------", "----------------------------",
"system_statistics", -- if enabled (Plugin) "system_statistics", -- if enabled (Plugin)
"version", "version",
+21 -3
View File
@@ -35,8 +35,26 @@ local DataStorage = require("datastorage")
-- the directory KOReader is installed in (and runs from) -- the directory KOReader is installed in (and runs from)
local package_dir = lfs.currentdir() local package_dir = lfs.currentdir()
-- the directory where KOReader stores user data local patch_dir = DataStorage:getPatchesDir()
local data_dir = DataStorage:getDataDir() local patches_disabled_path = patch_dir .. "/.patches_disabled"
local patches_disabled = lfs.attributes(patches_disabled_path, "mode") == "file"
function userpatch.arePatchesDisabled()
return patches_disabled
end
function userpatch.togglePatchesDisabled()
if patches_disabled then
os.remove(patches_disabled_path)
patches_disabled = false
else
local file = io.open(patches_disabled_path, "w")
if file then
file:close()
patches_disabled = true
end
end
end
--- Run lua patches --- Run lua patches
-- Execution order order is alphanum-sort for humans version 4: `1-patch.lua` is executed before `10-patch.lua` -- Execution order order is alphanum-sort for humans version 4: `1-patch.lua` is executed before `10-patch.lua`
@@ -90,7 +108,7 @@ end
--- This function applies lua patches from `/koreader/patches` --- This function applies lua patches from `/koreader/patches`
---- @string priority ... one of the defined priorities in the userpatch hashtable ---- @string priority ... one of the defined priorities in the userpatch hashtable
function userpatch.applyPatches(priority) function userpatch.applyPatches(priority)
local patch_dir = data_dir .. "/patches" if patches_disabled then return end
local update_once_marker = package_dir .. "/update_once.marker" local update_once_marker = package_dir .. "/update_once.marker"
local update_once_pending = lfs.attributes(update_once_marker, "mode") == "file" local update_once_pending = lfs.attributes(update_once_marker, "mode") == "file"