diff --git a/datastorage.lua b/datastorage.lua index 597921a59..affee2453 100644 --- a/datastorage.lua +++ b/datastorage.lua @@ -76,6 +76,10 @@ function DataStorage:getDocSettingsHashDir() return self:getDataDir() .. "/hashdocsettings" end +function DataStorage:getPatchesDir() + return self:getDataDir() .. "/patches" +end + --- Gets the full configuration/data path. -- @treturn string Directory path (e.g., /mnt/onboard/.adds/koreader) function DataStorage:getFullDataDir() diff --git a/frontend/pluginloader.lua b/frontend/pluginloader.lua index 7390c7533..b6c02e259 100644 --- a/frontend/pluginloader.lua +++ b/frontend/pluginloader.lua @@ -209,7 +209,8 @@ function PluginLoader:_discover() local metafile = plugin_root.."/_meta.lua" local plugin_name = entry:sub(1, -10) 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 disabled = true end @@ -312,6 +313,9 @@ function PluginLoader:genPluginManagerSubItem() for _, plugin in ipairs(self.all_plugins) do local item = { text = plugin.fullname, + enabled_func = function() + return BUILTIN_PLUGINS[plugin.name] or G_reader_settings:nilOrFalse("plugins_disable_external") + end, checked_func = function() return plugin.enable end, diff --git a/frontend/ui/elements/common_info_menu_table.lua b/frontend/ui/elements/common_info_menu_table.lua index 16f2b4b55..74af568b4 100644 --- a/frontend/ui/elements/common_info_menu_table.lua +++ b/frontend/ui/elements/common_info_menu_table.lua @@ -1,5 +1,6 @@ local BD = require("ui/bidi") local ConfirmBox = require("ui/widget/confirmbox") +local DataStorage = require("datastorage") local Device = require("device") local Event = require("ui/event") local InfoMessage = require("ui/widget/infomessage") @@ -8,6 +9,7 @@ local UIManager = require("ui/uimanager") local Version = require("version") local dbg = require("dbg") local lfs = require("libs/libkoreader-lfs") +local userpatch = require("userpatch") local _ = require("gettext") local T = require("ffi/util").template @@ -52,7 +54,6 @@ common_info.report_bug = { end, keep_menu_open = true, callback = function(touchmenu_instance) - local DataStorage = require("datastorage") 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"), Version:getCurrentRevision(), Device:info()) @@ -103,6 +104,17 @@ common_info.report_bug = { }) 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 = { text = T(_("Version: %1"), Version:getShortVersion()), keep_menu_open = true, diff --git a/frontend/ui/elements/filemanager_menu_order.lua b/frontend/ui/elements/filemanager_menu_order.lua index b9decc3e2..1b1cf6dec 100644 --- a/frontend/ui/elements/filemanager_menu_order.lua +++ b/frontend/ui/elements/filemanager_menu_order.lua @@ -190,6 +190,7 @@ local order = { "search_menu", "----------------------------", "report_bug", + "plugins_disable_external", "----------------------------", "system_statistics", -- if enabled (Plugin) "version", diff --git a/frontend/ui/elements/patch_management.lua b/frontend/ui/elements/patch_management.lua index 05a221582..cb5d25b63 100644 --- a/frontend/ui/elements/patch_management.lua +++ b/frontend/ui/elements/patch_management.lua @@ -1,7 +1,7 @@ local DataStorage = require("datastorage") 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 local InfoMessage = require("ui/widget/infomessage") @@ -50,6 +50,7 @@ local function done_callback() end local function genSubMenu(priority) + local patches_enabled = not userPatch.arePatchesDisabled() local sub_menu = {} for i, patch in ipairs(patches[priority]) do 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) sub_menu[i] = { text = patch_name:sub(1, -5) .. (userPatch.execution_status[patch_name] == false and " ⚠" or ""), + enabled_func = function() + return patches_enabled + end, checked_func = function() - return patch:find("%.lua$") ~= nil + return patches_enabled and patch:find("%.lua$") ~= nil end, callback = function() local extension_pos = patch:find(ext, 1, true) diff --git a/frontend/ui/elements/reader_menu_order.lua b/frontend/ui/elements/reader_menu_order.lua index 08a924eb3..131c3d709 100644 --- a/frontend/ui/elements/reader_menu_order.lua +++ b/frontend/ui/elements/reader_menu_order.lua @@ -250,6 +250,7 @@ local order = { "search_menu", "----------------------------", "report_bug", + "plugins_disable_external", "----------------------------", "system_statistics", -- if enabled (Plugin) "version", diff --git a/frontend/userpatch.lua b/frontend/userpatch.lua index 6d992eff8..7b0604b9d 100644 --- a/frontend/userpatch.lua +++ b/frontend/userpatch.lua @@ -35,8 +35,26 @@ local DataStorage = require("datastorage") -- the directory KOReader is installed in (and runs from) local package_dir = lfs.currentdir() --- the directory where KOReader stores user data -local data_dir = DataStorage:getDataDir() +local patch_dir = DataStorage:getPatchesDir() +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 -- 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` ---- @string priority ... one of the defined priorities in the userpatch hashtable 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_pending = lfs.attributes(update_once_marker, "mode") == "file"