From 1a08f2cb6959f9c4ae2d9702d41c7d834fc0ace6 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Mon, 10 May 2021 03:46:55 -0700 Subject: [PATCH] Plugins: adds PluginMenuInserter helper (#7419) Allows user-plugins to register themselves into "More tools" menu. --- frontend/ui/plugin/insert_menu.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 frontend/ui/plugin/insert_menu.lua diff --git a/frontend/ui/plugin/insert_menu.lua b/frontend/ui/plugin/insert_menu.lua new file mode 100644 index 000000000..a2b08c44e --- /dev/null +++ b/frontend/ui/plugin/insert_menu.lua @@ -0,0 +1,21 @@ +local reader_order = require("ui/elements/reader_menu_order") +local filemanager_order = require("ui/elements/filemanager_menu_order") + +-- A "hacky" way to update plugin menu items on-the-fly. +-- Use: require("plugins/insert_menu").add("my_plugin_menu_name") + +-- This piece of logic / table is singleton in the KOReader process. +-- It provides a way to add a plugin into the "More Plugins" and is useful to +-- work with contrib/plugins which are not in the core logic of KOReader. +-- To avoid duplicating the menu item, caller is expected to call the add once +-- in the KOReader process, usually it's achieveable to rely on the "require" +-- function in lua. + +local PluginMenuInserter = {} + +function PluginMenuInserter.add(name) + table.insert(reader_order.more_tools, name) + table.insert(filemanager_order.more_tools, name) +end + +return PluginMenuInserter