mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Implement keepalive plugin (#2456)
This commit is contained in:
@@ -20,10 +20,10 @@ function PluginLoader:loadPlugins()
|
||||
package.path = path.."/?.lua;"..package.path
|
||||
package.cpath = path.."/lib/?.so;"..package.cpath
|
||||
local ok, plugin_module = pcall(dofile, mainfile)
|
||||
if not ok then
|
||||
if not ok or not plugin_module then
|
||||
DEBUG("Error when loading", mainfile, plugin_module)
|
||||
end
|
||||
if not plugin_module.disabled and ok then
|
||||
if ok and plugin_module and not plugin_module.disabled then
|
||||
package.path = package_path
|
||||
package.cpath = package_cpath
|
||||
plugin_module.path = path
|
||||
|
||||
@@ -16,7 +16,7 @@ end
|
||||
function Hello:addToMainMenu(tab_item_table)
|
||||
table.insert(tab_item_table.plugins, {
|
||||
text = _("Hello World"),
|
||||
callback_func = function()
|
||||
callback = function()
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Hello, docless plugin world"),
|
||||
})
|
||||
|
||||
51
plugins/keepalive.koplugin/main.lua
Normal file
51
plugins/keepalive.koplugin/main.lua
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local Device = require("device")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local _ = require("gettext")
|
||||
|
||||
local function showConfirmBox(disable)
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("The system won't sleep when this message is showing.\nPress \"Stay Alive\" if you prefer to keep system on even after closing this notification. *It will drain the battery.*\n\nIf for any reasons KOReader died before \"Close\" is pressed, please start and close KeepAlive plugin again to ensure settings are reset."),
|
||||
ok_text = _("Close"),
|
||||
ok_callback = disable,
|
||||
cancel_text = _("Stay Alive"),
|
||||
})
|
||||
end
|
||||
|
||||
local menuItem = {
|
||||
text = _("Keep Alive"),
|
||||
}
|
||||
|
||||
if Device:isKobo() then
|
||||
disable = function() UIManager:_startAutoSuspend() end
|
||||
menuItem.callback = function()
|
||||
UIManager:_stopAutoSuspend()
|
||||
showConfirmBox(disable)
|
||||
end
|
||||
elseif Device:isKindle() then
|
||||
disable = function()
|
||||
os.execute("lipc-set-prop com.lab126.powerd preventScreenSaver 0")
|
||||
end
|
||||
menuItem.callback = function()
|
||||
os.execute("lipc-set-prop com.lab126.powerd preventScreenSaver 1")
|
||||
showConfirmBox(disable)
|
||||
end
|
||||
else
|
||||
return { disabled = true, }
|
||||
end
|
||||
|
||||
local KeepAlive = WidgetContainer:new{
|
||||
name = "keepalive",
|
||||
}
|
||||
|
||||
function KeepAlive:init()
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
|
||||
function KeepAlive:addToMainMenu(tab_item_table)
|
||||
table.insert(tab_item_table.plugins, menuItem)
|
||||
end
|
||||
|
||||
return KeepAlive
|
||||
Reference in New Issue
Block a user